Skip to content

Commit

Permalink
fix: int to int64 types
Browse files Browse the repository at this point in the history
  • Loading branch information
PraneethJain committed Sep 27, 2023
1 parent ee93904 commit bc702a4
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions math/binary_exponentiation.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#include <assert.h> // for assert()
#include <stdint.h> // for int64 types
#include <stdio.h> // for output
#include <stdlib.h> // for exit()

Expand All @@ -18,18 +19,11 @@
* @param n - exponent
* @return a raised to the nth power
* @warning
* `int` can overflow very quickly.
* can overflow very quickly.
*/
int binary_exponentiation(int a, int n)
int64_t binary_exponentiation(int64_t a, uint64_t n)
{
// Check for negative exponent
if (n < 0)
{
fprintf(stderr, "Illegal exponent passed! n should be non negative.\n");
exit(EXIT_FAILURE);
}

int res = 1;
int64_t res = 1;
while (n > 0)
{
if (n % 2 == 1) // If the current bit is 1
Expand Down

0 comments on commit bc702a4

Please sign in to comment.