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

Fixed uint overflow in floorf for negative exponents #153

Merged
merged 2 commits into from
May 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/math/floorf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}