Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit af8703e

Browse files
authored
Merge pull request #153 from m1el/floorf-uint-underflow
Fixed uint overflow in floorf for negative exponents
2 parents 50f854a + 7ebf006 commit af8703e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

libm/src/math/floorf.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn floorf(x: f32) -> f32 {
1212
}
1313
}
1414
let mut ui = x.to_bits();
15-
let e = (((ui >> 23) & 0xff) - 0x7f) as i32;
15+
let e = (((ui >> 23) as i32) & 0xff) - 0x7f;
1616

1717
if e >= 23 {
1818
return x;
@@ -37,3 +37,11 @@ pub fn floorf(x: f32) -> f32 {
3737
}
3838
return f32::from_bits(ui);
3939
}
40+
41+
#[cfg(test)]
42+
mod tests {
43+
#[test]
44+
fn no_overflow() {
45+
assert_eq!(super::floorf(0.5), 0.0);
46+
}
47+
}

0 commit comments

Comments
 (0)