What is a good way to define a range of doubles that isn't inclusive of the last value.
So I could for example define a range "a" zero up to 2.0, then have a range "b" from 2.0 to 4.0, then 2.0 would be part of b but not a.
Basically how the until function worms for other Number types
Kweku
04/14/2021, 2:45 PM
My current idea is to have an extension function where I subtract the smallest possible value which is Double.MIN_VALUE multiplied to the power of 309 (lower values don't seem to affect the number)
d
diesieben07
04/14/2021, 2:51 PM
Probably best to make your own `ClosedOpenRange`:
Copy code
public data class ClosedOpenRange<T : Comparable<T>>(val start: T, val endExclusive: T) {
public operator fun contains(value: T): Boolean {
return value >= start && value < endExclusive
}
}
m
mkrussel
04/14/2021, 2:53 PM
@Kweku There is
Double.nextDown()
for that.
k
Kweku
04/14/2021, 3:00 PM
@mkrussel thank you, dunno how I missed that 🤦🏿♂️, gives the same value as my idea and much simple