diff --git a/testcrate/tests/conv.rs b/testcrate/tests/conv.rs index 8c2a2b0e..5e99c93c 100644 --- a/testcrate/tests/conv.rs +++ b/testcrate/tests/conv.rs @@ -4,12 +4,14 @@ macro_rules! i_to_f { ($($from:ty, $into:ty, $fn:ident);*;) => { $( fuzz(N, |x: $from| { - // This makes sure that the conversion produced the best rounding possible. - // This assumes that float to integer conversion is correct. let f0 = x as $into; - let y_minus_ulp = <$into>::from_bits(f0.to_bits().wrapping_sub(1)) as $from; - let y = f0 as $from; - let y_plus_ulp = <$into>::from_bits(f0.to_bits().wrapping_add(1)) as $from; + let f1: $into = $fn(x); + // This makes sure that the conversion produced the best rounding possible, and does + // this independent of `x as $into` rounding correctly. + // This assumes that float to integer conversion is correct. + let y_minus_ulp = <$into>::from_bits(f1.to_bits().wrapping_sub(1)) as $from; + let y = f1 as $from; + let y_plus_ulp = <$into>::from_bits(f1.to_bits().wrapping_add(1)) as $from; let error_minus = <$from as Int>::abs_diff(y_minus_ulp, x); let error = <$from as Int>::abs_diff(y, x); let error_plus = <$from as Int>::abs_diff(y_plus_ulp, x); @@ -25,7 +27,7 @@ macro_rules! i_to_f { "incorrect rounding by {}({}): {}, ({}, {}, {}), errors ({}, {}, {})", stringify!($fn), x, - f0.to_bits(), + f1.to_bits(), y_minus_ulp, y, y_plus_ulp, @@ -35,9 +37,14 @@ macro_rules! i_to_f { ); } // test against native conversion - let f1: $into = $fn(x); if f0 != f1 { - panic!("{}({}): expected: {}, found: {}", stringify!($fn), x, f0, f1); + panic!( + "{}({}): expected: {}, found: {}", + stringify!($fn), + x, + f0.to_bits(), + f1.to_bits() + ); } }); )*