Merge pull request #153 from m1el/floorf-uint-underflow

Fixed uint overflow in floorf for negative exponents
This commit is contained in:
Alex Crichton
2019-05-02 14:35:15 -05:00
committed by GitHub
+9 -1
View File
@@ -12,7 +12,7 @@ pub fn floorf(x: f32) -> f32 {
}
}
let mut ui = x.to_bits();
let e = (((ui >> 23) & 0xff) - 0x7f) as i32;
let e = (((ui >> 23) as i32) & 0xff) - 0x7f;
if e >= 23 {
return x;
@@ -37,3 +37,11 @@ pub fn floorf(x: f32) -> f32 {
}
return f32::from_bits(ui);
}
#[cfg(test)]
mod tests {
#[test]
fn no_overflow() {
assert_eq!(super::floorf(0.5), 0.0);
}
}