approx and deepApprox to safely compare numbers
- Dominant language
- JavaScript
- Stars
- 1.9k
- Forks
- 359
- PR merge metrics
- No merged PRs in 30d
Description
Testing equallity of numbers is a tricky business because of possible round of errors in floating point numbers. For example the following test will unexpectedly fail as the result of the left expression is `0.22000000000000003` and not `0.22`.
``` js
test.equal(2.2 / 10, 0.22);
```
It would be great to have functions like `approx` and `deepApprox` to safely compare numbers and objects/arrays containing numbers against each other. The function should compare whether the difference between the two numbers is at least a predefined factor epsilon smaller than the values itself (I guess there will be some edge cases when one of the values is zero, NaN, or Inf).
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing nodeunit's existing assert-based comparison API. Define how approx and deepApprox should compare numbers, objects, and arrays, including the stated epsilon behavior and edge cases for zero, NaN, and Infinity. Done means the functions and their expected comparisons are specified and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100