mpq_get_d() rounding for different platforms?
K Shen
kishshen at yahoo.com
Tue Mar 17 22:41:02 CET 2009
Hi,
I ran the same code on all systems:
main () {
double i, j, k;
mpq_t rat;
printf("hi\n");
mpq_init(rat);
mpq_set_ui(rat, 4, 5);
k = mpq_get_d(rat);
printf("rat is %.17f\n", k);
}
and I built from the same GMP source.
The version of gcc used for each build is different:
32 bit Linux gcc 3.2.3
MinGW 32 bit Windows gcc 3.4.1
MinGW 64 bit Windows gcc 4.4.0
Does the version of gcc makes a difference? The Linux version was the only one I was able to run make check on (and it passed, as far as I can tell), because the others were all cross-compiled.
Is this a known issue for GMP 4.2.2 on Linux? Is there anyway I can avoid it -- I would like to use the same version of GMP for all platforms if possible.
Cheers,
Kish
--- On Tue, 3/17/09, Sisyphus <sisyphus1 at optusnet.com.au> wrote:
From: Sisyphus <sisyphus1 at optusnet.com.au>
Subject: Re: mpq_get_d() rounding for different platforms?
To: "K Shen" <kishshen at yahoo.com>, gmp-discuss at gmplib.org
Date: Tuesday, March 17, 2009, 10:56 AM
----- Original Message ----- From: "K Shen"
<kishshen at yahoo.com>
> For example, for the rational 4/5,
>
> the MinGW version returns 0.79999999999999993, while the Linux version
> returns 0.80000000000000004.
Make sure that the assignment of 4/5 is being carried out in the same way.
As the following little program demonstrates, mpq_set_str(q, "4/5",
10) and mpq_set_d(q, (double) 4 / 5) assigm different values:
#############################
#include <stdio.h>
#include <gmp.h>
int main(void) {
mpq_t q1;
mpq_t q2;
mpq_init(q1);
mpq_init(q2);
mpq_set_str(q1, "4/5", 10);
mpq_set_d(q2, (double)4 / 5);
printf("%.17f\n", mpq_get_d(q1));
printf("%.17f\n", mpq_get_d(q2));
mpq_clear(q1);
mpq_clear(q2);
return 0;
}
#############################
For me (both Linux and MinGW) that outputs:
0.79999999999999993
0.80000000000000004
Cheers,
Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gmplib.org/list-archives/gmp-discuss/attachments/20090317/a4f1e211/attachment.html>
More information about the gmp-discuss
mailing list