Skip to content

Commit e6ae95b

Browse files
authored
Merge pull request #74 from SciML/realimag
Define `real` and `imag` for StaticInteger
2 parents 7e01c7a + d7d30be commit e6ae95b

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Static"
22
uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
33
authors = ["chriselrod", "ChrisRackauckas", "Tokazama"]
4-
version = "0.7.4"
4+
version = "0.7.5"
55

66
[deps]
77
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"

src/Static.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ end
8787
ifelse(::True, @nospecialize(x), @nospecialize(y)) = x
8888
ifelse(::False, @nospecialize(x), @nospecialize(y)) = y
8989

90-
StaticInt(x::False) = Zero()
91-
StaticInt(x::True) = One()
92-
Base.Bool(::True) = true
93-
Base.Bool(::False) = false
94-
9590
const Zero = StaticInt{0}
9691
const One = StaticInt{1}
9792
const FloatOne = StaticFloat64{one(Float64)}
9893
const FloatZero = StaticFloat64{zero(Float64)}
9994

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

97+
StaticInt(x::False) = Zero()
98+
StaticInt(x::True) = One()
99+
Base.Bool(::True) = true
100+
Base.Bool(::False) = false
101+
102102
Base.eltype(@nospecialize(T::Type{<:StaticFloat64})) = Float64
103103
Base.eltype(@nospecialize(T::Type{<:StaticInt})) = Int
104104
Base.eltype(@nospecialize(T::Type{<:StaticBool})) = Bool
@@ -423,8 +423,6 @@ Base.xor(x::Union{Integer, Missing}, ::StaticInteger{Y}) where {Y} = xor(x, Y)
423423
Base.:(!)(::True) = False()
424424
Base.:(!)(::False) = True()
425425

426-
Base.real(@nospecialize(x::StaticNumber)) = known(x)
427-
428426
Base.all(::Tuple{Vararg{True}}) = true
429427
Base.all(::Tuple{Vararg{Union{True, False}}}) = false
430428
Base.all(::Tuple{Vararg{False}}) = false
@@ -433,6 +431,10 @@ Base.any(::Tuple{Vararg{True}}) = true
433431
Base.any(::Tuple{Vararg{Union{True, False}}}) = true
434432
Base.any(::Tuple{Vararg{False}}) = false
435433

434+
Base.real(@nospecialize(x::StaticNumber)) = x
435+
Base.real(@nospecialize(T::Type{<:StaticNumber})) = eltype(T)
436+
Base.imag(@nospecialize(x::StaticNumber)) = zero(x)
437+
436438
"""
437439
field_type(::Type{T}, f)
438440
@@ -590,7 +592,7 @@ value is a `StaticInt`.
590592
end
591593
end
592594

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

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ end
9898
@test +(p, static(1)) == +(static(1), p) == +(p, 1)
9999
@test -(p, static(1)) == -(static(1), p) == -(p, 1)
100100
end
101+
102+
@test real(static(3)) === static(3)
103+
@test imag(static(3)) === static(0)
101104
end
102105

103106
@testset "StaticBool" begin

0 commit comments

Comments
 (0)