Mercurial > hg > CbC > CbC_gcc
comparison libquadmath/math/llrintq.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 argument to nearest integral value according to current rounding | 1 /* Round argument to nearest integral value according to current rounding |
2 direction. | 2 direction. |
3 Copyright (C) 1997-2017 Free Software Foundation, Inc. | 3 Copyright (C) 1997-2018 Free Software Foundation, Inc. |
4 This file is part of the GNU C Library. | 4 This file is part of the GNU C Library. |
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997 and | 5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997 and |
6 Jakub Jelinek <jj@ultra.linux.cz>, 1999. | 6 Jakub Jelinek <jj@ultra.linux.cz>, 1999. |
7 | 7 |
8 The GNU C Library is free software; you can redistribute it and/or | 8 The GNU C Library is free software; you can redistribute it and/or |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 Lesser General Public License for more details. | 16 Lesser General Public License for more details. |
17 | 17 |
18 You should have received a copy of the GNU Lesser General Public | 18 You should have received a copy of the GNU Lesser General Public |
19 License along with the GNU C Library; if not, write to the Free | 19 License along with the GNU C Library; if not, see |
20 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | 20 <http://www.gnu.org/licenses/>. */ |
21 02111-1307 USA. */ | |
22 | 21 |
23 #include "quadmath-imp.h" | 22 #include "quadmath-imp.h" |
24 | 23 |
25 static const __float128 two112[2] = | 24 static const __float128 two112[2] = |
26 { | 25 { |
51 if (x > (__float128) LLONG_MAX) | 50 if (x > (__float128) LLONG_MAX) |
52 { | 51 { |
53 /* In the event of overflow we must raise the "invalid" | 52 /* In the event of overflow we must raise the "invalid" |
54 exception, but not "inexact". */ | 53 exception, but not "inexact". */ |
55 t = nearbyintq (x); | 54 t = nearbyintq (x); |
56 #ifdef USE_FENV_H | |
57 feraiseexcept (t == LLONG_MAX ? FE_INEXACT : FE_INVALID); | 55 feraiseexcept (t == LLONG_MAX ? FE_INEXACT : FE_INVALID); |
58 #endif | |
59 } | 56 } |
60 else | 57 else |
61 #endif | 58 #endif |
62 { | 59 { |
63 w = two112[sx] + x; | 60 w = two112[sx] + x; |
80 /* The number is too large. Unless it rounds to LLONG_MIN, | 77 /* The number is too large. Unless it rounds to LLONG_MIN, |
81 FE_INVALID must be raised and the return value is | 78 FE_INVALID must be raised and the return value is |
82 unspecified. */ | 79 unspecified. */ |
83 #if defined FE_INVALID || defined FE_INEXACT | 80 #if defined FE_INVALID || defined FE_INEXACT |
84 if (x < (__float128) LLONG_MIN | 81 if (x < (__float128) LLONG_MIN |
85 && x > (__float128) LLONG_MIN - 1.0Q) | 82 && x > (__float128) LLONG_MIN - 1) |
86 { | 83 { |
87 /* If truncation produces LLONG_MIN, the cast will not raise | 84 /* If truncation produces LLONG_MIN, the cast will not raise |
88 the exception, but may raise "inexact". */ | 85 the exception, but may raise "inexact". */ |
89 t = nearbyintq (x); | 86 t = nearbyintq (x); |
90 #ifdef USE_FENV_H | |
91 feraiseexcept (t == LLONG_MIN ? FE_INEXACT : FE_INVALID); | 87 feraiseexcept (t == LLONG_MIN ? FE_INEXACT : FE_INVALID); |
92 #endif | |
93 return LLONG_MIN; | 88 return LLONG_MIN; |
89 } | |
90 else if (FIX_FLT128_LLONG_CONVERT_OVERFLOW && x != (__float128) LLONG_MIN) | |
91 { | |
92 feraiseexcept (FE_INVALID); | |
93 return sx == 0 ? LLONG_MAX : LLONG_MIN; | |
94 } | 94 } |
95 | 95 |
96 #endif | 96 #endif |
97 | |
98 /* The number is too large. It is left implementation defined | |
99 what happens. */ | |
100 return (long long int) x; | 97 return (long long int) x; |
101 } | 98 } |
102 | 99 |
103 return sx ? -result : result; | 100 return sx ? -result : result; |
104 } | 101 } |