Floating point comparisons
The representation of floating-point numbers in computers is not exact. This leads to issues when comparing floating-point numbers. The assert_array_almost_equal_nulp
and assert_array_max_ulp
NumPy functions provide consistent floating-point comparisons.
ULP stands for Unit of Least Precision of floating point numbers. According to the IEEE 754 specification, a half ULP precision is required for elementary arithmetic operations. You can compare this to a ruler. A metric system ruler usually has ticks for millimetres, but beyond that you can only estimate half millimetres.
Machine epsilon is the largest relative rounding error in floating point arithmetic. Machine epsilon is equal to ULP relative to one. The NumPy finfo
function allows us to determine the machine epsilon. The Python standard library also can give you the machine epsilon value. The value should be the same as that given by NumPy.