Skip to content

Commit

Permalink
Remove some transmutes
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed May 5, 2018
1 parent e471c20 commit 6c8ec84
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/libcore/tests/num/flt2dec/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#![cfg(not(target_arch = "wasm32"))]

use std::i16;
use std::mem;
use std::str;

use core::num::flt2dec::MAX_SIG_DIGITS;
Expand Down Expand Up @@ -75,8 +74,7 @@ pub fn f32_random_equivalence_test<F, G>(f: F, g: G, k: usize, n: usize)
let mut rng: XorShiftRng = Rand::rand(&mut rand::thread_rng());
let f32_range = Range::new(0x0000_0001u32, 0x7f80_0000);
iterate("f32_random_equivalence_test", k, n, f, g, |_| {
let i: u32 = f32_range.ind_sample(&mut rng);
let x: f32 = unsafe {mem::transmute(i)};
let x = f32::from_bits(f32_range.ind_sample(&mut rng));
decode_finite(x)
});
}
Expand All @@ -87,8 +85,7 @@ pub fn f64_random_equivalence_test<F, G>(f: F, g: G, k: usize, n: usize)
let mut rng: XorShiftRng = Rand::rand(&mut rand::thread_rng());
let f64_range = Range::new(0x0000_0000_0000_0001u64, 0x7ff0_0000_0000_0000);
iterate("f64_random_equivalence_test", k, n, f, g, |_| {
let i: u64 = f64_range.ind_sample(&mut rng);
let x: f64 = unsafe {mem::transmute(i)};
let x = f64::from_bits(f64_range.ind_sample(&mut rng));
decode_finite(x)
});
}
Expand All @@ -105,7 +102,8 @@ pub fn f32_exhaustive_equivalence_test<F, G>(f: F, g: G, k: usize)
// iterate from 0x0000_0001 to 0x7f7f_ffff, i.e. all finite ranges
let (npassed, nignored) = iterate("f32_exhaustive_equivalence_test",
k, 0x7f7f_ffff, f, g, |i: usize| {
let x: f32 = unsafe {mem::transmute(i as u32 + 1)};

let x = f32::from_bits(i as u32 + 1);
decode_finite(x)
});
assert_eq!((npassed, nignored), (2121451881, 17643158));
Expand Down

0 comments on commit 6c8ec84

Please sign in to comment.