On Friday, August 28, 2015 at 10:28:39 AM UTC, Andreas Lobinger wrote: > > >> that is the right thing. I wander what MATLAB does, since all numbers(?) >> are stored as complex. 0im special cased? >> > > yes. Only real part is compared, if you need abs(a) > abs(b) or similar. >
I wander, since MATLAB compares/orders complex numbers, if Julia should too. http://www.cut-the-knot.org/do_you_know/complex_compare.shtml "It's actually possible to define the relationship "<" between complex numbers. [..] Still it's not very useful. To see what the problem is let's turn to the multiplication." It seems for sorting/datagrids, etc. (DataFrames.jl) you might want this. Does it lead to something very bad? Would if be helpful to special-case then only sort! and not isless in general? julia> a=[1.0+0im, 4, 3] 3-element Array{Complex{Float64},1}: 1.0+0.0im 4.0+0.0im 3.0+0.0im julia> sort!(a) ERROR: `isless` has no method matching isless(::Complex{Float64}, ::Complex{Float64}) in sort! at sort.jl:246 in sort! at sort.jl:260 in sort! at sort.jl:337 "Fixed" by: Base.isless(x::Complex, y::Complex) = x.re < y.re ? true : (x.re == y.re && x.im < y.im) # "Lexographical" order Maybe even just: Base.isless(x::Complex, y::Complex) = x.re < y.re ? true # is that for sure what MATLAB does? If this is not helpful in general, then maybe for MatlabCompat.jl, that exists.. Or a function in Base, enable_complex_sort() to add this, and adding a pointer to it in error-messages for sort and/or isless? Would there another "ordering" of complex number make sense? By magnitude..? I see also that https://github.com/forio/Quaternions.jl doesn't define isless.. maybe even less helpful there.. -- Palli.
