@@ -4,12 +4,14 @@ macro_rules! i_to_f {
4
4
( $( $from: ty, $into: ty, $fn: ident) ;* ; ) => {
5
5
$(
6
6
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.
9
7
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;
13
15
let error_minus = <$from as Int >:: abs_diff( y_minus_ulp, x) ;
14
16
let error = <$from as Int >:: abs_diff( y, x) ;
15
17
let error_plus = <$from as Int >:: abs_diff( y_plus_ulp, x) ;
@@ -25,7 +27,7 @@ macro_rules! i_to_f {
25
27
"incorrect rounding by {}({}): {}, ({}, {}, {}), errors ({}, {}, {})" ,
26
28
stringify!( $fn) ,
27
29
x,
28
- f0 . to_bits( ) ,
30
+ f1 . to_bits( ) ,
29
31
y_minus_ulp,
30
32
y,
31
33
y_plus_ulp,
@@ -35,9 +37,14 @@ macro_rules! i_to_f {
35
37
) ;
36
38
}
37
39
// test against native conversion
38
- let f1: $into = $fn( x) ;
39
40
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
+ ) ;
41
48
}
42
49
} ) ;
43
50
) *
0 commit comments