MCPcopy Index your code
hub / github.com/RustPython/RustPython / nextafter

Function nextafter

crates/common/src/float_ops.rs:107–126  ·  view source on GitHub ↗
(x: f64, y: f64)

Source from the content-addressed store, hash-verified

105// nextafter algorithm based off of https://gitlab.com/bronsonbdevost/next_afterf
106#[allow(clippy::float_cmp)]
107pub fn nextafter(x: f64, y: f64) -> f64 {
108 if x == y {
109 y
110 } else if x.is_nan() || y.is_nan() {
111 f64::NAN
112 } else if x >= f64::INFINITY {
113 f64::MAX
114 } else if x <= f64::NEG_INFINITY {
115 f64::MIN
116 } else if x == 0.0 {
117 f64::from_bits(1).copysign(y)
118 } else {
119 // next x after 0 if y is farther from 0 than x, otherwise next towards 0
120 // the sign is a separate bit in floats, so bits+1 moves away from 0 no matter the float
121 let b = x.to_bits();
122 let bits = if (y > x) == (x > 0.0) { b + 1 } else { b - 1 };
123 let ret = f64::from_bits(bits);
124 if ret == 0.0 { ret.copysign(x) } else { ret }
125 }
126}
127
128#[allow(clippy::float_cmp)]
129pub fn nextafter_with_steps(x: f64, y: f64, steps: u64) -> f64 {

Callers 1

ulpFunction · 0.70

Calls 1

is_nanMethod · 0.45

Tested by

no test coverage detected