Back to index

glibc  2.9
Functions
mpn2dbl.c File Reference
#include "gmp.h"
#include "gmp-impl.h"
#include <ieee754.h>
#include <float.h>

Go to the source code of this file.

Functions

double __mpn_construct_double (mp_srcptr frac_ptr, int expt, int negative)

Function Documentation

double __mpn_construct_double ( mp_srcptr  frac_ptr,
int  expt,
int  negative 
)

Definition at line 29 of file mpn2dbl.c.

{
  union ieee754_double u;

  u.ieee.negative = negative;
  u.ieee.exponent = expt + IEEE754_DOUBLE_BIAS;
#if BITS_PER_MP_LIMB == 32
  u.ieee.mantissa1 = frac_ptr[0];
  u.ieee.mantissa0 = frac_ptr[1] & (((mp_limb_t) 1
                                 << (DBL_MANT_DIG - 32)) - 1);
#elif BITS_PER_MP_LIMB == 64
  u.ieee.mantissa1 = frac_ptr[0] & (((mp_limb_t) 1 << 32) - 1);
  u.ieee.mantissa0 = (frac_ptr[0] >> 32) & (((mp_limb_t) 1
                                        << (DBL_MANT_DIG - 32)) - 1);
#else
  #error "mp_limb size " BITS_PER_MP_LIMB "not accounted for"
#endif

  return u.d;
}