diff --git a/base/math.jl b/base/math.jl index 3831ed2831961..1ff843a3a1327 100644 --- a/base/math.jl +++ b/base/math.jl @@ -698,7 +698,9 @@ end @inline ^(x::Float64, y::Integer) = x ^ Float64(y) @inline ^(x::Float32, y::Integer) = x ^ Float32(y) @inline ^(x::Float16, y::Integer) = Float16(Float32(x) ^ Float32(y)) -@inline ^{p}(x::Float16, ::Type{Val{p}}) = Float16(Float32(x) ^ Val{p}) +@inline ^{p}(x::Float16, ::Type{Val{p}}) = Float16(x ^ p) +@inline ^{p}(x::Float32, ::Type{Val{p}}) = Float32(x ^ p) +@inline ^{p}(x::Float64, ::Type{Val{p}}) = Float64(x ^ p) function angle_restrict_symm(theta) const P1 = 4 * 7.8539812564849853515625e-01 diff --git a/test/float16.jl b/test/float16.jl index 85356aa2cdb95..a919c03e3804a 100644 --- a/test/float16.jl +++ b/test/float16.jl @@ -61,6 +61,7 @@ g = Float16(1.) @test f*g === Float16(2f0) @test f/g === Float16(2f0) @test f^g === Float16(2f0) +@test f^Val{1} === Float16(2f0) @test f^-g === Float16(0.5f0) @test f + 2 === Float16(4f0) diff --git a/test/math.jl b/test/math.jl index 372bcf0e10a24..7549a6269eb1f 100644 --- a/test/math.jl +++ b/test/math.jl @@ -31,6 +31,7 @@ end @test e < big(20//6) @test e^pi == exp(pi) @test e^2 == exp(2) + @test e^Val{2} == exp(2) @test e^2.4 == exp(2.4) @test e^(2//3) == exp(2//3) @@ -128,6 +129,7 @@ end yi = 4 @testset "Random values" begin @test x^y ≈ big(x)^big(y) + @test x^Val{1} === x @test x^yi ≈ big(x)^yi @test acos(x) ≈ acos(big(x)) @test acosh(1+x) ≈ acosh(big(1+x))