1 | // [See license/rust-lang/libm] Copyright (c) 2018 Jorge Aparicio |
---|---|
2 | pub fn ceil(x: f32) -> f32 { |
3 | let mut ui: u32 = x.to_bits(); |
4 | let e: i32 = (((ui >> 23) & 0xff).wrapping_sub(0x7f)) as i32; |
5 | if e >= 23 { |
6 | return x; |
7 | } |
8 | if e >= 0 { |
9 | let m: u32 = 0x007fffff >> e; |
10 | if (ui & m) == 0 { |
11 | return x; |
12 | } |
13 | if ui >> 31 == 0 { |
14 | ui += m; |
15 | } |
16 | ui &= !m; |
17 | } else { |
18 | if ui >> 31 != 0 { |
19 | return -0.0; |
20 | } else if ui << 1 != 0 { |
21 | return 1.0; |
22 | } |
23 | } |
24 | f32::from_bits(ui) |
25 | } |
26 |