mpf_set_d

Hee Jung Lee heejung73 at yahoo.com
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.

-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



More information about the gmp-discuss mailing list