Generate intrinsic-based numeric comparison only for FP types

This commit is contained in:
Dmitry Petrov
2018-08-01 17:43:42 +03:00
parent cce9505e31
commit 1bfb75a51b
11 changed files with 156 additions and 33 deletions
@@ -0,0 +1,15 @@
// !LANGUAGE: +ProperIeee754Comparisons
fun eq1(a: Int?, b: Int) = a == b
fun eq2(a: Int, b: Int?) = a == b
fun eq3(a: Int?, b: Int?) = a == b
fun box(): String =
when {
!eq1(1, 1) -> "Fail 1"
!eq2(1, 1) -> "Fail 2"
!eq3(1, 1) -> "Fail 3"
else -> "OK"
}
@@ -0,0 +1,22 @@
// !LANGUAGE: +ProperIeee754Comparisons
fun eq1(a: Any?, b: Any?) =
a is Int? && b is Int && a == b
fun eq2(a: Any?, b: Any?) =
a is Int && b is Int? && a == b
fun eq3(a: Any?, b: Any?) =
a is Int && b is Int && a == b
fun eq4(a: Any?, b: Any?) =
a is Int? && b is Int? && a == b
fun box(): String =
when {
!eq1(1, 1) -> "Fail 1"
!eq2(1, 1) -> "Fail 2"
!eq3(1, 1) -> "Fail 3"
!eq4(1, 1) -> "Fail 4"
else -> "OK"
}
@@ -0,0 +1,11 @@
// !LANGUAGE: +ProperIeee754Comparisons
fun test(x: Any?): String {
if (x !is Int) return "Fail 1"
when (x) {
0 -> return "OK"
else -> return "Fail 2"
}
}
fun box(): String = test(0)