diff --git a/base/gmp.jl b/base/gmp.jl index b957ab22a4bea..90874b01977c2 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -931,7 +931,7 @@ function Base.://(x::Rational{BigInt}, y::Rational{BigInt}) if iszero(x.num) throw(DivideError()) end - return (isneg(x.num) ? -one(BigFloat) : one(BigFloat)) // y.num + return (isneg(x.num) ? -one(BigInt) : one(BigInt)) // y.num end zq = _MPQ() ccall((:__gmpq_div, :libgmp), Cvoid, diff --git a/test/gmp.jl b/test/gmp.jl index 3d7317b37bacc..1f34f67ecf1f5 100644 --- a/test/gmp.jl +++ b/test/gmp.jl @@ -69,6 +69,18 @@ ee = typemax(Int64) @test big(typeof(complex(x, x))) == typeof(big(complex(x, x))) end end + @testset "division" begin + oz = big(1 // 0) + zo = big(0 // 1) + + @test_throws DivideError() oz / oz + @test oz == oz / one(oz) + @test -oz == oz / (-one(oz)) + @test zero(oz) == one(oz) / oz + @test_throws DivideError() zo / zo + @test one(zo) / zo == big(1//0) + @test -one(zo) / zo == big(-1//0) + end end @testset "div, fld, mod, rem" begin for i = -10:10, j = [-10:-1; 1:10]