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

rational powers (fixes #18114) #18118

Merged
merged 3 commits into from
Aug 19, 2016
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
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 @@ -2137,7 +2137,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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but you can use cbrt(BigFloat(2)) on the left-hand side

Copy link
Member

@stevengj stevengj Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not if we want to guarantee exact equality, since cbrt might eventually do something fancy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already does for BigFloat, which calls mpfr_cbrt.


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