]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - sysdeps/ieee754/ldbl-128/ldbl2mpn.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / ieee754 / ldbl-128 / ldbl2mpn.c
index 08a4c37a511a0f3ab3d1e018c1e19cf5fd7a261a..6d6ee2a5556b7834b6e2225a166f82ce78bbdc2e 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2014 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -12,9 +12,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include "gmp.h"
 #include "gmp-impl.h"
@@ -49,8 +48,8 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
 #elif BITS_PER_MP_LIMB == 64
   /* Hopefully the compiler will combine the two bitfield extracts
      and this composition into just the original quadword extract.  */
-  res_ptr[0] = ((unsigned long int) u.ieee.mantissa2 << 32) | u.ieee.mantissa3;
-  res_ptr[1] = ((unsigned long int) u.ieee.mantissa0 << 32) | u.ieee.mantissa1;
+  res_ptr[0] = ((mp_limb_t) u.ieee.mantissa2 << 32) | u.ieee.mantissa3;
+  res_ptr[1] = ((mp_limb_t) u.ieee.mantissa0 << 32) | u.ieee.mantissa1;
   #define N 2
 #else
   #error "mp_limb size " BITS_PER_MP_LIMB "not accounted for"
@@ -70,7 +69,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
       else
        {
           /* It is a denormal number, meaning it has no implicit leading
-            one bit, and its exponent is in fact the format minimum.  */
+            one bit, and its exponent is in fact the format minimum.  */
          int cnt;
 
 #if N == 2
@@ -102,7 +101,7 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
 #else
          int j, k, l;
 
-         for (j = N - 1; j > 0; j++)
+         for (j = N - 1; j > 0; j--)
            if (res_ptr[j] != 0)
              break;
 
@@ -112,26 +111,29 @@ __mpn_extract_long_double (mp_ptr res_ptr, mp_size_t size,
          if (cnt < 0)
            {
              cnt += BITS_PER_MP_LIMB;
-             l++;
+             l--;
            }
          if (!cnt)
            for (k = N - 1; k >= l; k--)
              res_ptr[k] = res_ptr[k-l];
          else
-           for (k = N - 1; k >= l; k--)
-             res_ptr[k] = res_ptr[k-l] << cnt
-                          | res_ptr[k-l-1] >> (BITS_PER_MP_LIMB - cnt);
-           res_ptr[k--] = res_ptr[0] << cnt;
+           {
+             for (k = N - 1; k > l; k--)
+               res_ptr[k] = res_ptr[k-l] << cnt
+                            | res_ptr[k-l-1] >> (BITS_PER_MP_LIMB - cnt);
+             res_ptr[k--] = res_ptr[0] << cnt;
+           }
 
          for (; k >= 0; k--)
            res_ptr[k] = 0;
-         *expt = LDBL_MIN_EXP - 1 - 3 * BITS_PER_MP_LIMB - cnt;
+         *expt = LDBL_MIN_EXP - 1 - l * BITS_PER_MP_LIMB - cnt;
 #endif
        }
     }
   else
     /* Add the implicit leading one bit for a normalized number.  */
-    res_ptr[N - 1] |= 1L << (LDBL_MANT_DIG - 1 - ((N - 1) * BITS_PER_MP_LIMB));
+    res_ptr[N - 1] |= (mp_limb_t) 1 << (LDBL_MANT_DIG - 1
+                                       - ((N - 1) * BITS_PER_MP_LIMB));
 
   return N;
 }