Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error:RangeError: Maximum call stack size exceeded #590

Open
nikikalwar opened this issue Dec 15, 2020 · 0 comments
Open

Error:RangeError: Maximum call stack size exceeded #590

nikikalwar opened this issue Dec 15, 2020 · 0 comments

Comments

@nikikalwar
Copy link

Issue of the description:

When using negative integers for base and power getting the below error:

RangeError: Maximum call stack size exceeded
at fastPowering (C:\Users\techn\Music\react-interview\testapp\app.js:17:23)
at fastPowering (C:\Users\techn\Music\react-interview\testapp\app.js:34:22)
at fastPowering (C:\Users\techn\Music\react-interview\testapp\app.js:34:22)
at fastPowering (C:\Users\techn\Music\react-interview\testapp\app.js:34:22)
at fastPowering (C:\Users\techn\Music\react-interview\testapp\app.js:34:22)
at fastPowering (C:\Users\techn\Music\react-interview\testapp\app.js:34:22)
at fastPowering (C:\Users\techn\Music\react-interview\testapp\app.js:34:22)
at fastPowering (C:\Users\techn\Music\react-interview\testapp\app.js:34:22)
at fastPowering (C:\Users\techn\Music\react-interview\testapp\app.js:34:22)
at fastPowering (C:\Users\techn\Music\react-interview\testapp\app.js:34:22)

fastPowering(5,-5);
fastPowering(-5,5);

https://github.com/trekhleb/javascript-algorithms/blob/master/src/algorithms/math/fast-powering/fastPowering.js

It can be resolved by adding the below if statement to the code.

if(power<0){ power=power*-1; base=1/base; // console.log(base); fastPowering(base,power); }

Can I open a pull request to work on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant