marstran
03/05/2019, 7:48 PMprintln(-0.0 == 0.0) // true
println("${-0.0 == 0.0}") // false
println(-0.0 < 0.0) // false
println("${-0.0 < 0.0}") // true
serebit
03/05/2019, 7:49 PMprintln(buildString {
append(-0.0 < +0.0)
})
produces false
val n = -0.0
val p = +0.0
println(“${n < p}”)
false
Czar
03/05/2019, 8:02 PMprintln(-0.0 == 0.0) // true
println("${-0.0 == 0.0}") // false
gets translated by kotlin compiler into
boolean var0 = -0.0D == 0.0D;
System.out.println(var0);
String var1 = "false";
System.out.println(var1);
So the problem (if it is a problem) lies in the code of kotlin compiler responsible for String interpolation. Its equality algorithm is probably different from what JVM uses.serebit
03/05/2019, 8:04 PMcbruegg
03/05/2019, 8:05 PMmarstran
03/05/2019, 8:11 PMCzar
03/05/2019, 8:11 PMserebit
03/05/2019, 8:11 PMCzar
03/05/2019, 8:12 PM0.0 == -0.0
, and that gets evaluatedserebit
03/05/2019, 8:13 PMinline fun foo() = -0.0 < 0.0
fun main() {
println(“${foo()}”)
}
prints falsemarstran
03/05/2019, 8:15 PMserebit
03/05/2019, 8:16 PMfoo
into the string interpolation would be the same as print(“${-0.0 < 0.0}”)
Nikky
03/05/2019, 9:27 PMpublic static final void main() {
int $i$f$foo = false;
String var1 = String.valueOf(-0.0D < 0.0D);
System.out.println(var1);
}
that explains it i think