Search⌘ K
AI Features

Floating Point Equality Checks

Explore how Kotlin handles floating point equality by following the IEEE standard when types are inferred, and when it reverts to Java's rules. Learn the pitfalls of comparing floating point numbers directly and best practices like using tolerance or avoiding floating points for exact values. This lesson prepares you for writing precise and reliable Kotlin code.

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 Float, Double, or their nullable counterparts Float? and ...