Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronKutch committed Dec 8, 2020
1 parent df68694 commit a06d237
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions testcrate/tests/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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()
);
}
});
)*
Expand Down

0 comments on commit a06d237

Please sign in to comment.