-/* 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. */
{
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;