From bc702a4d59b0dfe2448c023d3ca9f18b2e9414d4 Mon Sep 17 00:00:00 2001 From: PraneethJain Date: Wed, 27 Sep 2023 23:32:02 +0530 Subject: [PATCH] fix: int to int64 types --- math/binary_exponentiation.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) 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