Skip to content

Commit 66a9e6a

Browse files
committed
Add Zero and One constants
1 parent f57b4e6 commit 66a9e6a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/static.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Use `Static(N)` instead of `Val(N)` when you want it to behave like a number.
66
struct Static{N} <: Integer
77
Static{N}() where {N} = new{N::Int}()
88
end
9+
10+
const Zero = Static{0}()
11+
const One = Static{1}()
12+
913
Base.@pure Static(N::Int) = Static{N}()
1014
Static(N::Integer) = Static(convert(Int, N))
1115
Static(::Static{N}) where {N} = Static{N}()
@@ -38,8 +42,8 @@ Base.iszero(::Static{0}) = true
3842
Base.iszero(::Static) = false
3943
Base.isone(::Static{1}) = true
4044
Base.isone(::Static) = false
41-
Base.zero(::Type{T}) where {T<:Static} = Static{0}()
42-
Base.one(::Type{T}) where {T<:Static} = Static{1}()
45+
Base.zero(::Type{T}) where {T<:Static} = Zero
46+
Base.one(::Type{T}) where {T<:Static} = One
4347

4448
for T = [:Real, :Rational, :Integer]
4549
@eval begin

0 commit comments

Comments
 (0)