What is a good way to define a range of doubles th...
# announcements
k
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
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
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
@Kweku There is
Double.nextDown()
for that.
k
@mkrussel thank you, dunno how I missed that 🤦🏿‍♂️, gives the same value as my idea and much simple