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

Function next_up

datafusion/common/src/rounding.rs:174–191  ·  view source on GitHub ↗

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

(float: F)

Source from the content-addressed store, hash-verified

172/// assert_eq!(next_f, 1.0000001);
173/// ```
174pub fn next_up<F: FloatBits + Copy>(float: F) -> F {
175 let bits = float.to_bits();
176 if float.float_is_nan() || bits == F::infinity().to_bits() {
177 return float;
178 }
179
180 let abs = bits & F::CLEAR_SIGN_MASK;
181 let next_bits = if bits == F::ZERO {
182 F::TINY_BITS
183 } else if abs == F::ZERO {
184 F::ZERO
185 } else if bits == abs {
186 bits + F::ONE
187 } else {
188 bits - F::ONE
189 };
190 F::from_bits(next_bits)
191}
192
193/// Returns the next representable floating-point value smaller than the input value.
194///

Calls 2

to_bitsMethod · 0.80
float_is_nanMethod · 0.80

Tested by 10

test_next_up_nanFunction · 0.68
test_next_up_nan_f32Function · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…