mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 08:31:26 +00:00
It's safe to upcast integer types to Long,
floating-point types to Double.
So we don't have to create a range instance for cases such as
fun testLongInInt(x: Long, a: Int, b: Int) =
x in a .. b
which is equivalent to
fun testLongInInt(x: Long, a: Int, b: Int) =
x in a.toLong() .. b.toLong()
28 lines
406 B
Kotlin
Vendored
28 lines
406 B
Kotlin
Vendored
// WITH_RUNTIME
|
|
|
|
fun inInt(x: Long): Boolean {
|
|
return x in 1..2
|
|
}
|
|
|
|
fun inLong(x: Int): Boolean {
|
|
return x in 1L..2L
|
|
}
|
|
|
|
fun inFloat(x: Double): Boolean {
|
|
return x in 1.0f..2.0f
|
|
}
|
|
|
|
fun inDouble(x: Float): Boolean {
|
|
return x in 1.0..2.0
|
|
}
|
|
|
|
// 3 I2L
|
|
// 3 F2D
|
|
// 0 INVOKESPECIAL
|
|
// 0 NEW
|
|
// 0 rangeTo
|
|
// 0 longRangeContains
|
|
// 0 intRangeContains
|
|
// 0 doubleRangeContains
|
|
// 0 floatRangeContains
|