Hee Jung Lee heejung73 at
Sat Nov 22 11:48:13 CET 2003

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.


-----Original Message-----
From: gmp-discuss-bounces at
[mailto:gmp-discuss-bounces at]On Behalf Of delta trinity
Sent: Saturday, November 22, 2003 11:21 AM
To: gmp-discuss at
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.


>From: "Hee Jung Lee" <heejung73 at>
>To: <gmp-discuss at>
>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
>#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);
>gmp-discuss mailing list
>gmp-discuss at

Set yourself up for fun at home!  Get tips on home entertainment equipment,
video game reviews, and more here.

gmp-discuss mailing list
gmp-discuss at

More information about the gmp-discuss mailing list