]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / ieee754 / ldbl-128ibm / mpn2ldbl.c
index 532a119b7e9615834f742d1e9d0d32fc46fd9f23..42f5e6a02d4f58341ec91dc7f08ee8718cda68c9 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995-2014 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2016 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
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include "gmp.h"
-#include "gmp-impl.h"
 #include <ieee754.h>
+#include <errno.h>
 #include <float.h>
 #include <math.h>
 
+/* Need to set this when including gmp headers after system headers.  */
+#define HAVE_ALLOCA 1
+
+#include "gmp.h"
+#include "gmp-impl.h"
+
 /* Convert a multi-precision integer of the needed number of bits (106
    for long double) and an integral power of two to a `long double' in
    IBM extended format.  */
@@ -111,6 +116,14 @@ __mpn_construct_long_double (mp_srcptr frac_ptr, int expt, int sign)
            {
              hi >>= 1;
              u.d[0].ieee.exponent++;
+             if (u.d[0].ieee.exponent == IEEE754_DOUBLE_BIAS + DBL_MAX_EXP)
+               {
+                 /* Overflow.  The appropriate overflowed result must
+                    be produced (if an infinity, that means the low
+                    part must be zero).  */
+                 __set_errno (ERANGE);
+                 return (sign ? -LDBL_MAX : LDBL_MAX) * LDBL_MAX;
+               }
            }
          u.d[1].ieee.negative = !sign;
          lo = (1LL << 53) - lo;