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)
| 207 | /// assert_eq!(next_f, 0.99999994); |
| 208 | /// ``` |
| 209 | pub 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")), |
searching dependent graphs…