From 506aefbc782b7c87b8bd6ca88340d976b6e9bf35 Mon Sep 17 00:00:00 2001 From: nikikalwar Date: Thu, 17 Dec 2020 06:50:04 +0530 Subject: [PATCH] fixed the boundary condition --- src/algorithms/math/fast-powering/fastPowering.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/algorithms/math/fast-powering/fastPowering.js b/src/algorithms/math/fast-powering/fastPowering.js index 4f4a6b35..2c957340 100644 --- a/src/algorithms/math/fast-powering/fastPowering.js +++ b/src/algorithms/math/fast-powering/fastPowering.js @@ -13,6 +13,13 @@ export default function fastPowering(base, power) { // Anything that is raised to the power of zero is 1. return 1; } + + if (power < 0 ) { + const powerNext = power * -1; + const baseNext = 1 / base; + // console.log("sssss") + return fastPowering(baseNext, powerNext); + } if (power % 2 === 0) { // If the power is even...