If this is being used for tests,
kotlin.test
has the following two functions which include a tolerance for equality of floating point numbers.
/** Asserts that the difference between the [actual] and the [expected] is within an [absoluteTolerance], with an optional [message]. */
@SinceKotlin("1.5")
fun assertEquals(expected: Double, actual: Double, absoluteTolerance: Double, message: String? = null) {
checkDoublesAreEqual(expected, actual, absoluteTolerance, message)
}
/** Asserts that the difference between the [actual] and the [expected] is within an [absoluteTolerance], with an optional [message]. */
@SinceKotlin("1.5")
fun assertEquals(expected: Float, actual: Float, absoluteTolerance: Float, message: String? = null) {
checkFloatsAreEqual(expected, actual, absoluteTolerance, message)
}