diff options
Diffstat (limited to 'sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c')
-rw-r--r-- | sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c b/sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c index bacb2cc98b..42f5e6a02d 100644 --- a/sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c +++ b/sysdeps/ieee754/ldbl-128ibm/mpn2ldbl.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2015 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 @@ -15,12 +15,17 @@ 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; |