Skip to content

Commit

Permalink
rational powers (fixes #18114) (#18118)
Browse files Browse the repository at this point in the history
Fixes precision problem for rational powers of BigFloats (#18114)
(cherry picked from commit db03824)
  • Loading branch information
pwl authored and tkelman committed Aug 20, 2016
1 parent 6d0aa14 commit 51aadfe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ function ^(x::Rational, n::Integer)
end

^(x::Number, y::Rational) = x^(y.num/y.den)
^{T<:AbstractFloat}(x::T, y::Rational) = x^(convert(T, y.num / y.den))
^{T<:AbstractFloat}(x::Complex{T}, y::Rational) = x^(convert(T, y.num / y.den))
^{T<:AbstractFloat}(x::T, y::Rational) = x^convert(T,y)
^{T<:AbstractFloat}(x::Complex{T}, y::Rational) = x^convert(T,y)

^{T<:Rational}(z::Complex{T}, n::Bool) = n ? z : one(z) # to resolve ambiguity
function ^{T<:Rational}(z::Complex{T}, n::Integer)
Expand Down
3 changes: 2 additions & 1 deletion test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2139,7 +2139,8 @@ rationalize(nextfloat(0.0)) == 0//1
# rational-exponent promotion rules (issue #3155):
@test 2.0f0^(1//3) == 2.0f0^(1.0f0/3)
@test 2^(1//3) == 2^(1/3)

# no loss of precision for rational powers (issue #18114)
@test BigFloat(2)^(BigFloat(1)/BigFloat(3)) == BigFloat(2)^(1//3)

# large shift amounts
@test Int32(-1)>>31 == -1
Expand Down

0 comments on commit 51aadfe

Please sign in to comment.