Skip to content

Commit be0fc14

Browse files
authored
Add convenient type-aliases (#63)
* Add type aliases * Export type aliases * Test type aliases * Increment version number * Increment version number
1 parent 34050c0 commit be0fc14

File tree

6 files changed

+37
-4
lines changed

6 files changed

+37
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Quaternions"
22
uuid = "94ee1d12-ae83-5a48-8b1c-48b8ff168ae0"
3-
version = "0.4.6"
3+
version = "0.4.7"
44

55
[deps]
66
DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"

src/DualQuaternion.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ DualQuaternion(q::Quaternion) = DualQuaternion(q, zero(q), q.norm)
2121

2222
DualQuaternion(a::Vector) = DualQuaternion(zero(Quaternion{typeof(a[1])}), Quaternion(a))
2323

24+
const DualQuaternionF16 = DualQuaternion{Float16}
25+
const DualQuaternionF32 = DualQuaternion{Float32}
26+
const DualQuaternionF64 = DualQuaternion{Float64}
27+
2428
convert(::Type{DualQuaternion{T}}, x::Real) where {T} =
2529
DualQuaternion(convert(Quaternion{T}, x), convert(Quaternion{T}, 0))
2630

src/Octonion.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Octonion(q::Quaternion) = Octonion(q.s, q.v1, q.v2, q.v3, zero(q.s), zero(q.s),
1818
Octonion(s::Real, a::Vector) = Octonion(s, a[1], a[2], a[3], a[4], a[5], a[6], a[7])
1919
Octonion(a::Vector) = Octonion(0, a[1], a[2], a[3], a[4], a[5], a[6], a[7])
2020

21+
const OctonionF16 = Octonion{Float16}
22+
const OctonionF32 = Octonion{Float32}
23+
const OctonionF64 = Octonion{Float64}
24+
2125
convert(::Type{Octonion{T}}, x::Real) where {T} =
2226
Octonion(convert(T, x), convert(T, 0), convert(T, 0), convert(T, 0), convert(T, 0), convert(T, 0), convert(T, 0), convert(T, 0))
2327
convert(::Type{Octonion{T}}, z::Complex) where {T} =

src/Quaternion.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ struct Quaternion{T<:Real} <: Number
66
norm::Bool
77
end
88

9+
const QuaternionF16 = Quaternion{Float16}
10+
const QuaternionF32 = Quaternion{Float32}
11+
const QuaternionF64 = Quaternion{Float64}
12+
913
(::Type{Quaternion{T}})(x::Real) where {T} = Quaternion{T}(x, 0, 0, 0, false)
1014
(::Type{Quaternion{T}})(q::Quaternion{T}) where {T<:Real} = q
1115
(::Type{Quaternion{T}})(q::Quaternion) where {T<:Real} = Quaternion{T}(q.s, q.v1, q.v2, q.v3, q.norm)

src/Quaternions.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ module Quaternions
1515
include("Octonion.jl")
1616
include("DualQuaternion.jl")
1717

18-
export Quaternion
18+
export Quaternion,
19+
QuaternionF16,
20+
QuaternionF32,
21+
QuaternionF64,
22+
Octonion,
23+
OctonionF16,
24+
OctonionF32,
25+
OctonionF64,
26+
DualQuaternion,
27+
DualQuaternionF16,
28+
DualQuaternionF32,
29+
DualQuaternionF64
1930
export quat
20-
export Octonion
2131
export octo
22-
export DualQuaternion
2332
export dualquat
2433
export angleaxis
2534
export angle

test/test_Quaternion.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ using Quaternions: argq
33
using LinearAlgebra
44
using Random
55

6+
@testset "type aliases" begin
7+
@test QuaternionF16 === Quaternion{Float16}
8+
@test QuaternionF32 === Quaternion{Float32}
9+
@test QuaternionF64 === Quaternion{Float64}
10+
@test OctonionF16 === Octonion{Float16}
11+
@test OctonionF32 === Octonion{Float32}
12+
@test OctonionF64 === Octonion{Float64}
13+
@test DualQuaternionF16 === DualQuaternion{Float16}
14+
@test DualQuaternionF32 === DualQuaternion{Float32}
15+
@test DualQuaternionF64 === DualQuaternion{Float64}
16+
end
17+
618
# creating random examples
719
sample(QT::Type{Quaternion{T}}) where {T <: Integer} = QT(rand(-100:100, 4)..., false)
820
sample(QT::Type{Quaternion{T}}) where {T <: AbstractFloat} = QT(rand(Bool) ? quatrand() : nquatrand())

0 commit comments

Comments
 (0)