1111#![ cfg( not( target_arch = "wasm32" ) ) ]
1212
1313use std:: i16;
14- use std:: mem;
1514use std:: str;
1615
1716use core:: num:: flt2dec:: MAX_SIG_DIGITS ;
@@ -75,8 +74,7 @@ pub fn f32_random_equivalence_test<F, G>(f: F, g: G, k: usize, n: usize)
7574 let mut rng: XorShiftRng = Rand :: rand ( & mut rand:: thread_rng ( ) ) ;
7675 let f32_range = Range :: new ( 0x0000_0001u32 , 0x7f80_0000 ) ;
7776 iterate ( "f32_random_equivalence_test" , k, n, f, g, |_| {
78- let i: u32 = f32_range. ind_sample ( & mut rng) ;
79- let x: f32 = unsafe { mem:: transmute ( i) } ;
77+ let x = f32:: from_bits ( f32_range. ind_sample ( & mut rng) ) ;
8078 decode_finite ( x)
8179 } ) ;
8280}
@@ -87,8 +85,7 @@ pub fn f64_random_equivalence_test<F, G>(f: F, g: G, k: usize, n: usize)
8785 let mut rng: XorShiftRng = Rand :: rand ( & mut rand:: thread_rng ( ) ) ;
8886 let f64_range = Range :: new ( 0x0000_0000_0000_0001u64 , 0x7ff0_0000_0000_0000 ) ;
8987 iterate ( "f64_random_equivalence_test" , k, n, f, g, |_| {
90- let i: u64 = f64_range. ind_sample ( & mut rng) ;
91- let x: f64 = unsafe { mem:: transmute ( i) } ;
88+ let x = f64:: from_bits ( f64_range. ind_sample ( & mut rng) ) ;
9289 decode_finite ( x)
9390 } ) ;
9491}
@@ -105,7 +102,8 @@ pub fn f32_exhaustive_equivalence_test<F, G>(f: F, g: G, k: usize)
105102 // iterate from 0x0000_0001 to 0x7f7f_ffff, i.e. all finite ranges
106103 let ( npassed, nignored) = iterate ( "f32_exhaustive_equivalence_test" ,
107104 k, 0x7f7f_ffff , f, g, |i : usize | {
108- let x: f32 = unsafe { mem:: transmute ( i as u32 + 1 ) } ;
105+
106+ let x = f32:: from_bits ( i as u32 + 1 ) ;
109107 decode_finite ( x)
110108 } ) ;
111109 assert_eq ! ( ( npassed, nignored) , ( 2121451881 , 17643158 ) ) ;
0 commit comments