gmp_gcdext method on 32bit vs 64 bit machines

Marc Glisse marc.glisse at inria.fr
Tue Apr 19 19:27:47 CEST 2011


On Fri, 15 Apr 2011, Waiki Wright wrote:

> Let me know if this is not the right place to post this question.

gmp-bugs sounds better, but I don't know.

> I have 2 machines- RedHat Rel6 64 bit and RedHat Rel6 32 bit.  I have php 5.3 
> and gmp 4.3 on both machines.
>
> I am using gmp_gcdex() method from php to get the g, s, t values.
> When I ran gmp_gcdex("34293864345", "23434293864345"); on the 64 bit and 32 
> bit machines, I got different results for s & t:
>
> On 64 bit: g=195, s= -20983781660442, t= 30707772373
> On 32 bit: g=195, s= -4760039754357, t= 6965866288
>
> I looked into how php treating big integers on 32 and 64 bit machine but did 
> not find anything.
>
> Does anyone have any idea why s & t values are different on 64 bit vs 32 bit?

This list is for GMP, the C (and C++) library, not the PHP interface, so 
you could try and reproduce this with a C program, and preferably using 
the latest GMP version.

The guarantees promised by the documentation are only: "abs(s) <= abs(b) 
and abs(t) <= abs(a)" which allows for many valid outputs. I believe the 
code was changed to better canonicalize the result in later versions 
(though it isn't documented), search the archives of the lists if you are 
interested.

In 64 bits, your numbers fit in 1 limb (an unsigned long), while in 32 
bits they require 2 limbs, so it isn't too surprising that the 
computations could turn out differently.

-- 
Marc Glisse


More information about the gmp-discuss mailing list