Floating Point Equality Checks
Floating Point Comparison
Kotlin follows the IEEE Standard for Floating Point Arithmetic when comparing floating point
numbers. However, this only works if the Kotlin compiler is able to statically infer the types of both operands to either
Double, or their nullable counterparts
If it cannot, Kotlin will fall back to Java’s implementations of
compare which don’t adhere to the IEEE standard in two situations:
NaN(Not-a-Number) is considered equal to itself, so
NaN == NaN.
-0.0fis considered less than
-0.0f < 0.0f.
If Kotlin can statically infer the types to
Float, it follows the IEEE standard: