Tóth István Zoltán
07/02/2023, 2:41 AMephemient
07/02/2023, 5:46 AMMichael Paus
07/02/2023, 6:27 AMTóth István Zoltán
07/02/2023, 6:35 AMfun Double.compareToDelta(other: Double) : Int {
val epsilon = max(this.ulp, other.ulp) * 1000
return when {
abs(this - other) <= epsilon -> 0
this < other -> -1
this > other -> 1
this.isNaN() && other.isNaN() -> 0
else -> 0
}
}
For more info:
https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
https://www.gamedevs.org/uploads/numerical-robustness-geometric-calculations.pdfTóth István Zoltán
07/02/2023, 6:37 AMRobert Munro
07/02/2023, 7:10 AMTóth István Zoltán
07/02/2023, 7:47 AMRobert Munro
07/02/2023, 7:49 AM(x * 1000).toInt()/1000.0