Construction is done by assigning an "epsilon" value, as demonstrated above, which is then incremented by 1 to
obtain the value that is actually used for comparing ratios. Doubles have 15 decimal-digits'-worth of
precision, so an ε of 1e-16 or lower will effectively result in strict equality:
implicitval ε: E = 1e-15// ε: hammerlab.math.tolerance.E = ±1.000000000000001implicitval ε: E = 1e-16// ε: hammerlab.math.tolerance.E = ±1.0
Note that equality (and by extension, ≤ and ≥) are not transitive! Don't try to use this as an Ordering!
Note also that 0 can only ===0; whether a Double shoould be considered fuzzily-equal to 0 is a
complicated question (likely requiring tracking of floating-point-arithmetic error) that this simple implementation
of fuzzy-equality doesn't attempt to address.
Consider Doubles to be "equal" if they are within a factor of ε of one another:
Construction is done by assigning an "epsilon" value, as demonstrated above, which is then incremented by 1 to obtain the value that is actually used for comparing ratios. Doubles have 15 decimal-digits'-worth of precision, so an ε of 1e-16 or lower will effectively result in strict equality:
Note that equality (and by extension, ≤ and ≥) are not transitive! Don't try to use this as an Ordering!
Note also that 0 can only === 0; whether a Double shoould be considered fuzzily-equal to 0 is a complicated question (likely requiring tracking of floating-point-arithmetic error) that this simple implementation of fuzzy-equality doesn't attempt to address.