Luigi Scarminio
10/09/2019, 11:25 AMspand
10/09/2019, 11:51 AMfun main(args: Array<String>) {
println(1.5 in (1.0..2.0))
}
Stephan Schroeder
10/09/2019, 12:27 PMcoerceIn
might be interesting to you as well. e.g.
val d: Double = getSomeDouble().coerceIn(0.0, 10.0)
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/coerce-in.htmlLuigi Scarminio
10/10/2019, 5:23 PMspand
10/11/2019, 6:32 AMin
I get:
@SinceKotlin("1.1")
public interface ClosedFloatingPointRange<T : Comparable<T>> : ClosedRange<T> {
override fun contains(value: T): Boolean = lessThanOrEquals(start, value) && lessThanOrEquals(value, endInclusive)
override fun isEmpty(): Boolean = !lessThanOrEquals(start, endInclusive)
/**
* Compares two values of range domain type and returns true if first is less than or equal to second.
*/
fun lessThanOrEquals(a: T, b: T): Boolean
}
spand
10/11/2019, 6:32 AMLuigi Scarminio
10/14/2019, 7:20 PM