Skip to content

Commit

Permalink
bug fix for x^Val{p} (fixes problem noted in #20648)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Feb 22, 2017
1 parent 35ce0fd commit fd1f577
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ end
^(x::Bool , y::BigInt ) = Base.power_by_squaring(x, y)

# override default inlining of x^2 and x^3 etc.
^{p}(x::BigInt, ::Type{Val{p}}) = x^Culong(p)
^{p}(x::BigInt, ::Type{Val{p}}) = x^p

function powermod(x::BigInt, p::BigInt, m::BigInt)
r = BigInt()
Expand Down
2 changes: 1 addition & 1 deletion base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ end
^(x::BigFloat, y::Unsigned) = typemin(Culong) <= y <= typemax(Culong) ? x^Culong(y) : x^BigInt(y)

# override default inlining of x^2 etc.
^{p}(x::BigFloat, ::Type{Val{p}}) = x^Culong(p)
^{p}(x::BigFloat, ::Type{Val{p}}) = x^p

for f in (:exp, :exp2, :exp10, :expm1, :cosh, :sinh, :tanh, :sech, :csch, :coth, :cbrt)
@eval function $f(x::BigFloat)
Expand Down
11 changes: 11 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2912,6 +2912,17 @@ immutable PR20530; end
@test x^p == 1
@test x^2 == 2
@test [x,x,x].^2 == [2,2,2]
for T in (Float16, Float32, Float64, BigFloat, Int8, Int, BigInt, Complex{Int}, Complex{Float64})
for p in -4:4
if p < 0 && (T <: Integer || T == Complex{Int})
@test_throws DomainError eval(:($T(2)^$p))
else
v = eval(:($T(2)^$p))
@test 2^p == T(2)^p == v
@test v isa T
end
end
end
end

@testset "iszero" begin
Expand Down

0 comments on commit fd1f577

Please sign in to comment.