Customizable behavior for nearlyEqual: relative or absolute difference #2752
Replies: 3 comments 1 reply
-
The |
Beta Was this translation helpful? Give feedback.
-
Ah, I see. I would love to see a method to compare absolute difference with EPSILON. Thanks anyway. |
Beta Was this translation helpful? Give feedback.
-
Yes makes sense. As a workaround you could implement an equal function which does do two checks: one for the math.import({
absEqual: (a, b) => math.equal(a, b) || math.equal(math.add(a, 1), math.add(b, 1))
})
math.config({epsilon: 1e-5})
console.log(math.equal(0, 1e-6)) // false
console.log(math.absEqual(0, 1e-6)) // true If we implement absolute nearly equal functionality I think it should go in a new config option. It makes sense, let's give this some more thought. I will reopen this issue and change the title accordingly. |
Beta Was this translation helpful? Give feedback.
-
package.json
I'm trying to set the epsilon value for comparing equality of two numbers. I want all numbers within a range of 1e-5 and below to be considered equal.
I'm doing:
But this gives an output of:
false
I've also tried:
But it prints the same output.
What's going on or what am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions