From c92e98dd3f94af2851185e6a4e234c657dcc880b Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 14 Nov 2013 23:24:03 -0500 Subject: [PATCH] another possible workaround for the GMP gcdx issue --- base/gmp.jl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/base/gmp.jl b/base/gmp.jl index 4c406911b759f..2bab89d7c2956 100644 --- a/base/gmp.jl +++ b/base/gmp.jl @@ -325,17 +325,21 @@ function gcdx(a::BigInt, b::BigInt) if b == 0 # shortcut this to ensure consistent results with gcdx(a,b) return a < 0 ? (-a,-one(BigInt),zero(BigInt)) : (a,one(BigInt),zero(BigInt)) end - if a == b - # work around a difference in some versions of GMP - return a < 0 ? (-a,zero(BigInt),-one(BigInt)) : (a,zero(BigInt),one(BigInt)) - end g = BigInt() s = BigInt() t = BigInt() ccall((:__gmpz_gcdext, :libgmp), Void, (Ptr{BigInt}, Ptr{BigInt}, Ptr{BigInt}, Ptr{BigInt}, Ptr{BigInt}), &g, &s, &t, &a, &b) - BigInt(g), BigInt(s), BigInt(t) + if t == 0 + # work around a difference in some versions of GMP + if a == b + return g, t, s + elseif abs(a)==abs(b) + return g, t, -s + end + end + g, s, t end function sum(arr::AbstractArray{BigInt})