Bill Allombert on Fri, 28 May 2010 00:09:09 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: integer representation in pari |
On Thu, May 27, 2010 at 05:27:00PM -0400, Sam Steingold wrote: > Hi, > It appears that integers are represented differently on different platforms. > Specifically, the "byte" order is different. > I have two machines, both little-endian: > 32bit AMD with "GP/PARI CALCULATOR Version 2.3.4 (released)" > 64bit Intel Pentium D with "GP/PARI CALCULATOR Version 2.3.5 (released)" Unfortunately this is the next line which is of importance here. Specifically, it depends whether you use the GMP kernel or the PARI kernel. > (gdb) p readseq("7906420317433764459701366445") > $1 = 11282736 Instead of using the debugger, you could just \x in gp: 7906420317433764459701366445 \x [&=00000000010b6940] INT(lg=4,CLONE):0300000000000004 (+,lgefint=4):4000000000000004 3cbd223800046ead 00000000198c09a0 > so we can see that the number is represented as 3 "32-bit bytes" in > positions 2,3,4, > ***LOW*** bytes first So you use the GMP kernel on 32bit. > 64-bit machine: > (+ (ash 428607904 64) 4376692036787793581) > => 7906420317433764459701366445 > > so we can see that the number is represented as 2 "64-bit bytes" in > positions 2,3, > ***HIGH*** bytes first. So you use the PARI kernel on 64bit. > Where is this documented? In the documentation. Try ??libpari and look up the definition of t_INT page 21. > Where is this behavior defined? You can use ./Configure --with-gmp or ./Configure --without-gmp to force one kernel to be used. (--without-gmp is the default for PARI 2.3, --with-gmp is the default for PARI 2.4.3) > How do I know what byte order is used on which platform? Looks at the name of the libpari library: if it is named libpari-gmp.so.2 then it is using the GMP kernel. You can also check whether the C macro PARI_KERNEL_GMP is defined, but usually it is better to use int_W() to acces the mantissa. Cheers, Bill.