[][src]Function almost::zero_with

pub fn zero_with<T: AlmostEqual>(v: T, tolerance: T::Float) -> bool

Returns true if a is almost zero, using the specified absolute tolerance.

assert!(!almost::zero_with(std::f32::EPSILON, std::f32::EPSILON));

This is a version of almost::zero which does not define a tolerance value for you.

The correct choice of tolerance value is tricky and differs depending on:

  • The type of numerical operations you're doing.
  • The scale of the values used.
  • The number of operations performed.

However, for comparison with zero it is possible to give broad guidelines (note that these do not apply to almost::equal_with, which for which the correct decision is more challenging).

Panics

This function panics in debug mode if tolerance is not greater than zero, as the results are unlikely to be sensible.

In release builds it should never panic.