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

Function next_down_f32

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

Source from the content-addressed store, hash-verified

282// Next representable f32 strictly less than `x`.
283#[inline]
284fn next_down_f32(x: f32) -> f32 {
285 if x.is_nan() || x == f32::NEG_INFINITY {
286 return x;
287 }
288 let bits = x.to_bits();
289 if x.is_sign_negative() {
290 // negative: increasing magnitude moves toward -inf
291 f32::from_bits(bits + 1)
292 } else {
293 // positive or +0: decreasing bits moves toward 0 and then negative
294 if bits == 0 {
295 f32::from_bits(0x8000_0001) // +0 -> smallest negative subnormal
296 } else {
297 f32::from_bits(bits - 1)
298 }
299 }
300}
301
302// --- f64 -> f32 with explicit rounding mode ---
303// Round with the host default (RNE), then nudge one ULP when the result lands on

Callers 1

f64_to_f32_with_rmFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected