From 044e3ef3f6b08b446926481107ac0876568f2045 Mon Sep 17 00:00:00 2001 From: Brandon Flores Date: Mon, 4 Nov 2024 15:19:53 -0600 Subject: [PATCH] Defined `isinf`, `isnan`, `isreal`, `isinteger`, `iseven`, and `isodd` --- src/CliffordNumbers.jl | 1 + src/math/arithmetic.jl | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/CliffordNumbers.jl b/src/CliffordNumbers.jl index 57eaeb2..62643cc 100644 --- a/src/CliffordNumbers.jl +++ b/src/CliffordNumbers.jl @@ -5,6 +5,7 @@ import Base: zero, one, oneunit import Base: signbit, sign, copysign, flipsign import Base: reverse, adjoint, conj, ~ import Base: ==, isequal, isapprox, +, -, *, /, //, muladd, abs, abs2, exp, ^ +import Base: isfinite, isinf, isnan, isreal, isinteger, iseven, isodd import Base: promote_rule, convert, similar, float, big import Base: print, show, summary diff --git a/src/math/arithmetic.jl b/src/math/arithmetic.jl index dd6d0e5..683ad21 100644 --- a/src/math/arithmetic.jl +++ b/src/math/arithmetic.jl @@ -35,6 +35,21 @@ end isapprox(x::AbstractCliffordNumber, y::Number; kwargs...) = isapprox(promote(x, y)...; kwargs...) isapprox(x::Number, y::AbstractCliffordNumber; kwargs...) = isapprox(promote(y, x)...; kwargs...) +#---Other properties-------------------------------------------------------------------------------# + +# Already works: Base.isfinite(x::AbstractCliffordNumber) = all(isfinite, Tuple(x)) +isinf(x::AbstractCliffordNumber) = any(isinf, Tuple(x)) +isnan(x::AbstractCliffordNumber) = any(isnan, Tuple(x)) + +isreal(x::AbstractCliffordNumber) = isreal(scalar(x)) && isscalar(x) +isreal(x::AbstractCliffordNumber{<:Any,<:Real}) = isscalar(x) + +isinteger(x::AbstractCliffordNumber) = isinteger(scalar(x)) && isscalar(x) +isinteger(x::AbstractCliffordNumber{<:Any,<:Integer}) = isscalar(x) + +iseven(x::AbstractCliffordNumber) = isreal(x) && iseven(real(scalar(x))) +isodd(x::AbstractCliffordNumber) = isreal(x) && isodd(real(scalar(x))) + #---Addition, negation, and subtraction------------------------------------------------------------# +(x::T, y::T) where T<:AbstractCliffordNumber = T(map(+, Tuple(x), Tuple(y)))