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

Function ulp

crates/common/src/float_ops.rs:191–204  ·  view source on GitHub ↗
(x: f64)

Source from the content-addressed store, hash-verified

189}
190
191pub fn ulp(x: f64) -> f64 {
192 if x.is_nan() {
193 return x;
194 }
195 let x = x.abs();
196 let x2 = nextafter(x, f64::INFINITY);
197 if x2.is_infinite() {
198 // special case: x is the largest positive representable float
199 let x2 = nextafter(x, f64::NEG_INFINITY);
200 x - x2
201 } else {
202 x2 - x
203 }
204}
205
206pub fn round_float_digits(x: f64, ndigits: i32) -> Option<f64> {
207 let float = if ndigits.is_zero() {

Callers

nothing calls this directly

Calls 4

absMethod · 0.80
nextafterFunction · 0.70
is_nanMethod · 0.45
is_infiniteMethod · 0.45

Tested by

no test coverage detected