Make comparison with NaN consistent with javac

This commit is contained in:
Alexander Udalov
2014-01-22 21:20:09 +04:00
parent db9d0e381b
commit 09e772ff61
3 changed files with 64 additions and 2 deletions
@@ -502,10 +502,10 @@ public abstract class StackValue {
}
if (operandType == Type.FLOAT_TYPE || operandType == Type.DOUBLE_TYPE) {
if (opToken == JetTokens.GT || opToken == JetTokens.GTEQ) {
v.cmpg(operandType);
v.cmpl(operandType);
}
else {
v.cmpl(operandType);
v.cmpg(operandType);
}
}
else if (operandType == Type.LONG_TYPE) {
@@ -0,0 +1,57 @@
// This test checks that our bytecode is consistent with javac bytecode
fun assert(condition: Boolean): Unit =
if (!condition) throw AssertionError("Fail")
fun assertFalse(condition: Boolean) = assert(!condition)
fun box(): String {
var dnan = java.lang.Double.NaN
if (System.nanoTime() < 0) dnan = 3.14 // To avoid possible compile-time const propagation
assertFalse(0.0 < dnan)
assertFalse(0.0 > dnan)
assertFalse(0.0 <= dnan)
assertFalse(0.0 >= dnan)
assertFalse(0.0 == dnan)
assertFalse(dnan < 0.0)
assertFalse(dnan > 0.0)
assertFalse(dnan <= 0.0)
assertFalse(dnan >= 0.0)
assertFalse(dnan == 0.0)
assertFalse(dnan < dnan)
assertFalse(dnan > dnan)
assertFalse(dnan <= dnan)
assertFalse(dnan >= dnan)
assertFalse(dnan == dnan)
// Double.compareTo: "NaN is considered by this method to be equal to itself and greater than all other values"
assert(0.0.compareTo(dnan) == -1)
assert(dnan.compareTo(0.0) == 1)
assert(dnan.compareTo(dnan) == 0)
var fnan = java.lang.Float.NaN
if (System.nanoTime() < 0) fnan = 3.14f
assertFalse(0.0f < fnan)
assertFalse(0.0f > fnan)
assertFalse(0.0f <= fnan)
assertFalse(0.0f >= fnan)
assertFalse(0.0f == fnan)
assertFalse(fnan < 0.0f)
assertFalse(fnan > 0.0f)
assertFalse(fnan <= 0.0f)
assertFalse(fnan >= 0.0f)
assertFalse(fnan == 0.0f)
assertFalse(fnan < fnan)
assertFalse(fnan > fnan)
assertFalse(fnan <= fnan)
assertFalse(fnan >= fnan)
assertFalse(fnan == fnan)
assert(0.0.compareTo(fnan) == -1)
assert(fnan.compareTo(0.0) == 1)
assert(fnan.compareTo(fnan) == 0)
return "OK"
}
@@ -4142,6 +4142,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/box/primitiveTypes"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("comparisonWithNaN.kt")
public void testComparisonWithNaN() throws Exception {
doTest("compiler/testData/codegen/box/primitiveTypes/comparisonWithNaN.kt");
}
@TestMetadata("comparisonWithNullCallsFun.kt")
public void testComparisonWithNullCallsFun() throws Exception {
doTest("compiler/testData/codegen/box/primitiveTypes/comparisonWithNullCallsFun.kt");