diff --git a/examples/quaternion.jl b/examples/quaternion.jl index 536e047c615e8..f2efb4336afa2 100644 --- a/examples/quaternion.jl +++ b/examples/quaternion.jl @@ -7,6 +7,11 @@ immutable Quaternion{T<:Real} <: Number q3::T end +function Quaternion{A<:Real,B<:Real,C<:Real,D<:Real}(q0::A,q1::B,q2::C,q3::D) + T = promote_type(A,B,C,D) + Quaternion{T}(convert(T,q0), convert(T,q1), convert(T,q2), convert(T,q3)) +end + convert{T}(::Type{Quaternion{T}}, x::Real) = Quaternion(convert(T,x), convert(T,0), convert(T,0), convert(T,0)) @@ -22,6 +27,8 @@ promote_rule{T,S}(::Type{Complex{T}}, ::Type{Quaternion{S}}) = promote_rule{S}(::Type{Bool}, ::Type{Quaternion{S}}) = Quaternion{S} promote_rule{T<:Real,S}(::Type{T}, ::Type{Quaternion{S}}) = Quaternion{promote_type(T,S)} +promote_rule{T,S}(::Type{Quaternion{T}}, ::Type{Quaternion{S}}) = + Quaternion{promote_type(T,S)} function show(io::IO, z::Quaternion) show(io, z.q0)