eygraber
11/29/2022, 12:58 AMuntil
function for Float
in common code?ephemient
11/29/2022, 1:27 AMClosedFloatingPointRange
, which cannot support a half-open rangeephemient
11/29/2022, 1:52 AMOpenEndRange
, with support for floatsephemient
11/29/2022, 2:02 AMinfix fun Float.until(to: Float): ClosedFloatingPointRange<Float> = this .. when {
to < 0f -> Float.fromBits(to.toBits() + 1)
to > 0f -> Float.fromBits(to.toBits() - 1)
to == 0f -> -Float.MIN_VALUE
else -> to
}
in current/earlier Kotlin versions to produce the nearest closed range that contains everything the open range wouldephemient
11/29/2022, 2:09 AM0 until 3
into 0..2
on integers currently, except that we have to do a bit of bit manipulation to get the immediately prior floating point value)Michael Paus
11/29/2022, 11:37 AMulp
function here but I guess the bit fiddling may be even more efficient.ephemient
11/29/2022, 4:42 PMulp
is the delta to the successor, not the prior, which is not necessarily the sameephemient
11/29/2022, 4:45 PMval x = 1f
val y = x - x.ulp
val z = Float.fromBits(1f.toBits() - 1)
y < z && z < x
so you can't actually use it to decrement the range end