MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / next_up_f32

Function next_up_f32

crates/virtual-machine/src/cpu/alu.rs:264–280  ·  view source on GitHub ↗
(x: f32)

Source from the content-addressed store, hash-verified

262// Next representable f32 strictly greater than `x`.
263#[inline]
264fn next_up_f32(x: f32) -> f32 {
265 if x.is_nan() || x == f32::INFINITY {
266 return x;
267 }
268 let bits = x.to_bits();
269 if x.is_sign_negative() {
270 // negative: decreasing magnitude (bits decrease) moves toward 0 / +inf
271 if bits == 0x8000_0000 {
272 f32::from_bits(0x0000_0001) // -0 -> smallest positive subnormal
273 } else {
274 f32::from_bits(bits - 1)
275 }
276 } else {
277 // positive or +0: increasing bits moves toward +inf
278 f32::from_bits(bits + 1)
279 }
280}
281
282// Next representable f32 strictly less than `x`.
283#[inline]

Callers 1

f64_to_f32_with_rmFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected