mpf_set_d
Niels Möller
nisse at lysator.liu.se
Sat Nov 22 21:18:23 CET 2003
"Hee Jung Lee" <heejung73 at yahoo.com> writes:
> 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...
One way to think about this is to understand that you lose precision
when assigning the number to a double. Assigning it to a 400-precision
mpf after that won't recover the precision, because it's already been
lost.
I haven't read the source, but the natural way to implement mpf_set_d
is to construct a number with exactly the same exponent and (binary)
mantissa as the given double, and just pad out the mantissa with
(binary) zeroes.
To get what you want, it might work better to convert the two numbers
897959184 and 1000000000 to mpf (they can be represented exactly as
doubles, I think), and then divide using 400-bit precision.
/Niels
More information about the gmp-discuss
mailing list