55use std:: fmt;
66use std:: hint:: black_box;
77
8+ #[ path = "../utils/mod.rs" ]
9+ mod utils;
10+ use utils:: check_all_outcomes;
11+
812fn ldexp ( a : f64 , b : i32 ) -> f64 {
913 extern "C" {
1014 fn ldexp ( x : f64 , n : i32 ) -> f64 ;
@@ -26,35 +30,6 @@ enum NaNKind {
2630}
2731use NaNKind :: * ;
2832
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-
5833// -- f32 support
5934#[ repr( C ) ]
6035#[ derive( Copy , Clone , Eq , PartialEq , Hash ) ]
@@ -81,7 +56,7 @@ const F32_EXP: u32 = 8; // 8 bits of exponent
8156const F32_MANTISSA : u32 = F32_SIGN_BIT - F32_EXP ;
8257const F32_NAN_PAYLOAD : u32 = F32_MANTISSA - 1 ;
8358
84- impl fmt:: Display for F32 {
59+ impl fmt:: Debug for F32 {
8560 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
8661 // Alaways show raw bits.
8762 write ! ( f, "0x{:08x} " , self . 0 ) ?;
@@ -154,7 +129,7 @@ const F64_EXP: u32 = 11; // 11 bits of exponent
154129const F64_MANTISSA : u32 = F64_SIGN_BIT - F64_EXP ;
155130const F64_NAN_PAYLOAD : u32 = F64_MANTISSA - 1 ;
156131
157- impl fmt:: Display for F64 {
132+ impl fmt:: Debug for F64 {
158133 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
159134 // Alaways show raw bits.
160135 write ! ( f, "0x{:08x} " , self . 0 ) ?;
0 commit comments