Files
kotlin-fork/compiler/testData/ir/irText/expressions/floatingPointComparisons/whenByFloatingPoint.kt.txt
T
Dmitriy Novozhilov b454fcc1e0 [FIR] Save IR dumps to .ir.txt files instead of .txt in tests
This is needed to avoid clashes between different dumps from different
  handlers
2021-10-12 17:26:36 +03:00

80 lines
1.6 KiB
Plaintext
Vendored

fun testSimple(x: Double): Int {
return { // BLOCK
val tmp0_subject: Double = x
when {
ieee754equals(arg0 = tmp0_subject, arg1 = 0.0) -> 0
else -> 1
}
}
}
fun testSmartCastInWhenSubject(x: Any): Int {
when {
x !is Double -> return -1
}
return { // BLOCK
val tmp0_subject: Any = x
when {
ieee754equals(arg0 = tmp0_subject /*as Double */, arg1 = 0.0) -> 0
else -> 1
}
}
}
fun testSmartCastInWhenCondition(x: Double, y: Any): Int {
when {
y !is Double -> return -1
}
return { // BLOCK
val tmp0_subject: Double = x
when {
ieee754equals(arg0 = tmp0_subject, arg1 = y /*as Double */) -> 0
else -> 1
}
}
}
fun testSmartCastInWhenConditionInBranch(x: Any): Int {
return { // BLOCK
val tmp0_subject: Any = x
when {
tmp0_subject is Double.not() -> -1
ieee754equals(arg0 = tmp0_subject /*as Double */, arg1 = 0.0) -> 0
else -> 1
}
}
}
fun testSmartCastToDifferentTypes(x: Any, y: Any): Int {
when {
x !is Double -> return -1
}
when {
y !is Float -> return -1
}
return { // BLOCK
val tmp0_subject: Any = x
when {
ieee754equals(arg0 = tmp0_subject /*as Double */, arg1 = y /*as Float */.toDouble()) -> 0
else -> 1
}
}
}
fun foo(x: Double): Double {
return x
}
fun testWithPrematureExitInConditionSubexpression(x: Any): Int {
return { // BLOCK
val tmp0_subject: Any = x
when {
EQEQ(arg0 = tmp0_subject, arg1 = foo(x = when {
x !is Double -> return 42
else -> x /*as Double */
})) -> 0
else -> 1
}
}
}