trekhleb / trekhleb/javascript-algorithms
Error:RangeError: Maximum call stack size exceeded
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 197k
- Forks
- 31k
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/algorithms/math/fast-powering/fastPowering.js and reproduce the issue using fastPowering(5, -5) and fastPowering(-5, 5). Check the negative-exponent behavior and verify that both calls complete without a maximum call stack error and return the expected power values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100