best way to get mantissa from mpf_t

Paul Zimmermann Paul.Zimmermann at
Thu Dec 4 08:56:30 CET 2008


> From: "Rev. Chris Korda" <victimofleisure at>
> Date: Wed, 3 Dec 2008 19:21:50 -0500
> My friend and I are developing fixed-point functions to accelerate squaring
> and adding/subtracting for a fractal explorer. The explorer uses mpf_t for
> navigation, so we need to convert from mpf_t to fixed-point. We're currently
> obtaining the mantissa by using mpf_get_str to convert to a hex string, and
> then converting the hex into binary words. Is this a reasonable approach, or
> is there something better? Should we convert to mpn_t first? We also need to
> convert back the other way (from fixed-point to mpf_t) but we haven't
> started working on that yet.
> Best regards,
> Chris

your approach is not the best possible. In mpf, the significand is stored in
base W, where W is the base word (2^32 or 2^64). Thus the fixed-point is
directly available from the significand, which is an array of limbs.
For example, the number sqrt(2) might be stored on a 64-bit computer as two
limbs, the most significant limb being a[0]=1, and the least significant limb
being a[-1]=7640891576956012809. The corresponding value is sum(a[i]*W^i).
As a consequence, you can transform the significand into a fixed point value
by a simple shift (mpn_rshift) or even no operation at all if your "point"
corresponds to some W^k.

Paul Zimmermann

More information about the gmp-discuss mailing list