Skip to content

Commit 290fe91

Browse files
committed
Add tests for large differences in magnitude
1 parent 2988c0a commit 290fe91

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/core/tests/num/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,17 @@ macro_rules! test_float {
870870
assert!(($nan as $fty).midpoint(1.0).is_nan());
871871
assert!((1.0 as $fty).midpoint($nan).is_nan());
872872
assert!(($nan as $fty).midpoint($nan).is_nan());
873+
874+
// test if large differences in magnitude are still correctly computed.
875+
// NOTE: that because of how small x and y are, x + y can never overflow
876+
// so (x + y) / 2.0 is always correct
877+
for i in 64..128 {
878+
for j in 0..64u8 {
879+
let x = (2.0f32.powi(i) + f32::from(j)) / 2.0;
880+
let y = 2.0f32.powi(i).midpoint(f32::from(j));
881+
assert_eq!(x, y);
882+
}
883+
}
873884
}
874885
#[test]
875886
fn rem_euclid() {

0 commit comments

Comments
 (0)