Generate intrinsic-based numeric comparison only for FP types
This commit is contained in:
+15
@@ -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"
|
||||
}
|
||||
+22
@@ -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"
|
||||
}
|
||||
+11
@@ -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)
|
||||
Reference in New Issue
Block a user