Skip to content

Commit 25ecf26

Browse files
update explanation of approx_check
1 parent 9a397ea commit 25ecf26

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

tests/pass/float.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ use std::fmt::{Debug, Display, LowerHex};
1212
use std::hint::black_box;
1313
use std::{f32, f64};
1414

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.
1616
/// Using `a` and `b` as floating point numbers:
1717
///
1818
/// Instead of doing a simple EPSILON check (which we did at first):
1919
/// Absolute difference of `a` and `b` can't be greater than some E (10^-6, ...).
20+
/// `(a - b).asb() <= E`
2021
///
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`
2223
/// 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:
2425
///
2526
/// s: sign bit
2627
/// e: exponent bits
@@ -33,11 +34,11 @@ use std::{f32, f64};
3334
/// Same with exponents but no zero checking.
3435
///
3536
/// 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
3738
/// we can say that `a` and `b` are approximately equal.
3839
///
3940
/// 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
4142
/// have a large value difference, their ULP can still be 1, so they are still "approximatly equal",
4243
/// but the EPSILON check would have failed.
4344
macro_rules! assert_approx_eq {

0 commit comments

Comments
 (0)