2 Copyright (C) 1997-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include "libm-test-driver.c"
21 static const struct test_f_L_data llround_test_data[] =
23 /* Bug 6797: errno setting may be missing. */
24 TEST_f_L (llround, plus_infty, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
25 TEST_f_L (llround, minus_infty, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
26 TEST_f_L (llround, qnan_value, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
27 TEST_f_L (llround, -qnan_value, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
28 TEST_f_L (llround, snan_value, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
29 TEST_f_L (llround, -snan_value, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
30 TEST_f_L (llround, max_value, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
31 TEST_f_L (llround, -max_value, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
32 TEST_f_L (llround, 0x1p31, 0x80000000LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
33 TEST_f_L (llround, 0x1p32, 0x100000000LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
34 TEST_f_L (llround, 0x1p33, 0x200000000LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
35 TEST_f_L (llround, 0x1p63, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
36 TEST_f_L (llround, 0x1p64, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
37 TEST_f_L (llround, 0x1p65, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
38 TEST_f_L (llround, -0x1p31, -0x80000000LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
39 TEST_f_L (llround, -0x1p32, -0x100000000LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
40 TEST_f_L (llround, -0x1p33, -0x200000000LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
41 TEST_f_L (llround, -0x1p63, LLONG_MIN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
42 TEST_f_L (llround, -0x1p64, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
43 TEST_f_L (llround, -0x1p65, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
44 TEST_f_L (llround, 0x7fffff80p0, 0x7fffff80LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
45 #if !TEST_COND_binary32
46 TEST_f_L (llround, 0x7fffffffp0, 0x7fffffffLL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
47 TEST_f_L (llround, 0x7fffffff.4p0, 0x7fffffffLL, ERRNO_UNCHANGED),
48 TEST_f_L (llround, 0x7fffffff.7ffffcp0, 0x7fffffffLL, ERRNO_UNCHANGED),
49 TEST_f_L (llround, 0x7fffffff.8p0, 0x80000000LL, ERRNO_UNCHANGED),
50 TEST_f_L (llround, 0x7fffffff.cp0, 0x80000000LL, ERRNO_UNCHANGED),
53 TEST_f_L (llround, 0x7fffffff.7fffffff8p0L, 0x7fffffffLL, ERRNO_UNCHANGED),
56 TEST_f_L (llround, 0x7fffffff.7fffffffffffffffffep0L, 0x7fffffffLL, ERRNO_UNCHANGED),
59 TEST_f_L (llround, 0x7fffffff.7fffffffffffffffffffcp0L, 0x7fffffffLL, ERRNO_UNCHANGED),
61 #if !TEST_COND_binary32
62 TEST_f_L (llround, -0x80000000.4p0, -0x80000000LL, ERRNO_UNCHANGED),
63 TEST_f_L (llround, -0x80000000.7ffff8p0, -0x80000000LL, ERRNO_UNCHANGED),
64 TEST_f_L (llround, -0x80000000.8p0, -0x80000001LL, ERRNO_UNCHANGED),
65 TEST_f_L (llround, -0x80000000.cp0, -0x80000001LL, ERRNO_UNCHANGED),
66 TEST_f_L (llround, -0x80000001p0, -0x80000001LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
68 TEST_f_L (llround, -0x80000100p0, -0x80000100LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
70 TEST_f_L (llround, -0x80000000.7fffffffp0L, -0x80000000LL, ERRNO_UNCHANGED),
73 TEST_f_L (llround, -0x80000000.7fffffffffffffffffcp0L, -0x80000000LL, ERRNO_UNCHANGED),
76 TEST_f_L (llround, -0x80000000.7fffffffffffffffffff8p0L, -0x80000000LL, ERRNO_UNCHANGED),
78 TEST_f_L (llround, 0x7fffff8000000000p0, 0x7fffff8000000000LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
79 #if !TEST_COND_binary32
80 TEST_f_L (llround, 0x7ffffffffffffc00p0, 0x7ffffffffffffc00LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
83 TEST_f_L (llround, 0x7fffffffffffffffp0L, 0x7fffffffffffffffLL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
84 TEST_f_L (llround, 0x7fffffffffffffff.8p0L, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
86 TEST_f_L (llround, 0x7fffffffffffffff.4p0L, 0x7fffffffffffffffLL, ERRNO_UNCHANGED),
87 TEST_f_L (llround, 0x7fffffffffffffff.cp0L, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
90 TEST_f_L (llround, 0x7fffffffffffffff.7fffffffffep0L, 0x7fffffffffffffffLL, ERRNO_UNCHANGED),
93 TEST_f_L (llround, 0x7fffffffffffffff.7fffffffffffcp0L, 0x7fffffffffffffffLL, ERRNO_UNCHANGED),
97 TEST_f_L (llround, -0x8000000000000001p0L, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
100 TEST_f_L (llround, -0x8000000000000000.4p0L, LLONG_MIN, ERRNO_UNCHANGED),
101 TEST_f_L (llround, -0x8000000000000000.7fffffffffcp0L, LLONG_MIN, ERRNO_UNCHANGED),
102 TEST_f_L (llround, -0x8000000000000000.8p0L, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
103 TEST_f_L (llround, -0x8000000000000000.cp0L, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
105 TEST_f_L (llround, -0x8000010000000000p0, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
106 #if !TEST_COND_binary32
107 TEST_f_L (llround, -0x8000000000000800p0, IGNORE, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION),
110 TEST_f_L (llround, -0x8000000000000000.7fffffffffff8p0L, LLONG_MIN, ERRNO_UNCHANGED),
112 TEST_f_L (llround, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
113 TEST_f_L (llround, minus_zero, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
114 TEST_f_L (llround, min_value, 0.0, ERRNO_UNCHANGED),
115 TEST_f_L (llround, -min_value, 0, ERRNO_UNCHANGED),
116 TEST_f_L (llround, min_subnorm_value, 0.0, ERRNO_UNCHANGED),
117 TEST_f_L (llround, -min_subnorm_value, 0, ERRNO_UNCHANGED),
118 TEST_f_L (llround, 0.2L, 0.0, ERRNO_UNCHANGED),
119 TEST_f_L (llround, -0.2L, 0, ERRNO_UNCHANGED),
120 TEST_f_L (llround, 0.5, 1, ERRNO_UNCHANGED),
121 TEST_f_L (llround, -0.5, -1, ERRNO_UNCHANGED),
122 TEST_f_L (llround, 0.8L, 1, ERRNO_UNCHANGED),
123 TEST_f_L (llround, -0.8L, -1, ERRNO_UNCHANGED),
124 TEST_f_L (llround, 1.5, 2, ERRNO_UNCHANGED),
125 TEST_f_L (llround, -1.5, -2, ERRNO_UNCHANGED),
126 TEST_f_L (llround, 22514.5, 22515, ERRNO_UNCHANGED),
127 TEST_f_L (llround, -22514.5, -22515, ERRNO_UNCHANGED),
128 TEST_f_L (llround, 1071930.0008, 1071930, ERRNO_UNCHANGED),
129 TEST_f_L (llround, 2097152.5, 2097153, ERRNO_UNCHANGED),
130 TEST_f_L (llround, -2097152.5, -2097153, ERRNO_UNCHANGED),
131 #if !TEST_COND_binary32
132 TEST_f_L (llround, 1073741824.01, 1073741824, ERRNO_UNCHANGED),
133 TEST_f_L (llround, 34359738368.5, 34359738369ll, ERRNO_UNCHANGED),
134 TEST_f_L (llround, -34359738368.5, -34359738369ll, ERRNO_UNCHANGED),
135 TEST_f_L (llround, -3.65309740835E17, -365309740835000000LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
136 TEST_f_L (llround, 281474976710656.025, 281474976710656, ERRNO_UNCHANGED),
137 TEST_f_L (llround, 18014398509481974, 18014398509481974, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
140 /* Test boundary conditions. */
142 TEST_f_L (llround, 2097151.0, 2097151LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
144 TEST_f_L (llround, 8388608.0, 8388608LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
146 TEST_f_L (llround, 16777216.0, 16777216LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
148 TEST_f_L (llround, 2199023255552.0, 2199023255552LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
150 TEST_f_L (llround, 4398046511104.0, 4398046511104LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
151 /* 0x1000000000000 */
152 TEST_f_L (llround, 281474976710656.0, 281474976710656LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
153 /* 0x10000000000000 */
154 TEST_f_L (llround, 4503599627370496.0, 4503599627370496LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
155 /* 0x10000080000000 */
156 TEST_f_L (llround, 4503601774854144.0, 4503601774854144LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
157 /* 0x20000000000000 */
158 TEST_f_L (llround, 9007199254740992.0, 9007199254740992LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
159 /* 0x80000000000000 */
160 TEST_f_L (llround, 36028797018963968.0, 36028797018963968LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
161 /* 0x100000000000000 */
162 TEST_f_L (llround, 72057594037927936.0, 72057594037927936LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
164 #if !TEST_COND_binary32
166 TEST_f_L (llround, 4294967295.5, 4294967296LL, ERRNO_UNCHANGED),
168 TEST_f_L (llround, 8589934591.5, 8589934592LL, ERRNO_UNCHANGED),
170 /* nextafter(0.5,-1) */
171 TEST_f_L (llround, 0x1.fffffffffffffp-2, 0, ERRNO_UNCHANGED),
172 /* nextafter(-0.5,1) */
173 TEST_f_L (llround, -0x1.fffffffffffffp-2, 0, ERRNO_UNCHANGED),
174 /* On PowerPC an exponent of '52' is the largest incrementally
175 * representable sequence of whole-numbers in the 'double' range. We test
176 * lround to make sure that a guard bit set during the lround operation
177 * hasn't forced an erroneous shift giving us an incorrect result. The odd
178 * numbers between +-(2^52+1 and 2^53-1) are affected since they have the
179 * rightmost bit set. */
181 TEST_f_L (llround, 0x1.0000000000001p+52, 4503599627370497LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
182 TEST_f_L (llround, -0x1.0000000000001p+52, -4503599627370497LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
183 /* +-(2^53-1): Input is the last (positive and negative) incrementally
184 * representable whole-number in the 'double' range that might round
186 TEST_f_L (llround, 0x1.fffffffffffffp+52, 9007199254740991LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
187 TEST_f_L (llround, -0x1.fffffffffffffp+52, -9007199254740991LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
189 TEST_f_L (llround, 0x1.fffffp-2, 0, ERRNO_UNCHANGED),
190 /* nextafter(0.5,-1) */
191 TEST_f_L (llround, 0x1.fffffep-2, 0, ERRNO_UNCHANGED),
192 TEST_f_L (llround, -0x1.fffffp-2, 0, ERRNO_UNCHANGED),
193 /* nextafter(-0.5,1) */
194 TEST_f_L (llround, -0x1.fffffep-2, 0, ERRNO_UNCHANGED),
195 TEST_f_L (llround, 0x1.fffffep+23, 16777215, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
196 TEST_f_L (llround, -0x1.fffffep+23, -16777215, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
197 /* As above, on PowerPC an exponent of '23' is the largest incrementally
198 * representable sequence of whole-numbers in the 'float' range.
199 * Likewise, numbers between +-(2^23+1 and 2^24-1) are affected. */
200 TEST_f_L (llround, 0x1.000002p+23, 8388609, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
201 TEST_f_L (llround, -0x1.000002p+23, -8388609, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
202 TEST_f_L (llround, 0x1.fffffep+23, 16777215, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
203 TEST_f_L (llround, -0x1.fffffep+23, -16777215, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
206 /* The input can only be represented in long double. */
207 TEST_f_L (llround, 4503599627370495.5L, 4503599627370496LL, ERRNO_UNCHANGED),
208 TEST_f_L (llround, 4503599627370496.25L, 4503599627370496LL, ERRNO_UNCHANGED),
209 TEST_f_L (llround, 4503599627370496.5L, 4503599627370497LL, ERRNO_UNCHANGED),
210 TEST_f_L (llround, 4503599627370496.75L, 4503599627370497LL, ERRNO_UNCHANGED),
211 TEST_f_L (llround, 4503599627370497.5L, 4503599627370498LL, ERRNO_UNCHANGED),
214 TEST_f_L (llround, 4503599627370495.4999999999999L, 4503599627370495LL, ERRNO_UNCHANGED),
215 TEST_f_L (llround, 4503599627370496.4999999999999L, 4503599627370496LL, ERRNO_UNCHANGED),
216 TEST_f_L (llround, 4503599627370497.4999999999999L, 4503599627370497LL, ERRNO_UNCHANGED),
217 TEST_f_L (llround, 4503599627370494.5000000000001L, 4503599627370495LL, ERRNO_UNCHANGED),
218 TEST_f_L (llround, 4503599627370495.5000000000001L, 4503599627370496LL, ERRNO_UNCHANGED),
219 TEST_f_L (llround, 4503599627370496.5000000000001L, 4503599627370497LL, ERRNO_UNCHANGED),
221 TEST_f_L (llround, -4503599627370495.4999999999999L, -4503599627370495LL, ERRNO_UNCHANGED),
222 TEST_f_L (llround, -4503599627370496.4999999999999L, -4503599627370496LL, ERRNO_UNCHANGED),
223 TEST_f_L (llround, -4503599627370497.4999999999999L, -4503599627370497LL, ERRNO_UNCHANGED),
224 TEST_f_L (llround, -4503599627370494.5000000000001L, -4503599627370495LL, ERRNO_UNCHANGED),
225 TEST_f_L (llround, -4503599627370495.5000000000001L, -4503599627370496LL, ERRNO_UNCHANGED),
226 TEST_f_L (llround, -4503599627370496.5000000000001L, -4503599627370497LL, ERRNO_UNCHANGED),
229 TEST_f_L (llround, -4503599627370495.5L, -4503599627370496LL, ERRNO_UNCHANGED),
230 TEST_f_L (llround, -4503599627370496.25L, -4503599627370496LL, ERRNO_UNCHANGED),
231 TEST_f_L (llround, -4503599627370496.5L, -4503599627370497LL, ERRNO_UNCHANGED),
232 TEST_f_L (llround, -4503599627370496.75L, -4503599627370497LL, ERRNO_UNCHANGED),
233 TEST_f_L (llround, -4503599627370497.5L, -4503599627370498LL, ERRNO_UNCHANGED),
235 TEST_f_L (llround, 9007199254740991.5L, 9007199254740992LL, ERRNO_UNCHANGED),
236 TEST_f_L (llround, 9007199254740992.25L, 9007199254740992LL, ERRNO_UNCHANGED),
237 TEST_f_L (llround, 9007199254740992.5L, 9007199254740993LL, ERRNO_UNCHANGED),
238 TEST_f_L (llround, 9007199254740992.75L, 9007199254740993LL, ERRNO_UNCHANGED),
239 TEST_f_L (llround, 9007199254740993.5L, 9007199254740994LL, ERRNO_UNCHANGED),
242 TEST_f_L (llround, 9007199254740991.4999999999999L, 9007199254740991LL, ERRNO_UNCHANGED),
243 TEST_f_L (llround, 9007199254740992.4999999999999L, 9007199254740992LL, ERRNO_UNCHANGED),
244 TEST_f_L (llround, 9007199254740993.4999999999999L, 9007199254740993LL, ERRNO_UNCHANGED),
245 TEST_f_L (llround, 9007199254740991.5000000000001L, 9007199254740992LL, ERRNO_UNCHANGED),
246 TEST_f_L (llround, 9007199254740992.5000000000001L, 9007199254740993LL, ERRNO_UNCHANGED),
247 TEST_f_L (llround, 9007199254740993.5000000000001L, 9007199254740994LL, ERRNO_UNCHANGED),
249 TEST_f_L (llround, -9007199254740991.4999999999999L, -9007199254740991LL, ERRNO_UNCHANGED),
250 TEST_f_L (llround, -9007199254740992.4999999999999L, -9007199254740992LL, ERRNO_UNCHANGED),
251 TEST_f_L (llround, -9007199254740993.4999999999999L, -9007199254740993LL, ERRNO_UNCHANGED),
252 TEST_f_L (llround, -9007199254740991.5000000000001L, -9007199254740992LL, ERRNO_UNCHANGED),
253 TEST_f_L (llround, -9007199254740992.5000000000001L, -9007199254740993LL, ERRNO_UNCHANGED),
254 TEST_f_L (llround, -9007199254740993.5000000000001L, -9007199254740994LL, ERRNO_UNCHANGED),
257 TEST_f_L (llround, -9007199254740991.5L, -9007199254740992LL, ERRNO_UNCHANGED),
258 TEST_f_L (llround, -9007199254740992.25L, -9007199254740992LL, ERRNO_UNCHANGED),
259 TEST_f_L (llround, -9007199254740992.5L, -9007199254740993LL, ERRNO_UNCHANGED),
260 TEST_f_L (llround, -9007199254740992.75L, -9007199254740993LL, ERRNO_UNCHANGED),
261 TEST_f_L (llround, -9007199254740993.5L, -9007199254740994LL, ERRNO_UNCHANGED),
263 TEST_f_L (llround, 72057594037927935.5L, 72057594037927936LL, ERRNO_UNCHANGED),
264 TEST_f_L (llround, 72057594037927936.25L, 72057594037927936LL, ERRNO_UNCHANGED),
265 TEST_f_L (llround, 72057594037927936.5L, 72057594037927937LL, ERRNO_UNCHANGED),
266 TEST_f_L (llround, 72057594037927936.75L, 72057594037927937LL, ERRNO_UNCHANGED),
267 TEST_f_L (llround, 72057594037927937.5L, 72057594037927938LL, ERRNO_UNCHANGED),
269 TEST_f_L (llround, -72057594037927935.5L, -72057594037927936LL, ERRNO_UNCHANGED),
270 TEST_f_L (llround, -72057594037927936.25L, -72057594037927936LL, ERRNO_UNCHANGED),
271 TEST_f_L (llround, -72057594037927936.5L, -72057594037927937LL, ERRNO_UNCHANGED),
272 TEST_f_L (llround, -72057594037927936.75L, -72057594037927937LL, ERRNO_UNCHANGED),
273 TEST_f_L (llround, -72057594037927937.5L, -72057594037927938LL, ERRNO_UNCHANGED),
275 TEST_f_L (llround, 9223372036854775806.25L, 9223372036854775806LL, ERRNO_UNCHANGED),
276 TEST_f_L (llround, -9223372036854775806.25L, -9223372036854775806LL, ERRNO_UNCHANGED),
277 TEST_f_L (llround, 9223372036854775806.5L, 9223372036854775807LL, ERRNO_UNCHANGED),
278 TEST_f_L (llround, -9223372036854775806.5L, -9223372036854775807LL, ERRNO_UNCHANGED),
279 TEST_f_L (llround, 9223372036854775807.0L, 9223372036854775807LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
280 TEST_f_L (llround, -9223372036854775807.0L, -9223372036854775807LL, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
287 ALL_RM_TEST (llround, 1, llround_test_data, RUN_TEST_LOOP_f_L, END);