Skip to content

Commit

Permalink
import isneg
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Nov 21, 2020
1 parent 2a9b9da commit 8dac842
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ module MPQ

# Rational{BigInt}
import .Base: unsafe_rational, __throw_rational_argerror_zero
import ..GMP: BigInt, MPZ, Limb
import ..GMP: BigInt, MPZ, Limb, isneg

mutable struct _MPQ
num_alloc::Cint
Expand Down Expand Up @@ -885,7 +885,7 @@ end

function Base.:+(x::Rational{BigInt}, y::Rational{BigInt})
if iszero(x.den) || iszero(y.den)
if iszero(x.den) && iszero(y.den) && signbit(x.num) != signbit(y.num)
if iszero(x.den) && iszero(y.den) && isneg(x.num) != isneg(y.num)
throw(DivideError())
end
return iszero(x.den) ? x : y
Expand All @@ -897,7 +897,7 @@ function Base.:+(x::Rational{BigInt}, y::Rational{BigInt})
end
function Base.:-(x::Rational{BigInt}, y::Rational{BigInt})
if iszero(x.den) || iszero(y.den)
if iszero(x.den) && iszero(y.den) && signbit(x.num) == signbit(y.num)
if iszero(x.den) && iszero(y.den) && isneg(x.num) == isneg(y.num)
throw(DivideError())
end
return iszero(x.den) ? x : -y
Expand All @@ -912,7 +912,7 @@ function Base.:*(x::Rational{BigInt}, y::Rational{BigInt})
if iszero(x.num) || iszero(y.num)
throw(DivideError())
end
return xor(signbit(x.num),signbit(y.num)) ? -one(BigInt)//zero(BigInt) : one(BigInt)//zero(BigInt)
return xor(isneg(x.num),isneg(y.num)) ? -one(BigInt)//zero(BigInt) : one(BigInt)//zero(BigInt)
end
zq = _MPQ()
ccall((:__gmpq_mul, :libgmp), Cvoid,
Expand Down

0 comments on commit 8dac842

Please sign in to comment.