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: 2 additions & 0 deletions src/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Base.:-(@nospecialize(x::StaticFloat64), @nospecialize(y::StaticFloat64)) = fsub
Base.:*(@nospecialize(x::StaticFloat64), @nospecialize(y::StaticFloat64)) = fmul(x, y)
@inline Base.:*(@nospecialize(x::StaticFloat64), @nospecialize(y::StaticInt)) = *(x, float(y))
@inline Base.:*(@nospecialize(x::StaticInt), @nospecialize(y::StaticFloat64)) = *(float(x), y)
@inline Base.:*(@nospecialize(x::StaticFloat64), ::Zero) = FloatZero()
@inline Base.:*(::Zero, @nospecialize(y::StaticFloat64)) = FloatZero()

Base.:/(@nospecialize(x::StaticFloat64), @nospecialize(y::StaticFloat64)) = fdiv(x, y)
Base.:/(@nospecialize(x::StaticFloat64), @nospecialize(y::StaticInt)) = /(x, float(y))
Expand Down
10 changes: 10 additions & 0 deletions src/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,29 @@ Base.isone(@nospecialize(x::StaticInt)) = false
Base.zero(@nospecialize(x::Type{<:StaticInt})) = Zero()
Base.one(@nospecialize(x::Type{<:StaticInt})) = One()


for T in [:Real, :Rational, :Integer]
for f in [:(-), :(+), :(*)]
@eval begin
Base.$(f)(x::$T, @nospecialize(y::StaticInt)) = $(f)(x, Int(y))
Base.$(f)(@nospecialize(x::StaticInt), y::$T) = $(f)(Int(x), y)
end
end
@eval begin
Base.:(*)(::$T, ::Zero) = Zero()
Base.:(*)(::Zero, ::$T) = Zero()
end
end
Base.:(*)(@nospecialize(x::StaticInt), ::Zero) = Zero()
Base.:(*)(::Zero, @nospecialize(y::StaticInt)) = Zero()
Base.:(*)(::Zero, ::Zero) = Zero()

@inline Base.:(-)(::StaticInt{M}) where {M} = StaticInt{-M}()

for f in [:(+), :(-), :(*), :(÷), :(%), :(<<), :(>>), :(>>>), :(&), :(|), :(⊻)]
eval(:(Base.$f(::StaticInt{M}, ::StaticInt{N}) where {M,N} = StaticInt{$f(M,N)}()))
end

for f in [:(<<), :(>>), :(>>>)]
@eval begin
Base.$f(@nospecialize(x::StaticInt), y::UInt) = $f(Int(x), y)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Static, Aqua
using Static: Zero
using Test

@testset "Static.jl" begin
Expand Down Expand Up @@ -43,6 +44,7 @@ using Test
@test convert(typeof(z), @inferred(f(2 // 7, i))) === z
end
end
@test @inferred(*(Zero(), 3)) === @inferred(*(3, Zero())) === *(Zero(), Zero())

@test UnitRange{Int16}(StaticInt(-9), 17) === Int16(-9):Int16(17)
@test UnitRange{Int16}(-7, StaticInt(19)) === Int16(-7):Int16(19)
Expand Down