I’m new to Julia, and was trying to find a way to define a half-open interval like (-Inf, 5.0]
, then test if a floating point number is contained therein.
In Swift I could do
let leftOpenInterval = ...5.0
print(leftOpenInterval.contains(-Double.infinity)) // true
print(leftOpenInterval.contains(3)) // true
print(leftOpenInterval.contains(6)) // false
print(leftOpenInterval.contains(Double.infinity)) // false
let rightOpenInterval = 5.0...
print(rightOpenInterval.contains(-Double.infinity)) // false
print(rightOpenInterval.contains(3)) // false
print(rightOpenInterval.contains(6)) // true
print(rightOpenInterval.contains(Double.infinity)) // true
How could I achieve the equivalent result in Julia? I tried doing -Inf:5.0
and 5.0:Inf
but these give me errors. Any advice on how to proceed here?