Created
July 19, 2020 08:35
-
-
Save kali/3e515bae15715c3380ae925d2b531b9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TOINT: f32 = 1.0f32 / f32::EPSILON; | |
fn foo(x: f32) -> f32 { | |
let u = x.to_bits(); | |
let e = u >> 23 & 0xff; | |
if e >= 0x7f + 23 { | |
return x; | |
} | |
let s = u >> 31; | |
let y = if s == 1 { x - TOINT + TOINT } else { x + TOINT - TOINT }; | |
if y == 0.0 { | |
if s == 1 { | |
-0f32 | |
} else { | |
0f32 | |
} | |
} else { | |
y | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment