diff --git a/math/binary_exponentiation.c b/math/binary_exponentiation.c index cf0291dc75..8d25faa21c 100644 --- a/math/binary_exponentiation.c +++ b/math/binary_exponentiation.c @@ -9,6 +9,7 @@ */ #include // for assert() +#include // for int64 types #include // for output #include // for exit() @@ -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