pub fn zero<T: AlmostEqual>(a: T) -> bool
Expand description
Returns true
if a
is almost zero.
assert!(almost::zero(std::f32::EPSILON));
This is the correct function to use when comparing to see if a value is almost zero.
Testing if a value is zero is a unique case where a relative comparison becomes almost useless, and an absolute comparison becomes the obviously correct choice.
As such, this performs comparison with a absolute threshold. The threshold
used assumes half of the bits have been lost to rounding, which is a good
default for user code that does not keep track of this, while still tight
enough for it to be unlikely to cause false positives in practice. However,
if you need a tighter bound, the function
almost::zero_with
can be used.