Skip to content
Closed
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
3 changes: 3 additions & 0 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ importall .StackTraces
# misc useful functions & macros
include("util.jl")

# limited compile-time arithmetic on Val types
include("valmath.jl")

# dense linear algebra
include("linalg/linalg.jl")
importall .LinAlg
Expand Down
3 changes: 3 additions & 0 deletions base/valmath.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@generated (+)(::Type{Val{X}}, ::Type{Val{Y}}) where {X, Y} = :(Val{$(X + Y)})
@generated (-)(::Type{Val{X}}, ::Type{Val{Y}}) where {X, Y} = :(Val{$(X - Y)})
@generated (*)(::Type{Val{X}}, ::Type{Val{Y}}) where {X, Y} = :(Val{$(X * Y)})
2 changes: 1 addition & 1 deletion test/choosetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function choosetests(choices = [])
"enums", "cmdlineargs", "i18n", "workspace", "libdl", "int",
"checked", "intset", "floatfuncs", "compile", "distributed", "inline",
"boundscheck", "error", "ambiguous", "cartesian", "asmvariant", "osutils",
"channels", "iostream", "specificity", "codegen"
"channels", "iostream", "specificity", "codegen", "valmath"
]
profile_skipped = false
if startswith(string(Sys.ARCH), "arm")
Expand Down
19 changes: 19 additions & 0 deletions test/valmath.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@testset "Val math" begin
@testset "Val +" begin
@testset for x in -10:1:10, y in -10:1:10
@test Val{x} + Val{y} == Val{x + y}
end
end

@testset "Val -" begin
@testset for x in -10:1:10, y in -10:1:10
@test Val{x} - Val{y} == Val{x - y}
end
end

@testset "Val *" begin
@testset for x in -10:1:10, y in -10:1:10
@test Val{x} * Val{y} == Val{x * y}
end
end
end