NumUtils Type Module

Numeric utility functions for working with floating-point values.

In particular, is_approx_eq and is_approx_eq_to_places provide IEEE 754-style hybrid (absolute + relative) tolerance comparison

is_approx_eq : F64, F64 -> Bool

Test whether two F64 values are approximately equal, using a hybrid of absolute and relative tolerance

|a - b| <= max(abs_tol, rel_tol * max(|a|, |b|))

Defaults: abs_tol = 1e-6, rel_tol = 1e-9.

expect is_approx_eq(1.0, 0.999999)
expect !is_approx_eq(1.0, 0.99999)
is_approx_eq_to_places : F64, F64, U64 -> Bool

Test whether two F64 values are approximately equal to within 10^-places absolute tolerance, plus a small relative tolerance (1e-9) so the check stays meaningful at large magnitudes:

|a - b| <= max(10^-places, 1e-9 * max(|a|, |b|))

expect is_approx_eq_to_places(1.0, 0.99999, 5)
expect !is_approx_eq_to_places(1.0, 0.99999, 6)