Float assignment and conversion to float

Sisyphus sisyphus1 at optusnet.com.au
Wed Mar 8 06:52:51 CET 2006


----- Original Message ----- 
From: "Gilles Rayrat" <gilles.rayrat at continuent.com>
To: <gmp-discuss at swox.com>
Sent: Wednesday, March 08, 2006 5:09 AM
Subject: Float assignment and conversion to float


> Hi all,
> First of all I want to say that this lib is just great. Good doc, good
> api, "bravo" !
>
> But I have two questions about mpfs: I have a mantissa 'm' and a scale
> 's', both mpz.  and I want to create a mpf_t 'f' from these like
> f=m/pow(10,s)
> Is there a simple way to do that ?

Not sure that I follow. If m = 123456781, and s = 6, then what is the value
of f ? I was thinking the answer would be 123.456781(ie m / 10^s), in which
case I might assign as mpfr_set_str(f, num, 10) - where 'num' is a char*
that contains the string '123456781 at -6' . I can't think of a really simple
way - but then I haven't given it a lot of thought as I'm not sure that I've
understood your requirements correctly. (Is 's' *really* that big that it
can't fit into a long ?)

> 2nd question, from this mpf_t, I'd like to have it converted to a float
> C type. I've seen the get_d() function, but nothing for floats. Any idea

Just assign the return of get_d() to a float.

Cheers,
Rob



More information about the gmp-discuss mailing list