ProperNumberComparisons is disabled by default (until LDC decision)

This commit is contained in:
Dmitry Petrov
2018-02-09 16:21:46 +03:00
parent af79bbd247
commit 839ebba157
17 changed files with 305 additions and 65 deletions
+1
View File
@@ -28,6 +28,7 @@ where advanced options include:
-Xno-optimize Disable optimizations
-Xno-param-assertions Don't generate not-null assertions on parameters of methods accessible from Java
-Xno-receiver-assertions Don't generate not-null assertion for extension receiver arguments of platform types
-Xproper-ieee754-comparisons Generate proper IEEE 754 comparisons in all cases if values are statically known to be of primitive numeric types
-Xreport-perf Report detailed performance statistics
-Xscript-resolver-environment=<key=value[,]>
Script resolver environment in key-value pairs (the value could be quoted and escaped)
@@ -0,0 +1,13 @@
// IGNORE_BACKEND: JS
val minus: Any = -0.0
fun box(): String {
if (minus is Double) {
if ((minus as Comparable<Double>) >= 0.0) return "fail 0"
if ((minus as Comparable<Double>) == 0.0) return "fail 1"
if (minus == (0.0 as Comparable<Double>)) return "fail 2"
if (minus == (0.0F as Comparable<Float>)) return "fail 3"
}
return "OK"
}
@@ -0,0 +1,14 @@
// !LANGUAGE: +ProperIeee754Comparisons
// IGNORE_BACKEND: JS
val minus: Any = -0.0
fun box(): String {
if (minus is Double) {
if ((minus as Comparable<Double>) >= 0.0) return "fail 0"
if ((minus as Comparable<Double>) == 0.0) return "fail 1"
if (minus == (0.0 as Comparable<Double>)) return "fail 2"
if (minus == (0.0F as Comparable<Float>)) return "fail 3"
}
return "OK"
}
@@ -1,4 +1,4 @@
// LANGUAGE_VERSION: 1.3
// !LANGUAGE: +ProperIeee754Comparisons
fun less(x: Comparable<Float>, y: Float) = x is Float && x < y
fun less(x: Comparable<Double>, y: Double) = x is Double && x < y
@@ -1,4 +1,4 @@
// LANGUAGE_VERSION: 1.3
// !LANGUAGE: +ProperIeee754Comparisons
fun testF(x: Any) =
when (x) {
@@ -15,10 +15,10 @@ fun testD(x: Any) =
}
fun box(): String {
val tf = testF(0.0F)
val tf = testF(-0.0F)
if (tf != "0.0") return "Fail 1: $tf"
val td = testD(0.0)
val td = testD(-0.0)
if (td != "0.0") return "Fail 2: $td"
return "OK"
@@ -0,0 +1,75 @@
// IGNORE_BACKEND: JS
fun eqDI(x: Any?, y: Any?) = x is Double? && y is Int? && x == y
fun eqDL(x: Any?, y: Any?) = x is Double? && y is Long? && x == y
fun eqID(x: Any?, y: Any?) = x is Int? && y is Double? && x == y
fun eqLD(x: Any?, y: Any?) = x is Long? && y is Double? && x == y
fun eqFI(x: Any?, y: Any?) = x is Float? && y is Int? && x == y
fun eqFL(x: Any?, y: Any?) = x is Float? && y is Long? && x == y
fun eqIF(x: Any?, y: Any?) = x is Int? && y is Float? && x == y
fun eqLF(x: Any?, y: Any?) = x is Long? && y is Float? && x == y
fun testNullNull() {
if (!eqDI(null, null)) throw Exception()
if (!eqDL(null, null)) throw Exception()
if (!eqID(null, null)) throw Exception()
if (!eqLD(null, null)) throw Exception()
if (!eqFI(null, null)) throw Exception()
if (!eqFL(null, null)) throw Exception()
if (!eqIF(null, null)) throw Exception()
if (!eqLF(null, null)) throw Exception()
}
fun testNull0() {
if (eqDI(null, 0)) throw Exception()
if (eqDL(null, 0L)) throw Exception()
if (eqID(null, 0.0)) throw Exception()
if (eqLD(null, 0.0)) throw Exception()
if (eqFI(null, 0)) throw Exception()
if (eqFL(null, 0L)) throw Exception()
if (eqIF(null, 0.0F)) throw Exception()
if (eqLF(null, 0.0F)) throw Exception()
}
fun test0Null() {
if (eqDI(0.0, null)) throw Exception()
if (eqDL(0.0, null)) throw Exception()
if (eqID(0, null)) throw Exception()
if (eqLD(0L, null)) throw Exception()
if (eqFI(0.0F, null)) throw Exception()
if (eqFL(0.0F, null)) throw Exception()
if (eqIF(0, null)) throw Exception()
if (eqLF(0L, null)) throw Exception()
}
fun testPlusMinus0() {
if (eqDI(-0.0, 0)) throw Exception()
if (eqDL(-0.0, 0L)) throw Exception()
if (eqID(0, -0.0)) throw Exception()
if (eqLD(0L, -0.0)) throw Exception()
if (eqFI(-0.0F, 0)) throw Exception()
if (eqFL(-0.0F, 0L)) throw Exception()
if (eqIF(0, -0.0F)) throw Exception()
if (eqLF(0L, -0.0F)) throw Exception()
}
fun test01() {
if (eqDI(0.0, 1)) throw Exception()
if (eqDL(0.0, 1L)) throw Exception()
if (eqID(0, 1.0)) throw Exception()
if (eqLD(0L, 1.0)) throw Exception()
if (eqFI(0.0F, 1)) throw Exception()
if (eqFL(0.0F, 1L)) throw Exception()
if (eqIF(0, 1.0F)) throw Exception()
if (eqLF(0L, 1.0F)) throw Exception()
}
fun box(): String {
testNullNull()
testNull0()
test0Null()
testPlusMinus0()
test01()
return "OK"
}
@@ -1,4 +1,4 @@
// LANGUAGE_VERSION: 1.3
// !LANGUAGE: +ProperIeee754Comparisons
// IGNORE_BACKEND: JS
fun eqDI(x: Any?, y: Any?) = x is Double? && y is Int? && x == y
@@ -1,4 +1,4 @@
// LANGUAGE_VERSION: 1.3
// !LANGUAGE: +ProperIeee754Comparisons
fun ne(x: Any, y: Any) = x is Double && y is Float && x != y
fun lt(x: Any, y: Any) = x is Double && y is Float && x < y
@@ -0,0 +1,13 @@
// !LANGUAGE: +ProperIeee754Comparisons
val minus: Any = -0.0
fun box(): String {
if (minus is Comparable<*> && minus is Double) {
if (minus < 0.0) return "fail 0"
if ((minus) != 0.0) return "fail 1"
if (minus != 0.0) return "fail 2"
if (minus != 0.0F) return "fail 3"
}
return "OK"
}