Skip to content

Commit 2ec7dc6

Browse files
committed
🔧 Define the operation -(::Quaternion)
The operation `-q` was returning an array instead of a Quaternion.
1 parent ae219e3 commit 2ec7dc6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/quaternion.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ Compute `qu + q` or `q + qu`, in which `qu` is the scaled identity quaternion
118118
# Operation: -
119119
# ==============================================================================
120120

121+
"""
122+
-(q::Quaternion)
123+
124+
Return the quaterion `-q`.
125+
126+
"""
127+
@inline -(q::Quaternion) = -1*q
128+
121129
"""
122130
-(qa::Quaternion, qb::Quaternion)
123131

test/test_quaternions.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ end
207207
# ====================================
208208

209209
let
210+
q = Quaternion(randn(4))
211+
@test -q === -1*q
212+
210213
q = Quaternion(1,1,1,1)
211214
@test typeof(q) == Quaternion{Int}
212215

0 commit comments

Comments
 (0)