summaryrefslogtreecommitdiff
path: root/libquadmath/math/llroundq.c
diff options
context:
space:
mode:
Diffstat (limited to 'libquadmath/math/llroundq.c')
-rw-r--r--libquadmath/math/llroundq.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/libquadmath/math/llroundq.c b/libquadmath/math/llroundq.c
index 098fb9ef72b..f22ad5a56c4 100644
--- a/libquadmath/math/llroundq.c
+++ b/libquadmath/math/llroundq.c
@@ -1,5 +1,5 @@
-/* Round __float128 value to long long int.
- Copyright (C) 1997-2017 Free Software Foundation, Inc.
+/* Round long double value to long long int.
+ Copyright (C) 1997-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997 and
Jakub Jelinek <jj@ultra.linux.cz>, 1999.
@@ -15,13 +15,11 @@
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 "quadmath-imp.h"
-
long long int
llroundq (__float128 x)
{
@@ -61,7 +59,7 @@ llroundq (__float128 x)
else
{
result = ((long long int) i0 << (j0 - 48)) | (j >> (112 - j0));
-#if defined FE_INVALID && defined USE_FENV_H
+#ifdef FE_INVALID
if (sign == 1 && result == LLONG_MIN)
/* Rounding brought the value out of range. */
feraiseexcept (FE_INVALID);
@@ -75,13 +73,18 @@ llroundq (__float128 x)
FE_INVALID must be raised and the return value is
unspecified. */
#ifdef FE_INVALID
- if (x <= (__float128) LLONG_MIN - 0.5Q)
+ if (FIX_FLT128_LLONG_CONVERT_OVERFLOW
+ && !(sign == -1 && x > (__float128) LLONG_MIN - 0.5Q))
+ {
+ feraiseexcept (FE_INVALID);
+ return sign == 1 ? LLONG_MAX : LLONG_MIN;
+ }
+ else if (!FIX_FLT128_LLONG_CONVERT_OVERFLOW
+ && x <= (__float128) LLONG_MIN - 0.5Q)
{
/* If truncation produces LLONG_MIN, the cast will not raise
the exception, but may raise "inexact". */
-#ifdef USE_FENV_H
feraiseexcept (FE_INVALID);
-#endif
return LLONG_MIN;
}
#endif