From 418507c643504a1e2fb45f0b528b73185c0fb0a4 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 10 Aug 2015 12:38:58 -0400 Subject: [PATCH] allow Rational inner ctor to accept any Integers. fixes #12536 --- base/rational.jl | 2 +- test/numbers.jl | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/base/rational.jl b/base/rational.jl index dc32a6cdb5eb3..f52906b6d84f8 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -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)) diff --git a/test/numbers.jl b/test/numbers.jl index 6f5802f57429e..15c5ea77dbb33 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -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))