mpf_set_d

Hee Jung Lee heejung73 at yahoo.com
Sat Nov 22 11:42:04 CET 2003


thx ilya, i just read your article & found it very interesting.
thank you for writing it.

i have an understanding of the fact that floating point
arithmatic is not exact.  i just expected mpf_set_d to at least
TRY to set my mpf_t number to be as "exact" as possible to
the precision that i set the mpf_t number to be.  in my
sample code, i set the default precision to be 400 bits.
that's a lot of significant digits.  & what i ended up w/
is an mpf_t number that's "exact" up to 16 digits, like double
precision.  so.. my question has to do w/ how mpf_set_d
works...



-----Original Message-----
From: gmp-discuss-bounces at swox.com [mailto:gmp-discuss-bounces at swox.com]On
Behalf Of Ilya A. Palopezhentsev
Sent: Saturday, November 22, 2003 7:18 AM
To: gmp-discuss at swox.com
Subject: (no subject)


>this is probably a really basic question.  but!
>when i use mpf_set_d(), how do i make sure that
>the copy is "exact"?  for example, suppose my double
>value is 0.897959184, i want my mpf_t to be
>0.897959184000000000000000000000 and NOT
>0.897959183999999965841709581582

I guess it's not possible at all. One shouldn't forget that mpf and mpfr are
_floating_point_ numbers and certain real numbers simply can't be
transferred to this format completely unchanged, this is connected with the
limits imposed by the limited precision of the digit grid of the number. I
suppose this is the case, i.e. when you write
double d = 0.897959184;
it ISN'T stored as 0.897959184, but as
0.8979591839999999
(double has only 15-16 valid digits). The rest of digits are _invalid_.
However, they are transferred to mpf number with correct ones as well.

Floating point numbers do influence various subtle errors, read my article
for further information:
http://www.cfxweb.net/modules.php?name=News&file=article&sid=1312&mode=&orde
r=0&thold=0
There I explain some bottlenecks of using floating point numbers, in popular
style.

By the way, advice to authors of GMP documentation: I feel it could be
useful to stress there that mpf and mpfr numbers aren't _exact_
representations of _real_ numbers, (as well as float and double in C),
because it seems there are people who don't understand it. If you wish, you
could even insert some excerpts from my article or give a link to it.

_______________________________________________
gmp-discuss mailing list
gmp-discuss at swox.com
https://gmplib.org/mailman/listinfo/gmp-discuss



More information about the gmp-discuss mailing list