macOSLinuxWindowswasm
#import "Sloppy_Math";
Approximate float comparison and the numeric limits of a type.
Procedures#
($T: Type) -> T
The smallest value of the numeric type T: the lowest integer, so -128 for s8 and 0 for any unsigned type.
($T: Type) -> T
The largest finite value of the numeric type T: 255 for u8, Math.FLOAT32_MAX for float32. Any non-numeric type fails an assert.
(f: float, epsilon := DEFAULT_EPSILON) -> bool
True when abs(f) is at most epsilon, which is 0.0001 unless given. The bound is inclusive, and a NaN is never approximately zero.
(f0: float, f1: float, epsilon := DEFAULT_EPSILON) -> bool
True when f0 and f1 differ by at most epsilon (0.0001 unless given). The test is absolute, not relative, and the bound is inclusive.
#import "Math";
assert(values_are_close(1.0, 1.00005));
assert(!values_are_close(1.0, 1.01));
assert(values_are_close(1.0, 1.01, 0.1));
assert(values_are_close(xyz(1, 2, 3), xyz(1, 2, 3.00001)));
assert(!values_are_close(xy(1, 2), xy(1, 3)));
↗