5
5
use std:: fmt;
6
6
use std:: hint:: black_box;
7
7
8
+ #[ path = "../utils/mod.rs" ]
9
+ mod utils;
10
+ use utils:: check_all_outcomes;
11
+
8
12
fn ldexp ( a : f64 , b : i32 ) -> f64 {
9
13
extern "C" {
10
14
fn ldexp ( x : f64 , n : i32 ) -> f64 ;
@@ -26,35 +30,6 @@ enum NaNKind {
26
30
}
27
31
use NaNKind :: * ;
28
32
29
- /// Check that the function produces the intended set of outcomes.
30
- #[ track_caller]
31
- fn check_all_outcomes < T : Eq + std:: hash:: Hash + fmt:: Display > (
32
- expected : impl IntoIterator < Item = T > ,
33
- generate : impl Fn ( ) -> T ,
34
- ) {
35
- use std:: collections:: HashSet ;
36
-
37
- let expected: HashSet < T > = HashSet :: from_iter ( expected) ;
38
- let mut seen = HashSet :: new ( ) ;
39
- // Let's give it N times as many tries as we are expecting values.
40
- let tries = expected. len ( ) * 12 ;
41
- for i in 0 ..tries {
42
- let val = generate ( ) ;
43
- assert ! ( expected. contains( & val) , "got an unexpected value: {val}" ) ;
44
- seen. insert ( val) ;
45
- if i > tries / 2 && expected. len ( ) == seen. len ( ) {
46
- // We saw everything and we did quite a few tries, let's avoid wasting time.
47
- return ;
48
- }
49
- }
50
- // Let's see if we saw them all.
51
- for val in expected {
52
- if !seen. contains ( & val) {
53
- panic ! ( "did not get value that should be possible: {val}" ) ;
54
- }
55
- }
56
- }
57
-
58
33
// -- f32 support
59
34
#[ repr( C ) ]
60
35
#[ derive( Copy , Clone , Eq , PartialEq , Hash ) ]
@@ -81,7 +56,7 @@ const F32_EXP: u32 = 8; // 8 bits of exponent
81
56
const F32_MANTISSA : u32 = F32_SIGN_BIT - F32_EXP ;
82
57
const F32_NAN_PAYLOAD : u32 = F32_MANTISSA - 1 ;
83
58
84
- impl fmt:: Display for F32 {
59
+ impl fmt:: Debug for F32 {
85
60
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
86
61
// Alaways show raw bits.
87
62
write ! ( f, "0x{:08x} " , self . 0 ) ?;
@@ -154,7 +129,7 @@ const F64_EXP: u32 = 11; // 11 bits of exponent
154
129
const F64_MANTISSA : u32 = F64_SIGN_BIT - F64_EXP ;
155
130
const F64_NAN_PAYLOAD : u32 = F64_MANTISSA - 1 ;
156
131
157
- impl fmt:: Display for F64 {
132
+ impl fmt:: Debug for F64 {
158
133
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
159
134
// Alaways show raw bits.
160
135
write ! ( f, "0x{:08x} " , self . 0 ) ?;
0 commit comments