isZero() does not respect config.epsilon #2838
Replies: 2 comments 14 replies
-
Oh, actually all that So my thinking at the moment: This violation is unnecessary and the situation is buggy. Change equal to truly be relative, so that the only thing equal to 0 is actual 0. Perhaps add an isNegligible function to mean "is less than config.epsilon in absolute value" -- that may need to be used in some places that relying on the "within Number.EPSILON is equal" fallback. But I didn't want to file a bug until I could get at least a second opinion. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
We definitely have to at least improve the documentation about it 😅 .
O wow, now I see. I was at first assuming it was also using mathjs/test/unit-tests/utils/number.test.js Lines 546 to 559 in b050d5e 1. Yes makes sense to me to introduce two variants of 2. The current behavior of comparing to zero is weird anyway, so I think it is a good idea to improve that. It makes sense to me to introduce a 3. The function |
Beta Was this translation helpful? Give feedback.
-
This concern came up in the implementation of the polynomial root solver that I am doing as a basic algebraic manipulation benchmark for mathjs/picomath. I was using
isZero
to test the discriminant of quadratics/cubics, but it involves some cancellation, so it can come out to a minuscule technically non-zero floating point number. I had assumed thatisZero
was a "relational function" as described in the mathjs docs and hence would consider such a result to be zero. However, that's not currently the case, leading to erroneous results (two distinct roots when there really should be one, or complex roots when they should be real, for example). So should we:(a) Modify isZero to respect config.epsilon? (Clearly a breaking change...)
(b) Add an equalZero function? (Right now one can use
equal(x, 0)
but that leads to an unnecessarily complicated double dispatch.)Beta Was this translation helpful? Give feedback.
All reactions