diff --git a/tests/pass/float.rs b/tests/pass/float.rs index abd44fccee..b66bbe897e 100644 --- a/tests/pass/float.rs +++ b/tests/pass/float.rs @@ -12,15 +12,16 @@ use std::fmt::{Debug, Display, LowerHex}; use std::hint::black_box; use std::{f32, f64}; -/// Another form of checking if 2 floating point numbers are almost equal to eachother +/// Another way of checking if 2 floating point numbers are almost equal to eachother. /// Using `a` and `b` as floating point numbers: /// /// Instead of doing a simple EPSILON check (which we did at first): /// Absolute difference of `a` and `b` can't be greater than some E (10^-6, ...). +/// `(a - b).asb() <= E` /// -/// We look at ULP: `Units in the Last Place` or `Units of Least Precision` +/// We will now use ULP: `Units in the Last Place` or `Units of Least Precision` /// It is the absolute difference of the *unsigned integer* representation of `a` and `b`. -/// For example for f32, which in IEEE format looks like this: +/// For example checking 2 f32's, which in IEEE format looks like this: /// /// s: sign bit /// e: exponent bits @@ -33,11 +34,11 @@ use std::{f32, f64}; /// Same with exponents but no zero checking. /// /// So when Sign and Exponent are the same, we can get a reasonable ULP value -/// by doing the operation explained above. And if this is less than or equal to our chosen upper bound +/// by doing the absolute difference, and if this is less than or equal to our chosen upper bound /// we can say that `a` and `b` are approximately equal. /// /// Basically ULP can be seen as a distance metric of floating point numbers, but having -/// the same amount of "spacing" between consecutive numbers. So eventhough 2 very large floating point numbers +/// the same amount of "spacing" between all consecutive representable values. So eventhough 2 very large floating point numbers /// have a large value difference, their ULP can still be 1, so they are still "approximatly equal", /// but the EPSILON check would have failed. macro_rules! assert_approx_eq {