[BACK]Return to get_d.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpz

Diff for /OpenXM_contrib/gmp/mpz/Attic/get_d.c between version 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2000/09/09 14:12:52 version 1.1.1.3, 2003/08/25 16:06:33
Line 1 
Line 1 
 /* double mpz_get_d (mpz_t src) -- Return the double approximation to SRC.  /* double mpz_get_d (mpz_t src) -- Return the double approximation to SRC.
   
 Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.  Copyright 1996, 1997, 2000, 2001, 2002 Free Software Foundation, Inc.
   
 This file is part of the GNU MP Library.  This file is part of the GNU MP Library.
   
Line 24  MA 02111-1307, USA. */
Line 24  MA 02111-1307, USA. */
 #include "longlong.h"  #include "longlong.h"
   
   
 static int  /* FIXME: Would prefer to inline this on all compilers, not just those with
 #if __STDC__     "inline".  */
 mpn_zero_p (mp_ptr p, mp_size_t n)  static inline int
 #else  mpn_zero_p (mp_srcptr p, mp_size_t n)
 mpn_zero_p (p, n)  
      mp_ptr p;  
      mp_size_t n;  
 #endif  
 {  {
   mp_size_t i;    mp_size_t i;
   
   for (i = 0; i < n; i++)    for (i = 0; i < n; i++)
     {      if (p[i] != 0)
       if (p[i] != 0)        return 0;
         return 0;  
     }  
   
   return 1;    return 1;
 }  }
   
   
 double  double
 #if __STDC__  
 mpz_get_d (mpz_srcptr src)  mpz_get_d (mpz_srcptr src)
 #else  
 mpz_get_d (src)  
      mpz_srcptr src;  
 #endif  
 {  {
   double res;    double res;
   mp_size_t size;    mp_size_t size;
Line 79  mpz_get_d (src)
Line 68  mpz_get_d (src)
   else    else
     {      {
       count_leading_zeros (cnt, qp[size - 1]);        count_leading_zeros (cnt, qp[size - 1]);
         cnt -= GMP_NAIL_BITS;
   
 #if BITS_PER_MP_LIMB == 32  #if BITS_PER_MP_LIMB == 32
       if (cnt == 0)        if (cnt == 0)
Line 88  mpz_get_d (src)
Line 78  mpz_get_d (src)
         }          }
       else        else
         {          {
           hz = (qp[size - 1] << cnt) | (qp[size - 2] >> BITS_PER_MP_LIMB - cnt);            hz = ((qp[size - 1] << cnt) | (qp[size - 2] >> GMP_NUMB_BITS - cnt)) & GMP_NUMB_MASK;
           lz = (qp[size - 2] << cnt) | (qp[size - 3] >> BITS_PER_MP_LIMB - cnt);            lz = ((qp[size - 2] << cnt) | (qp[size - 3] >> GMP_NUMB_BITS - cnt)) & GMP_NUMB_MASK;
         }          }
 #if _GMP_IEEE_FLOATS  #if _GMP_IEEE_FLOATS
       /* Take bits from less significant limbs, but only if they may affect        /* Take bits from less significant limbs, but only if they may affect
Line 97  mpz_get_d (src)
Line 87  mpz_get_d (src)
       if ((lz & 0x7ff) == 0x400)        if ((lz & 0x7ff) == 0x400)
         {          {
           if (cnt != 0)            if (cnt != 0)
             lz += ((qp[size - 3] << cnt) != 0 || ! mpn_zero_p (qp, size - 3));              lz += (((qp[size - 3] << cnt) & GMP_NUMB_MASK) != 0
                      || ! mpn_zero_p (qp, size - 3));
           else            else
             lz += (! mpn_zero_p (qp, size - 2));              lz += (! mpn_zero_p (qp, size - 2));
         }          }
 #endif  #endif
       res = MP_BASE_AS_DOUBLE * hz + lz;        res = MP_BASE_AS_DOUBLE * hz + lz;
       res = __gmp_scale2 (res, (size - 2) * BITS_PER_MP_LIMB - cnt);        res = __gmp_scale2 (res, (size - 2) * GMP_NUMB_BITS - cnt);
 #endif  #endif
 #if BITS_PER_MP_LIMB == 64  #if BITS_PER_MP_LIMB == 64
       if (cnt == 0)        if (cnt == 0)
         hz = qp[size - 1];          hz = qp[size - 1];
       else        else
         hz = (qp[size - 1] << cnt) | (qp[size - 2] >> BITS_PER_MP_LIMB - cnt);          hz = ((qp[size - 1] << cnt) | (qp[size - 2] >> GMP_NUMB_BITS - cnt)) & GMP_NUMB_MASK;
 #if _GMP_IEEE_FLOATS  #if _GMP_IEEE_FLOATS
       if ((hz & 0x7ff) == 0x400)        if ((hz & 0x7ff) == 0x400)
         {          {
           if (cnt != 0)            if (cnt != 0)
             hz += ((qp[size - 2] << cnt) != 0 || ! mpn_zero_p (qp, size - 2));              hz += (((qp[size - 2] << cnt) & GMP_NUMB_MASK) != 0
                      || ! mpn_zero_p (qp, size - 2));
           else            else
             hz += (! mpn_zero_p (qp, size - 1));              hz += (! mpn_zero_p (qp, size - 1));
         }          }
 #endif  #endif
       res = hz;        res = hz;
       res = __gmp_scale2 (res, (size - 1) * BITS_PER_MP_LIMB - cnt);        res = __gmp_scale2 (res, (size - 1) * GMP_NUMB_BITS - cnt);
 #endif  #endif
     }      }
   

Legend:
Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>