mpf_set_d

delta trinity deltatrinity at hotmail.com
Sat Nov 22 20:34:27 CET 2003


Sorry, I just saw it :)

Ok, I think that this might be because of this:

When you assign the number to the double, you lose some precision already.  
printf round off the number when printing it, in this case, to 16 digits on 
the right-size of the decimal point.

When you print the mpf_t value, you specify 20 digits.  What's strange is 
why you get more than 20 digits!!  I would suggest reporting a bug about 
that!  The double that you assigned to mpf_t does not have 20 digits 
precision. So, you're seeing the 'lost precision' of the assignment to the 
double.

You should try to gmp_printf the mpf_t with 16 digits precision, as you do 
for the double.

The output should be the same.  If you see more than 16 digits on right of 
decimal point, then it's the same bug as above (doh!).


Eric

>From: "Hee Jung Lee" <heejung73 at yahoo.com>
>To: "delta trinity" <deltatrinity at hotmail.com>
>CC: <gmp-discuss at swox.com>
>Subject: RE: mpf_set_d
>Date: Sat, 22 Nov 2003 11:48:13 -0800
>
>
>if you take a look at my sample code, you'll see that i set the default
>precision to 400 bits BEFORE i initialized it.  so i expected mpf_set_d
>to set my mpf_t number to be the value of my double number & be as
>accurate as possible to 400 bits, filling in the additional bits
>(after the 64 bits of the double) with zeros.
>
>-hj
>
>-----Original Message-----
>From: gmp-discuss-bounces at swox.com
>[mailto:gmp-discuss-bounces at swox.com]On Behalf Of delta trinity
>Sent: Saturday, November 22, 2003 11:21 AM
>To: gmp-discuss at swox.com
>Subject: Re: mpf_set_d
>
>
>You can adjust the precision of the mpf structure.
>
>Either with mpf_set_default_prec, which set default precision for 
>subsequent
>mpf_init, or with mpf_set_prec, in which case you can change precision of a
>specific mpf_t variable.
>
>Note that if you already initialized and assigned a value to an mpf_t,
>increasing precision after that won't get you back the precision you lost
>during the assignment.  You need to re-assign your variable to it, or use
>mpf_set_default_prec before mpf_init.
>
>
>Eric
>
>
> >From: "Hee Jung Lee" <heejung73 at yahoo.com>
> >To: <gmp-discuss at swox.com>
> >Subject: mpf_set_d
> >Date: Fri, 21 Nov 2003 17:10:23 -0800
> >
> >
> >hi guys!
> >
> >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
> >
> >src
> >===
> >#include <stdio.h>
> >#include <stdlib.h>
> >#include "gmp.h"
> >
> >int main()
> >{
> >	double d;
> >	mpf_t m;
> >
> >	mpf_set_default_prec(400);
> >	d = 0.897959184;
> >	mpf_init(m);
> >	mpf_set_d(m,d);
> >	printf("\nd=%.16f", d);
> >	gmp_printf("\nm=%.*Ffd",20,m);
> >	mpf_clear(m);
> >}
> >
> >output
> >======
> >d=0.8979591840000000
> >m=0.897959183999999965841709581582d
> >_______________________________________________
> >gmp-discuss mailing list
> >gmp-discuss at swox.com
> >https://gmplib.org/mailman/listinfo/gmp-discuss
>
>_________________________________________________________________
>Set yourself up for fun at home!  Get tips on home entertainment equipment,
>video game reviews, and more here.
>http://special.msn.com/home/homeent.armx
>
>_______________________________________________
>gmp-discuss mailing list
>gmp-discuss at swox.com
>https://gmplib.org/mailman/listinfo/gmp-discuss
>

_________________________________________________________________
online games and music with a high-speed Internet connection!  Prices start 
at less than $1 a day average.  https://broadband.msn.com (Prices may vary 
by service area.)



More information about the gmp-discuss mailing list