Skip to content

Commit

Permalink
Add Float16 to Base.HWReal (JuliaLang#55929)
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano authored Oct 4, 2024
1 parent 7986e17 commit 1c5cd96
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ end

# Restrict inlining to hardware-supported arithmetic types, which
# are fast enough to benefit from inlining.
const HWReal = Union{Int8,Int16,Int32,Int64,UInt8,UInt16,UInt32,UInt64,Float32,Float64}
const HWReal = Union{Int8,Int16,Int32,Int64,UInt8,UInt16,UInt32,UInt64,Float16,Float32,Float64}
const HWNumber = Union{HWReal, Complex{<:HWReal}, Rational{<:HWReal}}

# Inline x^2 and x^3 for Val
Expand Down
17 changes: 17 additions & 0 deletions test/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -616,3 +616,20 @@ end
@test Base.infer_effects(gcdx, (Int,Int)) |> Core.Compiler.is_foldable
@test Base.infer_effects(invmod, (Int,Int)) |> Core.Compiler.is_foldable
@test Base.infer_effects(binomial, (Int,Int)) |> Core.Compiler.is_foldable

@testset "literal power" begin
@testset for T in Base.uniontypes(Base.HWReal)
ns = (T(0), T(1), T(5))
if T <: AbstractFloat
ns = (ns..., T(3.14), T(-2.71))
end
for n in ns
@test n ^ 0 === T(1)
@test n ^ 1 === n
@test n ^ 2 === n * n
@test n ^ 3 === n * n * n
@test n ^ -1 inv(n)
@test n ^ -2 inv(n) * inv(n)
end
end
end

0 comments on commit 1c5cd96

Please sign in to comment.