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