3 ms·
Epsilon is not the smallest quantity that can be represented. Its the smallest amount that can be added to a number between 1 and 2. If its added to 2 the resul
by strainer 8y ago
Epsilon is not the smallest quantity that can be represented. Its the smallest amount that can be added to a number between 1 and 2. If its added to 2 the result is 2. We need to add 2 * Number.EPSILON to 2 to add anything. 4 * E to 4, 8 * E to 8, 16 * E to 16 etc.
That kind of equality test should be:
abs( a-b ) < Number.EPSILON * max( abs(a), abs(b) )
In practice I judge the scale of the quantization noise that may accrue and compare the difference to it.
It may also be possible to kind of caste precision away by adding a trick value. eg.
a + t == b + t
If a and b are positive, that is somewhat similar to:
abs( a-b ) < Number.EPSILON * t
- partycoder 8y agoThanks for pointing it out. A more popular definition is "the smallest number that yields a result different to 1 when added to 1".
- strainer 8y agoLook out - I just now tested those two extra ideas which I added for equality testing and found they dont work. This version of adding a rounding value seems to though: ( a-b + rounder ) == rounder My apologies, be careful out there :)