From b837b841c04544c8bfd7789fc48e44e99b486c1b Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Tue, 16 May 2023 18:44:48 +0100 Subject: [PATCH 01/13] Quality of life Update FIX: added checking for negative exponents to both functions. Removed user interaction and repalced with tests function. CHORE: added author, reformatted function documentation, added descriptions of what is happening in each algo and adhered to other repo standards --- math/binary_exponent.cpp | 110 ++++++++++++++++++++++++++++++--------- 1 file changed, 85 insertions(+), 25 deletions(-) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index 05e6f33f7ae..742b004f3a5 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -2,6 +2,7 @@ * @file * @brief C++ Program to find Binary Exponent Iteratively and Recursively. * + * @details * Calculate \f$a^b\f$ in \f$O(\log(b))\f$ by converting \f$b\f$ to a * binary number. Binary exponentiation is also known as exponentiation by * squaring. @@ -19,17 +20,42 @@ * \f} * Hence to calculate 2^10 we only need to multiply \f$2^8\f$ and \f$2^2\f$ * skipping \f$2^1\f$ and \f$2^4\f$. + * + * @author[Mann Mehta]https://github.com/mann2108 */ +#include #include -/// Recursive function to calculate exponent in \f$O(\log(n))\f$ using binary -/// exponent. -int binExpo(int a, int b) { +namespace math { +/** + * @brief Recursive function to calculate exponent in \f$O(\log(n))\f$ using + * binary exponent. + * @param a base number + * @param b exponent number + * @return 1 if the exponent number is 0 the return value will always be 1 + * @return 0 if the exponential number is < 0 ( 0 representing NULL since + * < 0 is an invalid exponential to use ) + * @return (res * res * a) if modulo 2 of exponential is 0 + * @return (res * res) if modulo 2 of exponential is 1 + */ +long long binExpo_recursive(long long a, long long b) { + /*! + * Provided that b != 0, this function recursively calls itself, until an + * instance of it returns 1 (which eventually occurs due to b/2 for each + * call to binExpo). This triggers a chain reaction eventually leading + * back to the original call to binExpo returning. This works like a + * building a russian doll, first figure out however dolls you want to use ( + * say, until a call to binExpo returns 1 ) and then assemble the dolls ( + * with each return, res gets exponentially bigger ) + */ if (b == 0) { return 1; + } else if (b < 0) { // if b is not a valid exponent + return 0; } - int res = binExpo(a, b / 2); + + long long res = binExpo_recursive(a, b / 2); if (b % 2) { return res * res * a; } else { @@ -37,11 +63,28 @@ int binExpo(int a, int b) { } } -/// Iterative function to calculate exponent in \f$O(\log(n))\f$ using binary -/// exponent. -int binExpo_alt(int a, int b) { - int res = 1; - while (b > 0) { +/** + * @brief Iterative function to calculate exponent in \f$O(\log(n))\f$ using + binary + + exponent. + * @param a base number + * @param b exponential number + * @return res if the exponential number is >= 0 + * @return 0 if the exponential number is < 0 ( 0 representing NULL since + * < 0 is an invalid exponential to use ) + */ +long long binExpo_iterative(long long a, long long b) { + /*! + * Provided b > 0, this function iteratively multiples the value res. Each + * iteration of the while loop, checks if the exponential number is binary, + * if so res is multiplied by the current value of a, for that iteration. + * Additionally, a is multiplied by itself and b is halved by itself. + */ + if (b < 0) { + return 0; + } + long long res = 1; + while (b > 0) { // if b is not a valid exponent if (b % 2) { res = res * a; } @@ -50,22 +93,39 @@ int binExpo_alt(int a, int b) { } return res; } +} // namespace math -/// Main function -int main() { - int a, b; - /// Give two numbers a, b - std::cin >> a >> b; - if (a == 0 && b == 0) { - std::cout << "Math error" << std::endl; - } else if (b < 0) { - std::cout << "Exponent must be positive !!" << std::endl; - } else { - int resRecurse = binExpo(a, b); - /// int resIterate = binExpo_alt(a, b); +using namespace math; +/** + * @brief self-test implementation + * @returns void + */ +static void tests() { + assert(binExpo_recursive(1, 0) == 1); + assert(binExpo_recursive(746584, 0) == 1); + assert(binExpo_recursive(1, 1) == 1); + assert(binExpo_recursive(2938374, 1) == 2938374); + assert(binExpo_recursive(3, 7) == 2187); + assert(binExpo_recursive(31, 5) == 28629151); + assert(binExpo_recursive(0, 0) == 1); + assert(binExpo_recursive(1, -20) == 0); - /// Result of a^b (where '^' denotes exponentiation) - std::cout << resRecurse << std::endl; - /// std::cout << resIterate << std::endl; - } + assert(binExpo_iterative(1, 0) == 1); + assert(binExpo_iterative(746584, 0) == 1); + assert(binExpo_iterative(1, 1) == 1); + assert(binExpo_iterative(2938374, 1) == 2938374); + assert(binExpo_iterative(3, 7) == 2187); + assert(binExpo_iterative(31, 5) == 28629151); + assert(binExpo_iterative(0, 0) == 1); + assert(binExpo_iterative(1, -20) == 0); + std::cout << "all tests have passed" << std::endl; +} + +/** + * @brief Main function + * @returns 0 on exit + */ +int main() { + tests(); // perform self-test implementations + return 0; } From 033b8855394d3887dc4a08ddb8467c17b7017f20 Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Thu, 18 May 2023 12:49:05 +0100 Subject: [PATCH 02/13] Update binary_exponent.cpp --- math/binary_exponent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index 742b004f3a5..ee88860f9f9 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -24,8 +24,8 @@ * @author[Mann Mehta]https://github.com/mann2108 */ -#include -#include +#include // for assert +#include // for cout namespace math { /** From 8198035c4fde02b754410286bdef0eff0d06743f Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Tue, 23 May 2023 17:44:49 +0100 Subject: [PATCH 03/13] Update math/binary_exponent.cpp Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com> --- math/binary_exponent.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index ee88860f9f9..d5ad93b942d 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -26,7 +26,10 @@ #include // for assert #include // for cout - +/** + * @brief Mathematical algorithms + * @namespace + */ namespace math { /** * @brief Recursive function to calculate exponent in \f$O(\log(n))\f$ using From 2e3313a5cbd2c8ba3c271d32b7985775a0f9fce0 Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Tue, 23 May 2023 17:44:56 +0100 Subject: [PATCH 04/13] Update math/binary_exponent.cpp Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com> --- math/binary_exponent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index d5ad93b942d..08f7b3a981d 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -24,8 +24,8 @@ * @author[Mann Mehta]https://github.com/mann2108 */ -#include // for assert -#include // for cout +#include /// for assert +#include /// for cout /** * @brief Mathematical algorithms * @namespace From e99f5e5528216ce26edc99ee5002f1c4d5da9e72 Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Sat, 3 Jun 2023 14:24:46 +0100 Subject: [PATCH 05/13] Update math/binary_exponent.cpp Co-authored-by: David Leal --- math/binary_exponent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index 08f7b3a981d..34ba1217147 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -21,7 +21,7 @@ * Hence to calculate 2^10 we only need to multiply \f$2^8\f$ and \f$2^2\f$ * skipping \f$2^1\f$ and \f$2^4\f$. * - * @author[Mann Mehta]https://github.com/mann2108 + * @author [Mann Mehta](https://github.com/mann2108) */ #include /// for assert From bcc9d7d834d24b28587ef74c45ec51e182c11e9b Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Sat, 3 Jun 2023 14:25:50 +0100 Subject: [PATCH 06/13] Update math/binary_exponent.cpp Co-authored-by: David Leal --- math/binary_exponent.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index 34ba1217147..9bc99f09172 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -24,8 +24,9 @@ * @author [Mann Mehta](https://github.com/mann2108) */ -#include /// for assert -#include /// for cout +#include /// for assert +#include /// for IO operations + /** * @brief Mathematical algorithms * @namespace From 26028356ffe04a81dc44a5ee60c91e4389ff2538 Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Sat, 3 Jun 2023 14:26:25 +0100 Subject: [PATCH 07/13] Update math/binary_exponent.cpp Co-authored-by: David Leal --- math/binary_exponent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index 9bc99f09172..2cd75fea02e 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -69,7 +69,7 @@ long long binExpo_recursive(long long a, long long b) { /** * @brief Iterative function to calculate exponent in \f$O(\log(n))\f$ using - binary + * binary + exponent. * @param a base number * @param b exponential number From 08d955413f91f2eb7b30f9370d29cc1ab2eb15f6 Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Sat, 3 Jun 2023 15:29:28 +0100 Subject: [PATCH 08/13] change long long to (u)int64_t also one or two small wording changes --- math/binary_exponent.cpp | 55 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index 2cd75fea02e..7b0a0f37f41 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -24,8 +24,8 @@ * @author [Mann Mehta](https://github.com/mann2108) */ -#include /// for assert -#include /// for IO operations +#include /// for assert +#include /// for IO operations /** * @brief Mathematical algorithms @@ -43,7 +43,7 @@ namespace math { * @return (res * res * a) if modulo 2 of exponential is 0 * @return (res * res) if modulo 2 of exponential is 1 */ -long long binExpo_recursive(long long a, long long b) { +uint64_t binExpo_recursive(int64_t a, int64_t b) { /*! * Provided that b != 0, this function recursively calls itself, until an * instance of it returns 1 (which eventually occurs due to b/2 for each @@ -55,11 +55,11 @@ long long binExpo_recursive(long long a, long long b) { */ if (b == 0) { return 1; - } else if (b < 0) { // if b is not a valid exponent + } else if (b < 0) { // if b is not a valid exponent return 0; } - long long res = binExpo_recursive(a, b / 2); + uint64_t res = binExpo_recursive(a, b / 2); if (b % 2) { return res * res * a; } else { @@ -77,7 +77,7 @@ long long binExpo_recursive(long long a, long long b) { * @return 0 if the exponential number is < 0 ( 0 representing NULL since * < 0 is an invalid exponential to use ) */ -long long binExpo_iterative(long long a, long long b) { +uint64_t binExpo_iterative(int64_t a, int64_t b) { /*! * Provided b > 0, this function iteratively multiples the value res. Each * iteration of the while loop, checks if the exponential number is binary, @@ -87,8 +87,8 @@ long long binExpo_iterative(long long a, long long b) { if (b < 0) { return 0; } - long long res = 1; - while (b > 0) { // if b is not a valid exponent + uint64_t res = 1; + while (b > 0) { // if b is not a valid exponent if (b % 2) { res = res * a; } @@ -99,30 +99,29 @@ long long binExpo_iterative(long long a, long long b) { } } // namespace math -using namespace math; /** - * @brief self-test implementation + * @brief Self-test implementation * @returns void */ static void tests() { - assert(binExpo_recursive(1, 0) == 1); - assert(binExpo_recursive(746584, 0) == 1); - assert(binExpo_recursive(1, 1) == 1); - assert(binExpo_recursive(2938374, 1) == 2938374); - assert(binExpo_recursive(3, 7) == 2187); - assert(binExpo_recursive(31, 5) == 28629151); - assert(binExpo_recursive(0, 0) == 1); - assert(binExpo_recursive(1, -20) == 0); + assert(math::binExpo_recursive(1, 0) == 1); + assert(math::binExpo_recursive(746584, 0) == 1); + assert(math::binExpo_recursive(1, 1) == 1); + assert(math::binExpo_recursive(2938374, 1) == 2938374); + assert(math::binExpo_recursive(3, 7) == 2187); + assert(math::binExpo_recursive(31, 5) == 28629151); + assert(math::binExpo_recursive(0, 0) == 1); + assert(math::binExpo_recursive(1, -20) == 0); - assert(binExpo_iterative(1, 0) == 1); - assert(binExpo_iterative(746584, 0) == 1); - assert(binExpo_iterative(1, 1) == 1); - assert(binExpo_iterative(2938374, 1) == 2938374); - assert(binExpo_iterative(3, 7) == 2187); - assert(binExpo_iterative(31, 5) == 28629151); - assert(binExpo_iterative(0, 0) == 1); - assert(binExpo_iterative(1, -20) == 0); - std::cout << "all tests have passed" << std::endl; + assert(math::binExpo_iterative(1, 0) == 1); + assert(math::binExpo_iterative(746584, 0) == 1); + assert(math::binExpo_iterative(1, 1) == 1); + assert(math::binExpo_iterative(2938374, 1) == 2938374); + assert(math::binExpo_iterative(3, 7) == 2187); + assert(math::binExpo_iterative(31, 5) == 28629151); + assert(math::binExpo_iterative(0, 0) == 1); + assert(math::binExpo_iterative(1, -20) == 0); + std::cout << "All tests have successfully passed!" << std::endl; } /** @@ -130,6 +129,6 @@ static void tests() { * @returns 0 on exit */ int main() { - tests(); // perform self-test implementations + tests(); // run self-test implementations return 0; } From c1bea3c14ecd17127e95d3cb50add0998a3324a4 Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Mon, 5 Jun 2023 20:06:26 +0100 Subject: [PATCH 09/13] changed int64_t values to uint64_t --- math/binary_exponent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index 7b0a0f37f41..a08cd7e557c 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -43,7 +43,7 @@ namespace math { * @return (res * res * a) if modulo 2 of exponential is 0 * @return (res * res) if modulo 2 of exponential is 1 */ -uint64_t binExpo_recursive(int64_t a, int64_t b) { +uint64_t binExpo_recursive(uint64_t a, uint64_t b) { /*! * Provided that b != 0, this function recursively calls itself, until an * instance of it returns 1 (which eventually occurs due to b/2 for each @@ -77,7 +77,7 @@ uint64_t binExpo_recursive(int64_t a, int64_t b) { * @return 0 if the exponential number is < 0 ( 0 representing NULL since * < 0 is an invalid exponential to use ) */ -uint64_t binExpo_iterative(int64_t a, int64_t b) { +uint64_t binExpo_iterative(uint64_t a, uint64_t b) { /*! * Provided b > 0, this function iteratively multiples the value res. Each * iteration of the while loop, checks if the exponential number is binary, From 4bae829df4884b2317966bffa9d8a8f1f37f8a69 Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Mon, 5 Jun 2023 20:11:52 +0100 Subject: [PATCH 10/13] removed checking for < 0 --- math/binary_exponent.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index a08cd7e557c..3f5e6082530 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -38,8 +38,6 @@ namespace math { * @param a base number * @param b exponent number * @return 1 if the exponent number is 0 the return value will always be 1 - * @return 0 if the exponential number is < 0 ( 0 representing NULL since - * < 0 is an invalid exponential to use ) * @return (res * res * a) if modulo 2 of exponential is 0 * @return (res * res) if modulo 2 of exponential is 1 */ @@ -55,8 +53,6 @@ uint64_t binExpo_recursive(uint64_t a, uint64_t b) { */ if (b == 0) { return 1; - } else if (b < 0) { // if b is not a valid exponent - return 0; } uint64_t res = binExpo_recursive(a, b / 2); @@ -74,8 +70,6 @@ uint64_t binExpo_recursive(uint64_t a, uint64_t b) { * @param a base number * @param b exponential number * @return res if the exponential number is >= 0 - * @return 0 if the exponential number is < 0 ( 0 representing NULL since - * < 0 is an invalid exponential to use ) */ uint64_t binExpo_iterative(uint64_t a, uint64_t b) { /*! @@ -84,9 +78,6 @@ uint64_t binExpo_iterative(uint64_t a, uint64_t b) { * if so res is multiplied by the current value of a, for that iteration. * Additionally, a is multiplied by itself and b is halved by itself. */ - if (b < 0) { - return 0; - } uint64_t res = 1; while (b > 0) { // if b is not a valid exponent if (b % 2) { @@ -111,7 +102,7 @@ static void tests() { assert(math::binExpo_recursive(3, 7) == 2187); assert(math::binExpo_recursive(31, 5) == 28629151); assert(math::binExpo_recursive(0, 0) == 1); - assert(math::binExpo_recursive(1, -20) == 0); + assert(math::binExpo_recursive(1, 20) == 0); assert(math::binExpo_iterative(1, 0) == 1); assert(math::binExpo_iterative(746584, 0) == 1); @@ -120,7 +111,7 @@ static void tests() { assert(math::binExpo_iterative(3, 7) == 2187); assert(math::binExpo_iterative(31, 5) == 28629151); assert(math::binExpo_iterative(0, 0) == 1); - assert(math::binExpo_iterative(1, -20) == 0); + assert(math::binExpo_iterative(1, 20) == 0); std::cout << "All tests have successfully passed!" << std::endl; } From 324520e719cc235a989355d736f8bc5d7a5be43e Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Thu, 8 Jun 2023 17:47:39 +0100 Subject: [PATCH 11/13] multiple changes new assert test, new guard clauses ( now in both functions ), binary shift now in iterative function instead of /=2, base numbers can now be negative (exponents still unsigned if that's ok?) --- math/binary_exponent.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index 3f5e6082530..c742cb8f3eb 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -41,7 +41,7 @@ namespace math { * @return (res * res * a) if modulo 2 of exponential is 0 * @return (res * res) if modulo 2 of exponential is 1 */ -uint64_t binExpo_recursive(uint64_t a, uint64_t b) { +int64_t binExpo_recursive(int64_t a, uint64_t b) { /*! * Provided that b != 0, this function recursively calls itself, until an * instance of it returns 1 (which eventually occurs due to b/2 for each @@ -51,11 +51,13 @@ uint64_t binExpo_recursive(uint64_t a, uint64_t b) { * say, until a call to binExpo returns 1 ) and then assemble the dolls ( * with each return, res gets exponentially bigger ) */ - if (b == 0) { + if (b == 0 || a == 1) { return 1; + } else if(b == 1 || a == 0){ + return a; } - uint64_t res = binExpo_recursive(a, b / 2); + int64_t res = binExpo_recursive(a, b / 2); if (b % 2) { return res * res * a; } else { @@ -71,20 +73,26 @@ uint64_t binExpo_recursive(uint64_t a, uint64_t b) { * @param b exponential number * @return res if the exponential number is >= 0 */ -uint64_t binExpo_iterative(uint64_t a, uint64_t b) { +int64_t binExpo_iterative(int64_t a, uint64_t b) { /*! * Provided b > 0, this function iteratively multiples the value res. Each * iteration of the while loop, checks if the exponential number is binary, * if so res is multiplied by the current value of a, for that iteration. * Additionally, a is multiplied by itself and b is halved by itself. */ - uint64_t res = 1; + if (b == 0 || a == 1) { + return 1; + } else if(b == 1 || a == 0){ + return a; + } + + int64_t res = 1; while (b > 0) { // if b is not a valid exponent if (b % 2) { res = res * a; } a = a * a; - b /= 2; + b >>= 1; } return res; } @@ -95,21 +103,23 @@ uint64_t binExpo_iterative(uint64_t a, uint64_t b) { * @returns void */ static void tests() { + assert(math::binExpo_recursive(0, 1) == 0); assert(math::binExpo_recursive(1, 0) == 1); assert(math::binExpo_recursive(746584, 0) == 1); assert(math::binExpo_recursive(1, 1) == 1); assert(math::binExpo_recursive(2938374, 1) == 2938374); assert(math::binExpo_recursive(3, 7) == 2187); - assert(math::binExpo_recursive(31, 5) == 28629151); + assert(math::binExpo_recursive(-31, 5) == -28629151); assert(math::binExpo_recursive(0, 0) == 1); assert(math::binExpo_recursive(1, 20) == 0); + assert(math::binExpo_iterative(0, 1) == 0); assert(math::binExpo_iterative(1, 0) == 1); assert(math::binExpo_iterative(746584, 0) == 1); assert(math::binExpo_iterative(1, 1) == 1); assert(math::binExpo_iterative(2938374, 1) == 2938374); assert(math::binExpo_iterative(3, 7) == 2187); - assert(math::binExpo_iterative(31, 5) == 28629151); + assert(math::binExpo_iterative(-31, 5) == -28629151); assert(math::binExpo_iterative(0, 0) == 1); assert(math::binExpo_iterative(1, 20) == 0); std::cout << "All tests have successfully passed!" << std::endl; From c9ae29d9d412164732aae74176e5bc8c6c8ac8ba Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Sat, 10 Jun 2023 14:56:52 +0100 Subject: [PATCH 12/13] Update math/binary_exponent.cpp Co-authored-by: David Leal --- math/binary_exponent.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index c742cb8f3eb..06fc7da99a2 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -22,6 +22,7 @@ * skipping \f$2^1\f$ and \f$2^4\f$. * * @author [Mann Mehta](https://github.com/mann2108) + * @author [ewd00010](https://github.com/ewd00010) */ #include /// for assert From 7673a20ff384516a2b58e23240b1adc7479cfaeb Mon Sep 17 00:00:00 2001 From: ewd00010 <78011234+ewd00010@users.noreply.github.com> Date: Sat, 10 Jun 2023 14:57:38 +0100 Subject: [PATCH 13/13] Update binary_exponent.cpp small fix to assert test --- math/binary_exponent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/math/binary_exponent.cpp b/math/binary_exponent.cpp index 06fc7da99a2..436d89b56e6 100644 --- a/math/binary_exponent.cpp +++ b/math/binary_exponent.cpp @@ -112,7 +112,7 @@ static void tests() { assert(math::binExpo_recursive(3, 7) == 2187); assert(math::binExpo_recursive(-31, 5) == -28629151); assert(math::binExpo_recursive(0, 0) == 1); - assert(math::binExpo_recursive(1, 20) == 0); + assert(math::binExpo_recursive(1, 20) == 1); assert(math::binExpo_iterative(0, 1) == 0); assert(math::binExpo_iterative(1, 0) == 1); @@ -122,7 +122,7 @@ static void tests() { assert(math::binExpo_iterative(3, 7) == 2187); assert(math::binExpo_iterative(-31, 5) == -28629151); assert(math::binExpo_iterative(0, 0) == 1); - assert(math::binExpo_iterative(1, 20) == 0); + assert(math::binExpo_iterative(1, 20) == 1); std::cout << "All tests have successfully passed!" << std::endl; }