Skip to content

Commit 0a5b294

Browse files
authored
Popagate StaticInt on max/min/minmax (#57)
1 parent fe85e11 commit 0a5b294

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
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.6.3"
4+
version = "0.6.4"
55

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

src/int.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ Base.:(*)(::Zero, ::Zero) = Zero()
7575

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

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

82+
Base.minmax(x::StaticInt, y::StaticInt) = y < x ? (y, x) : (x, y)
83+
8284
for f in [:(<<), :(>>), :(>>>)]
8385
@eval begin
8486
Base.$f(@nospecialize(x::StaticInt), y::UInt) = $f(Int(x), y)

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ using Test
1818
@test eltype(one(StaticInt)) <: Int
1919

2020
x = StaticInt(1)
21+
y = static(3)
22+
@test @inferred(minmax(x, y)) == @inferred(minmax(y, x)) == minmax(1, 3)
2123
@test @inferred(Bool(x)) isa Bool
2224
@test @inferred(BigInt(x)) isa BigInt
2325
@test @inferred(Integer(x)) === x
@@ -26,7 +28,7 @@ using Test
2628
for i Any[StaticInt(0), StaticInt(1), StaticInt(2), 3]
2729
for j Any[StaticInt(0), StaticInt(1), StaticInt(2), 3]
2830
i === j === 3 && continue
29-
for f [+, -, *, ÷, %, <<, >>, >>>, &, |, , ==, , ]
31+
for f [+, -, *, ÷, %, <<, >>, >>>, &, |, , ==, , , min, max]
3032
(iszero(j) && ((f === ÷) || (f === %))) && continue # integer division error
3133
@test convert(Int, @inferred(f(i,j))) == f(convert(Int, i), convert(Int, j))
3234
end

0 commit comments

Comments
 (0)