Skip to main content

Module precision

Module precision 

Source
Expand description

Floating-point comparison and rounding utilities.

This module provides tools for safe floating-point arithmetic, including multiple comparison strategies (absolute, relative, ULP-based) and rounding utilities.

Constants§

EPS
Machine epsilon for f64 (2^-52).
F32_EPS
Machine epsilon for f32 (2^-23).

Functions§

abs_diff
Absolute difference: |a - b|.
almost_eq
Absolute-tolerance equality: |a - b| <= eps.
almost_eq_rel
Relative-tolerance equality: |a - b| <= tol * max(|a|, |b|). Equal when both are zero.
almost_eq_ulp
ULP-based floating-point equality for f64.
ceil_to_multiple
Round x up to the nearest multiple of m.
copysign
Copy the sign of b to the magnitude of a.
epsilon
Machine epsilon for a generic Real type.
floor_to_multiple
Round x down to the nearest multiple of m.
is_close
Combined absolute + relative tolerance comparison.
is_infinite
Check if f64 is infinite (positive or negative).
is_nan
Check if f64 is NaN.
is_subnormal
Check if f64 is subnormal (denormal).
next_float
Next representable f64 toward positive infinity.
prev_float
Next representable f64 toward negative infinity.
relative_diff
Relative difference: |a - b| / max(|a|, |b|).
round_to
Round x to decimals decimal places.
round_to_multiple
Round x to the nearest multiple of m.
significant_figures
Round x to n significant figures.
ulp
Distance from x to the next representable f64 toward +infinity.