IntervalSets.jl icon indicating copy to clipboard operation
IntervalSets.jl copied to clipboard

Conversion to complex should throw an error

Open dlfivefifty opened this issue 5 years ago • 1 comments

The following behaviour is problematic:

julia> d = convert(AbstractInterval{ComplexF64}, 0..1)
0.0 + 0.0im..1.0 + 0.0im

julia> 0.5 in d
ERROR: MethodError: no method matching isless(::Complex{Float64}, ::Float64)
Closest candidates are:
  isless(::Float64, ::Float64) at float.jl:459
  isless(::Missing, ::Any) at missing.jl:66
  isless(::AbstractFloat, ::AbstractFloat) at operators.jl:148
  ...
Stacktrace:
 [1] <(::Complex{Float64}, ::Float64) at ./operators.jl:260
 [2] <=(::Complex{Float64}, ::Float64) at ./operators.jl:309
 [3] in(::Float64, ::Interval{:closed,:closed,Complex{Float64}}) at /Users/sheehanolver/.julia/packages/IntervalSets/xr34V/src/IntervalSets.jl:126
 [4] top-level scope at none:0

dlfivefifty avatar Oct 31 '18 16:10 dlfivefifty

Should we drop the following constructor, not just the conversion?

julia> d = (1)..(1+im)
1 + 0im..1 + 1im

julia> 1 in d
ERROR: MethodError: no method matching isless(::Complex{Int64}, ::Int64)
Closest candidates are:
  isless(::AbstractFloat, ::Real) at ~/julia/julia-1.7.2/share/julia/base/operators.jl:186
  isless(::Real, ::Real) at ~/julia/julia-1.7.2/share/julia/base/operators.jl:430
  isless(::Any, ::Missing) at ~/julia/julia-1.7.2/share/julia/base/missing.jl:88
  ...
Stacktrace:
 [1] <(x::Complex{Int64}, y::Int64)
   @ Base ./operators.jl:352
 [2] <=(x::Complex{Int64}, y::Int64)
   @ Base ./operators.jl:401
 [3] in(v::Int64, I::ClosedInterval{Complex{Int64}})
   @ IntervalSets ~/.julia/dev/IntervalSets/src/IntervalSets.jl:120
 [4] top-level scope
   @ REPL[4]:1

hyrodium avatar Apr 03 '22 06:04 hyrodium