Skip to content

Instantly share code, notes, and snippets.

@m1el
Created October 16, 2018 01:27
Show Gist options
  • Save m1el/dc18a85b82357589825d9ffa4532b0a6 to your computer and use it in GitHub Desktop.
Save m1el/dc18a85b82357589825d9ffa4532b0a6 to your computer and use it in GitHub Desktop.
fn main() {
let mut failed = 0usize;
for i in 0..=u32::max_value() {
if i & 0xffffff == 0 { println!("{}", i); }
let x = f32::from_bits(i);
let r_std = x.round();
let r_hoc = (x+0.5).floor();
if r_std.to_bits() != r_hoc.to_bits() {
println!("round for {} fails", x);
failed += 1;
if failed > 10 { break }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment