mpq_get_d() rounding for different platforms?

K Shen kishshen at yahoo.com
Mon Mar 16 17:40:15 CET 2009


Hi,



I am trying to port our system (the constraint logic programming 
platform ECLiPSe) to 64 bit x86-64 Windows, using MinGW-W64. Our system 
uses GMP to implement large integers and rationals, and I have run into 
some issues with rounding of rationals to double (using mpq_get_d()).



I am using GMP 4.2.2, because I believe is the GMP version used by 
MinGW-W64 itself. The issue I have ran into is that in some cases, the 
MinGW-W64 version of GMP returns a slightly different double from the 32 
bit Linux version of the same GMP. For example, for the rational 4/5,

the MinGW version returns 0.79999999999999993, while the Linux version 
returns 0.80000000000000004.



Looking at the manual, it seems that from GMP 4.2 onwards, mpq_get_d() 
should round towards zero, and this suggest to me that 
0.79999999999999993 should be returned, for both platforms (they have 
the same representation for double, I believe). Should the two platforms 
return different values, and is there anyway I can get them to return 
the same value on platforms with the same double representation?



Thanks in advance for any information!



Kish Shen





      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gmplib.org/list-archives/gmp-discuss/attachments/20090316/0c9e913b/attachment.html>


More information about the gmp-discuss mailing list