Fix nullable number comparisons in JS

This commit is contained in:
Dmitry Petrov
2020-01-14 16:09:30 +03:00
parent f8341ad7eb
commit 933ac3a16b
15 changed files with 168 additions and 18 deletions
@@ -0,0 +1,42 @@
// !LANGUAGE: +ProperIeee754Comparisons
// IGNORE_BACKEND: JS
// ^ if (eq_double_any(0.0, 0)) throw AssertionError("eq_double_any(0.0, 0)")
fun eq_double_doubleN(a: Double, b: Double?) = a == b
fun eq_double_any(a: Double, b: Any) = a == b
fun eq_double_anyN(a: Double, b: Any?) = a == b
fun eq_doubleN_double(a: Double?, b: Double) = a == b
fun eq_doubleN_doubleN(a: Double?, b: Double?) = a == b
fun eq_doubleN_any(a: Double?, b: Any) = a == b
fun eq_doubleN_anyN(a: Double?, b: Any?) = a == b
fun box(): String {
if (!eq_double_doubleN(0.0, -0.0)) throw AssertionError("!eq_double_doubleN(0.0, -0.0)")
if (eq_double_doubleN(0.0, null)) throw AssertionError("eq_double_doubleN(0.0, null)")
if (!eq_double_any(0.0, 0.0)) throw AssertionError("!eq_double_any(0.0, 0.0)")
if (eq_double_any(0.0, -0.0)) throw AssertionError("eq_double_any(0.0, -0.0)")
if (eq_double_any(0.0, 0)) throw AssertionError("eq_double_any(0.0, 0)")
if (!eq_double_anyN(0.0, 0.0)) throw AssertionError("!eq_double_anyN(0.0, 0.0)")
if (eq_double_anyN(0.0, -0.0)) throw AssertionError("eq_double_anyN(0.0, -0.0)")
if (eq_double_anyN(0.0, 0)) throw AssertionError("eq_double_anyN(0.0, 0)")
if (eq_double_anyN(0.0, null)) throw AssertionError("eq_double_anyN(0.0, null)")
if (eq_doubleN_double(null, 0.0)) throw AssertionError("eq_doubleN_double(null, 0.0)")
if (!eq_doubleN_doubleN(0.0, -0.0)) throw AssertionError("!eq_doubleN_doubleN(0.0, -0.0)")
if (eq_doubleN_doubleN(0.0, null)) throw AssertionError("eq_doubleN_doubleN(0.0, null)")
if (!eq_doubleN_any(0.0, 0.0)) throw AssertionError("!eq_doubleN_any(0.0, 0.0)")
if (eq_doubleN_any(0.0, -0.0)) throw AssertionError("eq_doubleN_any(0.0, -0.0)")
if (eq_doubleN_any(0.0, 0)) throw AssertionError("eq_doubleN_any(0.0, 0)")
if (!eq_doubleN_anyN(0.0, 0.0)) throw AssertionError("!eq_doubleN_anyN(0.0, 0.0)")
if (eq_doubleN_anyN(0.0, -0.0)) throw AssertionError("eq_doubleN_anyN(0.0, -0.0)")
if (eq_doubleN_anyN(0.0, 0)) throw AssertionError("eq_doubleN_anyN(0.0, 0)")
if (eq_doubleN_anyN(0.0, null)) throw AssertionError("eq_doubleN_anyN(0.0, null)")
return "OK"
}