Skip to main content

Module ulp

Module ulp 

Source
Expand description

Integer ULP (unit in the last place) distance between floating point values.

Absolute and relative tolerances answer “is the result roughly right?”. ULP distance answers a sharper question: “how many representable floats apart are these two results?”. That is the useful metric when two implementations of the same kernel are supposed to be equivalent, because it stays meaningful across the whole dynamic range and cleanly separates a one-off rounding difference from a genuinely different computation.

The distance follows the usual total-ordering convention: adjacent floats are 1 apart, +0.0 and -0.0 are 1 apart (they are distinct representations), two NaNs are 0 apart, and a NaN against anything else is UlpFloat::MAX_ULP.

Traits§

UlpFloat
Floating point types for which an integer ULP distance is defined.

Functions§

max_ulp_distance
Largest ULP distance over two sequences, with the index where it occurs.
ulp_distance
Integer ULP distance between two floats of the same type.