mpf_t and return values

Karl Hasselström kha@treskal.com
Tue, 29 Jul 2003 22:25:15 +0200


--0F1p//8PRICkK4MW
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2003-07-29 13:30:09 -0400, Aram Khalili wrote:

> I just downloaded and installed libgmp. I need to calculate
> factorials for fairly large number (up to 1000! maybe). I'm using
> Stirling's approximation for that, and a regular C double gives up
> at 171! . Does the mpf_t extend the exponent range of a double?

The manual says: "The exponent of each float is a fixed precision, one
machine word on most systems. In the current implementation the
exponent is a count of limbs, so for example on a 32-bit system this
means a range of roughly 2^-68719476768 to 2^68719476736, or on a
64-bit system this will be greater."

> Also, I have a few functions that I would like to return mpf_t's. I
> get casting warnings about that. I would also like to be able to use
> the function return value as an argument to another mpf_ function,
> but I get an error and warnings about that. Is it possible? If not,
> do I need to put everything into one function? Isn't mpf_t a
> pointer? Why isn't it treated as such?

Have a look in the manual, and do what GMPs mpf functions do: have the
caller supply one or more extra arguments to store the result(s) in.
Essentially, an mpf_t variable is a pointer to all the data
representing the number (but with a bit of black magic so that you
won't need all those &'s), so what you're really doing is passing each
function pointers to numbers it's supposed to read, and pointers to
memory where it's supposed to write the results.

Generally, I'd advise you to read the manual; it's quite informative,
and not that long if you just skip the parts you're not interested in.
:-)

--=20
Karl Hasselstr=F6m, kha@treskal.com
      www.treskal.com/kalle

--0F1p//8PRICkK4MW
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/JtgrN7iPzXSoOQoRAs6BAJ9/0luWjjTrJ4ltZs5zP358Ck7DGgCeIrix
hJj6qNA6bZPk6XhZEiaENfM=
=z6ir
-----END PGP SIGNATURE-----

--0F1p//8PRICkK4MW--