What is a good way to define a range of doubles th...

# announcementsk

Kweku

04/14/2021, 2:43 PMWhat 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 PMMy 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 PMProbably 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`Double.nextDown()`

for that.k

Kweku

04/14/2021, 3:00 PM5 Views