JS: fix double compareTo behaviour for NaN and +-0 (KT-22723)

This commit is contained in:
Anton Bannykh
2017-12-27 21:18:05 +03:00
parent 12c01ef80a
commit ed80252ba8
49 changed files with 260 additions and 307 deletions
@@ -1,4 +1,4 @@
// IGNORE_BACKEND: JS, NATIVE
// IGNORE_BACKEND: NATIVE
inline fun ltx(a: Comparable<Any>, b: Any) = a < b
inline fun lex(a: Comparable<Any>, b: Any) = a <= b
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS
// IGNORE_BACKEND: NATIVE
fun equals1(a: Double, b: Double) = a.equals(b)
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JS
val minus: Any = -0.0
fun box(): String {
@@ -1,5 +1,4 @@
// !LANGUAGE: +ProperIeee754Comparisons
// IGNORE_BACKEND: JS
val minus: Any = -0.0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS
fun box(): String {
if ((-0.0 as Comparable<Double>) >= 0.0) return "fail 0"
if ((-0.0F as Comparable<Float>) >= 0.0F) return "fail 1"
@@ -0,0 +1,62 @@
fun box(): String {
if (0.toByte().compareTo(-0.0) != 1) return "fail 1.1"
if (0.toByte().compareTo(-0.0F) != 1) return "fail 1.2"
if (0.toByte().compareTo(Double.NaN) != -1) return "fail 1.3"
if (0.toByte().compareTo(Float.NaN) != -1) return "fail 1.4"
if (0.toShort().compareTo(-0.0) != 1) return "fail 2.1"
if (0.toShort().compareTo(-0.0F) != 1) return "fail 2.2"
if (0.toShort().compareTo(Double.NaN) != -1) return "fail 2.3"
if (0.toShort().compareTo(Float.NaN) != -1) return "fail 2.4"
if (0.compareTo(-0.0) != 1) return "fail 3.1"
if (0.compareTo(-0.0F) != 1) return "fail 3.2"
if (0.compareTo(Double.NaN) != -1) return "fail 3.3"
if (0.compareTo(Float.NaN) != -1) return "fail 3.4"
if (0.0F.compareTo(-0.0) != 1) return "fail 4.1"
if (0.0F.compareTo(-0.0F) != 1) return "fail 4.2"
if (0.0F.compareTo(Double.NaN) != -1) return "fail 4.3"
if (0.0F.compareTo(Float.NaN) != -1) return "fail 4.4"
if (0.0.compareTo(-0.0) != 1) return "fail 5.1"
if (0.0.compareTo(-0.0F) != 1) return "fail 5.2"
if (0.0.compareTo(Double.NaN) != -1) return "fail 5.3"
if (0.0.compareTo(Float.NaN) != -1) return "fail 5.4"
if (0L.compareTo(-0.0) != 1) return "fail 6.1"
if (0L.compareTo(-0.0F) != 1) return "fail 6.2"
if (0L.compareTo(Double.NaN) != -1) return "fail 6.3"
if (0L.compareTo(Float.NaN) != -1) return "fail 6.4"
if ((-0.0).compareTo(0.toByte()) != -1) return "fail 7.1"
if ((-0.0).compareTo(0.toShort()) != -1) return "fail 7.2"
if ((-0.0).compareTo(0) != -1) return "fail 7.3"
if ((-0.0).compareTo(0.0F) != -1) return "fail 7.4"
if ((-0.0).compareTo(0.0) != -1) return "fail 7.5"
if ((-0.0).compareTo(0L) != -1) return "fail 7.6"
if ((-0.0F).compareTo(0.toByte()) != -1) return "fail 8.1"
if ((-0.0F).compareTo(0.toShort()) != -1) return "fail 8.2"
if ((-0.0F).compareTo(0) != -1) return "fail 8.3"
if ((-0.0F).compareTo(0.0F) != -1) return "fail 8.4"
if ((-0.0F).compareTo(0.0) != -1) return "fail 8.5"
if ((-0.0F).compareTo(0L) != -1) return "fail 8.6"
if (Double.NaN.compareTo(0.toByte()) != 1) return "fail 9.1"
if (Double.NaN.compareTo(0.toShort()) != 1) return "fail 9.2"
if (Double.NaN.compareTo(0) != 1) return "fail 9.3"
if (Double.NaN.compareTo(0.0F) != 1) return "fail 9.4"
if (Double.NaN.compareTo(0.0) != 1) return "fail 9.5"
if (Double.NaN.compareTo(0L) != 1) return "fail 9.6"
if (Float.NaN.compareTo(0.toByte()) != 1) return "fail 10.1"
if (Float.NaN.compareTo(0.toShort()) != 1) return "fail 10.2"
if (Float.NaN.compareTo(0) != 1) return "fail 10.3"
if (Float.NaN.compareTo(0.0F) != 1) return "fail 10.4"
if (Float.NaN.compareTo(0.0) != 1) return "fail 10.5"
if (Float.NaN.compareTo(0L) != 1) return "fail 10.6"
return "OK"
}
-1
View File
@@ -1,5 +1,4 @@
// !LANGUAGE: -ProperIeee754Comparisons
// IGNORE_BACKEND: JS
fun equals1(a: Double, b: Double) = a == b
-1
View File
@@ -1,5 +1,4 @@
// !LANGUAGE: -ProperIeee754Comparisons
// IGNORE_BACKEND: JS
fun equals1(a: Float, b: Float) = a == b
-1
View File
@@ -1,6 +1,5 @@
// !LANGUAGE: -ProperIeee754Comparisons
// WITH_RUNTIME
// IGNORE_BACKEND: JS
import kotlin.test.*
@@ -1,5 +1,4 @@
// !LANGUAGE: -ProperIeee754Comparisons
// IGNORE_BACKEND: JS
fun equals1(a: Double, b: Double?) = a == b
@@ -1,5 +1,4 @@
// !LANGUAGE: -ProperIeee754Comparisons
// IGNORE_BACKEND: JS
fun equals1(a: Float, b: Float?) = a == b
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS
fun less1(a: Double, b: Double) = a.compareTo(b) == -1
fun less2(a: Double?, b: Double?) = a!!.compareTo(b!!) == -1
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JS
fun equals1(a: Double, b: Double) = a.equals(b)
fun equals2(a: Double?, b: Double?) = a!!.equals(b!!)
@@ -1,5 +1,4 @@
// !LANGUAGE: -ProperIeee754Comparisons
// IGNORE_BACKEND: JS
fun greater1(a: Double, b: Double) = a > b
-1
View File
@@ -1,5 +1,4 @@
// !LANGUAGE: -ProperIeee754Comparisons
// IGNORE_BACKEND: JS
fun greater1(a: Float, b: Float) = a > b
-2
View File
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JS
inline fun less(a: Comparable<Double>, b: Double): Boolean {
return a < b
}
-1
View File
@@ -1,5 +1,4 @@
// !LANGUAGE: -ProperIeee754Comparisons
// IGNORE_BACKEND: JS
fun less1(a: Double, b: Double) = a < b
-1
View File
@@ -1,5 +1,4 @@
// !LANGUAGE: -ProperIeee754Comparisons
// IGNORE_BACKEND: JS
fun less1(a: Float, b: Float) = a < b
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS
fun box(): String {
val plusZero: Double? = 0.0
val minusZero: Double = -0.0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS
fun box(): String {
val zero: Any = 0.0
val floatZero: Any = -0.0F
@@ -1,5 +1,3 @@
// 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
@@ -1,5 +1,4 @@
// !LANGUAGE: +ProperIeee754Comparisons
// 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
-1
View File
@@ -1,5 +1,4 @@
// !LANGUAGE: -ProperIeee754Comparisons
// IGNORE_BACKEND: JS
fun box(): String {
val plusZero: Any = 0.0
-1
View File
@@ -1,5 +1,4 @@
// LANGUAGE_VERSION: 1.0
// IGNORE_BACKEND: JS
fun box(): String {
val plusZero: Any = 0.0
@@ -1,5 +1,4 @@
// !LANGUAGE: -ProperIeee754Comparisons
// IGNORE_BACKEND: JS
fun box(): String {
val plusZero: Any = 0.0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS
// WITH_RUNTIME
val DOUBLE_RANGE = 0.0 .. -0.0