Mercurial > hg > CbC > CbC_gcc
comparison libquadmath/math/lrintq.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 { |
54 && x > (__float128) LONG_MAX) | 53 && x > (__float128) LONG_MAX) |
55 { | 54 { |
56 /* In the event of overflow we must raise the "invalid" | 55 /* In the event of overflow we must raise the "invalid" |
57 exception, but not "inexact". */ | 56 exception, but not "inexact". */ |
58 t = nearbyintq (x); | 57 t = nearbyintq (x); |
59 #ifdef USE_FENV_H | |
60 feraiseexcept (t == LONG_MAX ? FE_INEXACT : FE_INVALID); | 58 feraiseexcept (t == LONG_MAX ? FE_INEXACT : FE_INVALID); |
61 #endif | |
62 } | 59 } |
63 else | 60 else |
64 #endif | 61 #endif |
65 { | 62 { |
66 w = two112[sx] + x; | 63 w = two112[sx] + x; |
83 && x > (__float128) LONG_MAX) | 80 && x > (__float128) LONG_MAX) |
84 { | 81 { |
85 /* In the event of overflow we must raise the "invalid" | 82 /* In the event of overflow we must raise the "invalid" |
86 exception, but not "inexact". */ | 83 exception, but not "inexact". */ |
87 t = nearbyintq (x); | 84 t = nearbyintq (x); |
88 #ifdef USE_FENV_H | |
89 feraiseexcept (t == LONG_MAX ? FE_INEXACT : FE_INVALID); | 85 feraiseexcept (t == LONG_MAX ? FE_INEXACT : FE_INVALID); |
90 #endif | |
91 } | 86 } |
92 else | 87 else |
93 #endif | 88 #endif |
94 { | 89 { |
95 w = two112[sx] + x; | 90 w = two112[sx] + x; |
111 /* The number is too large. Unless it rounds to LONG_MIN, | 106 /* The number is too large. Unless it rounds to LONG_MIN, |
112 FE_INVALID must be raised and the return value is | 107 FE_INVALID must be raised and the return value is |
113 unspecified. */ | 108 unspecified. */ |
114 #if defined FE_INVALID || defined FE_INEXACT | 109 #if defined FE_INVALID || defined FE_INEXACT |
115 if (x < (__float128) LONG_MIN | 110 if (x < (__float128) LONG_MIN |
116 && x > (__float128) LONG_MIN - 1.0Q) | 111 && x > (__float128) LONG_MIN - 1) |
117 { | 112 { |
118 /* If truncation produces LONG_MIN, the cast will not raise | 113 /* If truncation produces LONG_MIN, the cast will not raise |
119 the exception, but may raise "inexact". */ | 114 the exception, but may raise "inexact". */ |
120 t = nearbyintq (x); | 115 t = nearbyintq (x); |
121 #ifdef USE_FENV_H | |
122 feraiseexcept (t == LONG_MIN ? FE_INEXACT : FE_INVALID); | 116 feraiseexcept (t == LONG_MIN ? FE_INEXACT : FE_INVALID); |
123 #endif | |
124 return LONG_MIN; | 117 return LONG_MIN; |
125 } | 118 } |
119 else if (FIX_FLT128_LONG_CONVERT_OVERFLOW && x != (__float128) LONG_MIN) | |
120 { | |
121 feraiseexcept (FE_INVALID); | |
122 return sx == 0 ? LONG_MAX : LONG_MIN; | |
123 } | |
124 | |
126 #endif | 125 #endif |
127 return (long int) x; | 126 return (long int) x; |
128 } | 127 } |
129 | 128 |
130 return sx ? -result : result; | 129 return sx ? -result : result; |