File tree Expand file tree Collapse file tree 1 file changed +5
-16
lines changed
Expand file tree Collapse file tree 1 file changed +5
-16
lines changed Original file line number Diff line number Diff line change 11//! Provides utility functions for working with floating point precision
22
3+ use approx:: AbsDiffEq ;
4+
35/// Standard epsilon, maximum relative precision of IEEE 754 double-precision
46/// floating point numbers (64 bit) e.g. `2^-53`
57pub const F64_PREC : f64 = 0.00000000000000011102230246251565 ;
68
79/// Default accuracy for `f64`, equivalent to `0.0 * F64_PREC`
810pub const DEFAULT_F64_ACC : f64 = 0.0000000000000011102230246251565 ;
911
10- /// Returns true if `a` and `b `are within `acc` of each other.
11- /// If `a` or `b` are infinite, returns `true` only if both are
12- /// infinite and similarly signed. Always returns `false` if
13- /// either number is a `NAN`.
12+ /// Compares if two floats are close via `approx::abs_diff_eq`
13+ /// using a maximum absolute difference (epsilon) of `acc`.
1414pub fn almost_eq ( a : f64 , b : f64 , acc : f64 ) -> bool {
15- // only true if a and b are infinite with same
16- // sign
17- if a. is_infinite ( ) || b. is_infinite ( ) {
18- return a == b;
19- }
20-
21- // NANs are never equal
22- if a. is_nan ( ) && b. is_nan ( ) {
23- return false ;
24- }
25-
26- ( a - b) . abs ( ) < acc
15+ a. abs_diff_eq ( & b, acc)
2716}
2817
2918/// Compares if two floats are close via `approx::relative_eq!`
You can’t perform that action at this time.
0 commit comments