0.7 / 1.0 ?= 0.52
Hans Aberg
haberg-1 at telia.com
Fri Jun 15 15:31:42 CEST 2012
On 15 Jun 2012, at 15:07, Torbjorn Granlund wrote:
> Hans Aberg <haberg-1 at telia.com> writes:
>
>> The division produce a funny bug. What do you think?
>>
>> mpf_t a;
>> mpf_init(a);
>> mpf_set_d(a, 0.7);
>> mpf_t b;
>> mpf_init(b);
>> mpf_set_d(b, 1.0);
>> mpf_t l;
>> mpf_init(l);
>>
>> gmp_printf ("%.*Ff \n", 5, a); --- 0.70000
>> gmp_printf ("%.*Ff \n", 5, b); --- 1.00000
>>
>> mpf_div(l, a, b);
>> gmp_printf ("%.*Ff", 5, l); --- 0.52502
>
> This example works on Mac OS X 10.7.4 with GMP 5.0.4 compiled directly
> from source, using the llvm-gcc 4.2.1 you indicate, and the example
> compiled using this compiler, clang 3.1 also from Xcode 4.3.2, and gcc
> 4.7.0 compiled from source using this llvm-gcc.
>
> If llvm-gcc compiles that code, it is more broken than I could ever have
> imagined; I knew its code generator and optimiser were badly broken, but
> now its parser thinks the above code is valid C…!
I had to wrap it into a function, and change the Haskell style '--' comments into C/C++ style (see below). Then just use any of the compilers mentioned above.
Hans
---- divide-test.c ----
#include <gmp.h>
int main() {
mpf_t a;
mpf_init(a);
mpf_set_d(a, 0.7);
mpf_t b;
mpf_init(b);
mpf_set_d(b, 1.0);
mpf_t l;
mpf_init(l);
gmp_printf("%.*Ff \n", 5, a); // Prints 0.70000
gmp_printf ("%.*Ff \n", 5, b); // Prints 1.00000
mpf_div(l, a, b);
gmp_printf ("%.*Ff", 5, l); // Prints 0.70000
return 0;
}
----
More information about the gmp-bugs
mailing list