MCPcopy Create free account
hub / github.com/apache/datafusion / next_down

Function next_down

datafusion/common/src/rounding.rs:209–226  ·  view source on GitHub ↗

Returns the next representable floating-point value smaller than the input value. This function takes a floating-point value that implements the FloatBits trait, calculates the next representable value smaller than the input, and returns it. If the input value is NaN or negative infinity, the function returns the input value. # Examples ``` use datafusion_common::rounding::next_down; let f: f

(float: F)

Source from the content-addressed store, hash-verified

207/// assert_eq!(next_f, 0.99999994);
208/// ```
209pub fn next_down<F: FloatBits + Copy>(float: F) -> F {
210 let bits = float.to_bits();
211 if float.float_is_nan() || bits == F::neg_infinity().to_bits() {
212 return float;
213 }
214
215 let abs = bits & F::CLEAR_SIGN_MASK;
216 let next_bits = if bits == F::ZERO {
217 F::NEG_ZERO
218 } else if abs == F::ZERO {
219 F::NEG_TINY_BITS
220 } else if bits == abs {
221 bits - F::ONE
222 } else {
223 bits + F::ONE
224 };
225 F::from_bits(next_bits)
226}
227
228#[cfg(any(
229 not(any(target_arch = "x86_64", target_arch = "aarch64")),

Calls 2

to_bitsMethod · 0.80
float_is_nanMethod · 0.80

Tested by 11

test_next_downFunction · 0.68
test_next_down_nanFunction · 0.68
test_next_down_nan_f32Function · 0.68
test_next_down_zero_f32Function · 0.68
test_next_down_zero_f64Function · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…