mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
fixed the boundary condition
This commit is contained in:
parent
3b1fcd8333
commit
506aefbc78
@ -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...
|
||||
|
Loading…
Reference in New Issue
Block a user