comparison libquadmath/math/llroundq.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Round __float128 value to long long int. 1 /* Round long double value to long long int.
2 Copyright (C) 1997-2017 Free Software Foundation, Inc. 2 Copyright (C) 1997-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library. 3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997 and 4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997 and
5 Jakub Jelinek <jj@ultra.linux.cz>, 1999. 5 Jakub Jelinek <jj@ultra.linux.cz>, 1999.
6 6
7 The GNU C Library is free software; you can redistribute it and/or 7 The GNU C Library is free software; you can redistribute it and/or
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details. 15 Lesser General Public License for more details.
16 16
17 You should have received a copy of the GNU Lesser General Public 17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free 18 License along with the GNU C Library; if not, see
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19 <http://www.gnu.org/licenses/>. */
20 02111-1307 USA. */
21 20
22 #include "quadmath-imp.h" 21 #include "quadmath-imp.h"
23
24 22
25 long long int 23 long long int
26 llroundq (__float128 x) 24 llroundq (__float128 x)
27 { 25 {
28 int64_t j0; 26 int64_t j0;
59 if (j0 == 48) 57 if (j0 == 48)
60 result = (long long int) i0; 58 result = (long long int) i0;
61 else 59 else
62 { 60 {
63 result = ((long long int) i0 << (j0 - 48)) | (j >> (112 - j0)); 61 result = ((long long int) i0 << (j0 - 48)) | (j >> (112 - j0));
64 #if defined FE_INVALID && defined USE_FENV_H 62 #ifdef FE_INVALID
65 if (sign == 1 && result == LLONG_MIN) 63 if (sign == 1 && result == LLONG_MIN)
66 /* Rounding brought the value out of range. */ 64 /* Rounding brought the value out of range. */
67 feraiseexcept (FE_INVALID); 65 feraiseexcept (FE_INVALID);
68 #endif 66 #endif
69 } 67 }
73 { 71 {
74 /* The number is too large. Unless it rounds to LLONG_MIN, 72 /* The number is too large. Unless it rounds to LLONG_MIN,
75 FE_INVALID must be raised and the return value is 73 FE_INVALID must be raised and the return value is
76 unspecified. */ 74 unspecified. */
77 #ifdef FE_INVALID 75 #ifdef FE_INVALID
78 if (x <= (__float128) LLONG_MIN - 0.5Q) 76 if (FIX_FLT128_LLONG_CONVERT_OVERFLOW
77 && !(sign == -1 && x > (__float128) LLONG_MIN - 0.5Q))
78 {
79 feraiseexcept (FE_INVALID);
80 return sign == 1 ? LLONG_MAX : LLONG_MIN;
81 }
82 else if (!FIX_FLT128_LLONG_CONVERT_OVERFLOW
83 && x <= (__float128) LLONG_MIN - 0.5Q)
79 { 84 {
80 /* If truncation produces LLONG_MIN, the cast will not raise 85 /* If truncation produces LLONG_MIN, the cast will not raise
81 the exception, but may raise "inexact". */ 86 the exception, but may raise "inexact". */
82 #ifdef USE_FENV_H
83 feraiseexcept (FE_INVALID); 87 feraiseexcept (FE_INVALID);
84 #endif
85 return LLONG_MIN; 88 return LLONG_MIN;
86 } 89 }
87 #endif 90 #endif
88 return (long long int) x; 91 return (long long int) x;
89 } 92 }