JuliaLang/julia — pull request #3155 by stevengj (2013-05-20 17:02:57+00:00)
Title: ^(x::Number,y::Rational) should promote y to the correct type

`rational.jl` contains the rule:

^(x::Number, y::Rational) = x^(y.num/y.den)

which always promotes `y` to `Float64` (for `Rational{Int}`) regardless of the type of `x`. This is too *little* precision if `x` is a `BigFloat` (in which case the exponent should be computed in `BigFloat` precision), and is too *much* precision if `x` is `Float32` (in which case we want a `Float32` result).

The attached patch corrects this by adding two extra definitions (an a test case):

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