Skip to content

Commit a06d237

Browse files
committed
tmp
1 parent df68694 commit a06d237

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Diff for: testcrate/tests/conv.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ macro_rules! i_to_f {
44
($($from:ty, $into:ty, $fn:ident);*;) => {
55
$(
66
fuzz(N, |x: $from| {
7-
// This makes sure that the conversion produced the best rounding possible.
8-
// This assumes that float to integer conversion is correct.
97
let f0 = x as $into;
10-
let y_minus_ulp = <$into>::from_bits(f0.to_bits().wrapping_sub(1)) as $from;
11-
let y = f0 as $from;
12-
let y_plus_ulp = <$into>::from_bits(f0.to_bits().wrapping_add(1)) as $from;
8+
let f1: $into = $fn(x);
9+
// This makes sure that the conversion produced the best rounding possible, and does
10+
// this independent of `x as $into` rounding correctly.
11+
// This assumes that float to integer conversion is correct.
12+
let y_minus_ulp = <$into>::from_bits(f1.to_bits().wrapping_sub(1)) as $from;
13+
let y = f1 as $from;
14+
let y_plus_ulp = <$into>::from_bits(f1.to_bits().wrapping_add(1)) as $from;
1315
let error_minus = <$from as Int>::abs_diff(y_minus_ulp, x);
1416
let error = <$from as Int>::abs_diff(y, x);
1517
let error_plus = <$from as Int>::abs_diff(y_plus_ulp, x);
@@ -25,7 +27,7 @@ macro_rules! i_to_f {
2527
"incorrect rounding by {}({}): {}, ({}, {}, {}), errors ({}, {}, {})",
2628
stringify!($fn),
2729
x,
28-
f0.to_bits(),
30+
f1.to_bits(),
2931
y_minus_ulp,
3032
y,
3133
y_plus_ulp,
@@ -35,9 +37,14 @@ macro_rules! i_to_f {
3537
);
3638
}
3739
// test against native conversion
38-
let f1: $into = $fn(x);
3940
if f0 != f1 {
40-
panic!("{}({}): expected: {}, found: {}", stringify!($fn), x, f0, f1);
41+
panic!(
42+
"{}({}): expected: {}, found: {}",
43+
stringify!($fn),
44+
x,
45+
f0.to_bits(),
46+
f1.to_bits()
47+
);
4148
}
4249
});
4350
)*

0 commit comments

Comments
 (0)