Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix for x^Val{p} (fixes problem noted in #20648) #20732

Merged
merged 1 commit into from
Feb 22, 2017
Merged
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
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 && real(T) <: Integer
@test_throws DomainError eval(:($T(2)^$p))
else
v = eval(:($T(2)^$p))
@test 2.0^p == T(2)^p == v
@test v isa T
end
end
end
end

@testset "iszero" begin
Expand Down