`test/modules/powSqrt.js` has never run — `ReferenceError: total is not defined`
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- javascript
- Domain
- testing-qa
Research direction
Start with test/modules/powSqrt.js and reproduce the ReferenceError using the node command in the issue. Read test/setup.js to understand the available counters and test/test.js to check how modules are listed. Done means powSqrt runs without the undefined variable error, is included in the suite, and its assertions pass.
Written by the indexing model from the issue text.
Description
Summary
test/modules/powSqrt.js cannot execute. It throws before its first assertion,
on a clean checkout of master, on any Node version.
Reproduction
git clone https://github.com/MikeMcl/decimal.js
cd decimal.js
node -e "require('./test/modules/powSqrt.js')"
Testing pow against sqrt...
ReferenceError: total is not defined
at .../test/modules/powSqrt.js:12
Cause
Line 12 loops on a free variable:
for (var e, n, p, r, s; total < 10000; ) {
Nothing defines total. test/setup.js keeps its counters as closure variables
inside T — passed and testNumber — and exposes them only afterwards, as
T.result. There is no global of that name, so the comparison throws on the
first evaluation of the loop condition.
test/test.js computes a local total while summing results, which looks like
where the name came from, but that variable is not in scope here and the module
is required in its own right.
Why it went unnoticed
test/test.js lists 60 modules to require, and powSqrt is not among them —
test/modules/ holds 61 files. So npm test never loads it, and the failure
never surfaces.
Why it matters
The module is a genuinely valuable cross-check that is currently doing nothing.
It compares r.pow(0.5) against r.sqrt() for random values, at a random
rounding mode and a random precision in [1, 40], ten thousand times — which
exercises naturalExponential and naturalLogarithm against the independent
Newton-Raphson path in squareRoot. Nothing else in the suite pits those two
implementations against each other.
Suggested fixes
Either would do:
-
Use the harness's own counter.
T.resultis only set once the module
finishes, so this needs a live counter — e.g. exposingtestNumberfrom
setup.js, and looping on that. -
Loop a fixed number of times, which is what the code appears to intend:
for (var e, n, p, r, s, i = 0; i < 10000; i++) {
Then add 'powSqrt' to the module list in test/test.js so it actually runs.
Be aware it is slow — ten thousand pow(0.5) calls at up to 40 significant
digits.
- Dominant language
- JavaScript
- Stars
- 7.3k
- Forks
- 498
- Avg merge
- 17h 52m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
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.
More from MikeMcl/decimal.js
-
Add `toBigInt` Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
MikeMcl/decimal.js#256 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
MikeMcl/decimal.js#257 · 1 comment ·
-
Restore toFormat Open
Difficulty 4/5 3-5 days Newbie friendliness 45/100
MikeMcl/decimal.js#251 · 3 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
MikeMcl/decimal.js#245 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
MikeMcl/decimal.js#243 · 1 comment ·
All issues in MikeMcl/decimal.js
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·