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

fix -1.0^big #44456

Merged
merged 9 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 0 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ end
@constprop :aggressive function ^(x::Float64, y::Float64)
yint = unsafe_trunc(Int, y) # Note, this is actually safe since julia freezes the result
y == yint && return x^yint
x === -1.0 && y >= 2*inv(eps()) && return 1.0
oscardssmith marked this conversation as resolved.
Show resolved Hide resolved
x<0 && y > -4e18 && throw_exp_domainerror(x) # |y| is small enough that y isn't an integer
x == 1 && return 1.0
return pow_body(x, y)
Expand All @@ -1017,6 +1018,7 @@ end
@constprop :aggressive function ^(x::T, y::T) where T <: Union{Float16, Float32}
yint = unsafe_trunc(Int64, y) # Note, this is actually safe since julia freezes the result
y == yint && return x^yint
x === T(-1) && y >= 2*inv(eps(T)) && return T(1)
x < 0 && y > -4e18 && throw_exp_domainerror(x) # |y| is small enough that y isn't an integer
return pow_body(x, y)
end
Expand Down
2 changes: 2 additions & 0 deletions test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ end
@test x^y === T(big(x)^big(y))
@test x^1 === x
@test x^yi === T(big(x)^yi)
# test that (-1)^x == 1 for x larger than typemax(Int)
@test T(-1)^floatmax(T) === T(1)
# test for large negative exponent where error compensation matters
@test 0.9999999955206014^-1.0e8 == 1.565084574870928
@test (-x)^yi == x^yi
Expand Down