Quaternion type: Difference between revisions
Content added Content deleted
(added Julia example) |
|||
Line 2,777:
=={{header|Julia}}==
This is from the [https://github.com/JuliaLang/julia/blob/master/examples/quaternion.jl quaternion example file] included with Julia 0.2, which implements a quaternion type complete with arithmetic, type conversions and promotion rules, and pretty-printing:
<lang julia>import Base: promote_rule, convert
Line 2,857:
Example usage and output: <lang julia>julia> q = Quaternion(1,0,0,0)
julia>
q1 = Quaternion(2, 3, 4, 5)
q2 = Quaternion(3, 4, 5, 6)
r = 7.
julia>
5.477225575051661
julia> -q
q = 1 + 0i + 0j + 0k▼
-1 - 2i - 3j - 4k
q*2.0+2 = 4.0 + 0.0i + 0.0j + 0.0k▼
julia> conj(q)
1 - 2i - 3j - 4k
julia> r + q, q + r
julia> q1 + q2
julia> r*q, q*r
(7.0 + 14.0i + 21.0j + 28.0k,7.0 + 14.0i + 21.0j + 28.0k)
julia> q1*q2, q2*q1, q1*q2 != q2*q1
(-56 + 16i + 24j + 26k,-56 + 18i + 20j + 28k,true)</lang>
=={{header|Liberty BASIC}}==
|