Skip to content

Commit

Permalink
allow Rational inner ctor to accept any Integers. fixes JuliaLang#12536
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Aug 10, 2015
1 parent 8b1ae03 commit 418507c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ immutable Rational{T<:Integer} <: Real
num::T
den::T

function Rational(num::T, den::T)
function Rational(num::Integer, den::Integer)
num == den == zero(T) && throw(ArgumentError("invalid rational: zero($T)//zero($T)"))
g = den < 0 ? -gcd(den, num) : gcd(den, num)
new(div(num, g), div(den, g))
Expand Down
4 changes: 4 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2518,3 +2518,7 @@ for (d,B) in ((4//2+1im,Rational{BigInt}),(3.0+1im,BigFloat),(2+1im,BigInt))
end

@test 0x2^9 === 0x2^big(9) === 0x0

# issue #12536
@test Rational{Int16}(1,2) === Rational(Int16(1),Int16(2))
@test Rational{Int16}(500000,1000000) === Rational(Int16(1),Int16(2))

0 comments on commit 418507c

Please sign in to comment.