Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Static"
uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
authors = ["chriselrod", "ChrisRackauckas", "Tokazama"]
version = "0.7.4"
version = "0.7.5"

[deps]
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
Expand Down
18 changes: 10 additions & 8 deletions src/Static.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ end
ifelse(::True, @nospecialize(x), @nospecialize(y)) = x
ifelse(::False, @nospecialize(x), @nospecialize(y)) = y

StaticInt(x::False) = Zero()
StaticInt(x::True) = One()
Base.Bool(::True) = true
Base.Bool(::False) = false

const Zero = StaticInt{0}
const One = StaticInt{1}
const FloatOne = StaticFloat64{one(Float64)}
const FloatZero = StaticFloat64{zero(Float64)}

const StaticType{T} = Union{StaticNumber{T}, StaticSymbol{T}}

StaticInt(x::False) = Zero()
StaticInt(x::True) = One()
Base.Bool(::True) = true
Base.Bool(::False) = false

Base.eltype(@nospecialize(T::Type{<:StaticFloat64})) = Float64
Base.eltype(@nospecialize(T::Type{<:StaticInt})) = Int
Base.eltype(@nospecialize(T::Type{<:StaticBool})) = Bool
Expand Down Expand Up @@ -423,8 +423,6 @@ Base.xor(x::Union{Integer, Missing}, ::StaticInteger{Y}) where {Y} = xor(x, Y)
Base.:(!)(::True) = False()
Base.:(!)(::False) = True()

Base.real(@nospecialize(x::StaticNumber)) = known(x)

Base.all(::Tuple{Vararg{True}}) = true
Base.all(::Tuple{Vararg{Union{True, False}}}) = false
Base.all(::Tuple{Vararg{False}}) = false
Expand All @@ -433,6 +431,10 @@ Base.any(::Tuple{Vararg{True}}) = true
Base.any(::Tuple{Vararg{Union{True, False}}}) = true
Base.any(::Tuple{Vararg{False}}) = false

Base.real(@nospecialize(x::StaticNumber)) = x
Base.real(@nospecialize(T::Type{<:StaticNumber})) = eltype(T)
Base.imag(@nospecialize(x::StaticNumber)) = zero(x)

"""
field_type(::Type{T}, f)

Expand Down Expand Up @@ -590,7 +592,7 @@ value is a `StaticInt`.
end
end

function Base.invperm(p::Tuple{StaticInt,Vararg{StaticInt,N}}) where {N}
function Base.invperm(p::Tuple{StaticInt, Vararg{StaticInt, N}}) where {N}
map(Base.Fix2(find_first_eq, p), ntuple(static, StaticInt(N + 1)))
end

Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ end
@test +(p, static(1)) == +(static(1), p) == +(p, 1)
@test -(p, static(1)) == -(static(1), p) == -(p, 1)
end

@test real(static(3)) === static(3)
@test imag(static(3)) === static(0)
end

@testset "StaticBool" begin
Expand Down