Skip to content

Commit

Permalink
OddCliffordNumber constructor now fails to convert arbitrary scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
brainandforce committed Aug 8, 2024
1 parent 2e9103e commit c9132ab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed
- `OddCliffordNumber` constructors now fail to operate on scalars unless there is exactly one odd
element in the algebra.

## [0.1.6] - 2024-06-27

### Added
Expand Down
11 changes: 11 additions & 0 deletions src/even.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ end
# Convert real/complex numbers to CliffordNumber
(::Type{T})(x::BaseNumber) where {T<:Z2CliffordNumber} = T(ntuple(i -> x*isone(i), Val(nblades(T))))

function (::Type{T})(x::BaseNumber) where {T<:OddCliffordNumber}
isone(nblades(T)) && return T(ntuple(i -> x*isone(i), Val(nblades(T))))
throw(
DomainError(
x,
"An OddCliffordNumber cannot be constructed from a scalar unless the algebra " *
"contains exactly one odd element."
)
)
end

#---Number of elements-----------------------------------------------------------------------------#

nblades(::Type{<:Z2CliffordNumber{P,Q}}) where {P,Q} = div(blade_count(Q), 2)
Expand Down
3 changes: 3 additions & 0 deletions test/construction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ end
k2 = KVector{2,VGA(3)}(1, 2, 3)
@test CliffordNumber{VGA(3)}(1337) === CliffordNumber{VGA(3)}(1337, 0, 0, 0, 0, 0, 0, 0)
@test EvenCliffordNumber{VGA(3)}(1337) === EvenCliffordNumber{VGA(3)}(1337, 0, 0, 0)
# If there is more than one odd element of the subalgebra, this should throw
@test_throws DomainError OddCliffordNumber{VGA(3)}(1337)
@test OddCliffordNumber{VGA(1)}(1337) == KVector{1,VGA(1)}(1337)
# Mixed types in input
@test CliffordNumber{VGA(3)}(0.0, 0, 0, 0, 0, 0, 0, 0) === zero(CliffordNumber{VGA(3),Float64})
@test CliffordNumber{VGA(3)}(0, 0, 0, 0, 0, 0, 0, 0.0) === zero(CliffordNumber{VGA(3),Float64})
Expand Down

0 comments on commit c9132ab

Please sign in to comment.