public static isClose<LEFT_TYPE extends AbstractNumber, RIGHT_TYPE extends AbstractNumber>( a as LEFT_TYPE, b as RIGHT_TYPE, rel_tol as Double = 1e-9, abs_tol as Double = 0.0 ) as Boolean:
Reports whether two real numbers are close within relative and absolute tolerances.
The comparison is equivalent to abs(a - b) <= max(rel_tol * abs(a), rel_tol * abs(b), abs_tol). Both tolerances must be non-negative. Their defaults match the conventional floating-point comparison: rel_tol = 1e-9 and abs_tol = 0.0.
IEEE 754 special values keep their normal semantics. A NaN is never close to any value, including another NaN. Positive and negative infinity are close only to the same infinity.
| Parameter | Description |
|---|---|
a | First number to compare. |
b | Second number to compare. |
rel_tol | Maximum relative tolerance; defaults to 1e-9. |
abs_tol | Maximum absolute tolerance; defaults to 0.0. |
true when the values satisfy either tolerance.
import klyn.math assert Math.isClose(0.1 + 0.2, 0.3) assert Math.isClose(0.0, 1e-12, abs_tol=1e-9) assert not Math.isClose(nan, nan) assert Math.isClose(inf, inf) assert not Math.isClose(inf, -inf)