-
Notifications
You must be signed in to change notification settings - Fork 35
Closed
Labels
Description
We already have constructor and convert method from Complex to Quaternion.
julia> Quaternion(Complex(1,2))
Quaternion{Int64}(1, 2, 0, 0, false)
julia> convert(Quaternion, Complex(1,2))
Quaternion{Int64}(1, 2, 0, 0, false)However, we still missing the following methods + and *.
julia> Quaternion(1,2,3,4) + Complex(1,2)
ERROR: MethodError: no method matching imag(::Complex{Int64})
You may have intended to import Base.imag
Closest candidates are:
imag(::Quaternion) at ~/.julia/dev/Quaternions/src/Quaternion.jl:44
imag(::Octonion) at ~/.julia/dev/Quaternions/src/Octonion.jl:48
Stacktrace:
[1] convert(#unused#::Type{Quaternion{Int64}}, z::Complex{Int64})
@ Quaternions ~/.julia/dev/Quaternions/src/Quaternion.jl:21
[2] _promote
@ ./promotion.jl:327 [inlined]
[3] promote
@ ./promotion.jl:350 [inlined]
[4] +(x::Quaternion{Int64}, y::Complex{Int64})
@ Base ./promotion.jl:379
[5] top-level scope
@ REPL[23]:1
julia> Quaternion(1,2,3,4) * Complex(1,2)
ERROR: MethodError: no method matching imag(::Complex{Int64})
You may have intended to import Base.imag
Closest candidates are:
imag(::Quaternion) at ~/.julia/dev/Quaternions/src/Quaternion.jl:44
imag(::Octonion) at ~/.julia/dev/Quaternions/src/Octonion.jl:48
Stacktrace:
[1] convert(#unused#::Type{Quaternion{Int64}}, z::Complex{Int64})
@ Quaternions ~/.julia/dev/Quaternions/src/Quaternion.jl:21
[2] _promote
@ ./promotion.jl:327 [inlined]
[3] promote
@ ./promotion.jl:350 [inlined]
[4] *(x::Quaternion{Int64}, y::Complex{Int64})
@ Base ./promotion.jl:380
[5] top-level scope
@ REPL[24]:1I think we have the following choices to solve this problem.
- Remove the constructor and
convertmethod- There is no natural embedding ℂ ⊆ ℍ because it depends on the choice of the basis.
- This will make a breaking change.
- Add type promotions
- This will not make a breaking change.
I don't know the practical benefit of converting from Complex to Quaternion, so I prefer the first.
Related comment: #29 (comment)