1#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2pub fn nextafterf(x: f32, y: f32) -> f32 {
3 if x.is_nan() || y.is_nan() {
4 return x + y;
5 }
6
7 let mut ux_i = x.to_bits();
8 let uy_i = y.to_bits();
9 if ux_i == uy_i {
10 return y;
11 }
12
13 let ax = ux_i & 0x7fff_ffff_u32;
14 let ay = uy_i & 0x7fff_ffff_u32;
15 if ax == 0 {
16 if ay == 0 {
17 return y;
18 }
19 ux_i = (uy_i & 0x8000_0000_u32) | 1;
20 } else if ax > ay || ((ux_i ^ uy_i) & 0x8000_0000_u32) != 0 {
21 ux_i -= 1;
22 } else {
23 ux_i += 1;
24 }
25
26 let e = ux_i.wrapping_shr(0x7f80_0000_u32);
27 // raise overflow if ux_f is infinite and x is finite
28 if e == 0x7f80_0000_u32 {
29 force_eval!(x + x);
30 }
31 let ux_f = f32::from_bits(ux_i);
32 // raise underflow if ux_f is subnormal or zero
33 if e == 0 {
34 force_eval!(x * x + ux_f * ux_f);
35 }
36 ux_f
37}
38