Question about creating and displaying mpf

Markus Törnqvist mjt at nysv.org
Tue Sep 14 19:53:20 CEST 2010


On Tue, Sep 14, 2010 at 07:56:40AM -0700, Case Vanhorsen wrote:
>[ gmpy is maintained independently from GMP so this discussion should
>probably continue off this list. ]

Well, sure, but that's only a small part of my problem.

>> When I print it out in C code, from the Python object, its printed as
>> mpf('1.67800000000000000002e0')
>> * Question one is: Why is that not the given value? Did it store
>> it badly, like a regular badly-rounded float, or is that representation only?
>It is stored as a binary floating point number.

How does that work?

I had very good accuracy in the preliminary tests, but that kind of a rounding
error came up just now. Accuracy also means lots of limbs to store zeros in before
the last odd rounding-error-like 2? :)

>>  gmp_printf("%f\n", (((PympfObject *)(foo))->f)); // prints out 0.000000
>I haven't tried this, but shouldn't that be "%F\n" ?

man 3 printf lists %f and %F as synonyms, except that C99's inf and NaN are
uppercase INF and NAN with %F, so no bonus.

Besides, it behaves as if the real value stored was, is, 0.

I made a demo case, no gmpy involved, the smallest I could come up with:
http://gmp.pastebin.com/PhCy1fuG

And a bit of a longer one:
http://gmp.pastebin.com/Y23W6rja

:(

Anyone able to reproduce those? On any version 4?

Thanks!

PS.
I can't access the original Debian box from home, but I have 4.3.2, ie.
Ubuntu's "2:4.3.2+dfsg-1ubuntu1"

-- 
mjt



More information about the gmp-discuss mailing list