Add further _BitInt <-> floating point tests [PR102989]
[official-gcc.git] / gcc / testsuite / gcc.dg / bitint-29.c
blobb6a88567c8c916586ace6954d5a04cec03d5f87c
1 /* PR c/102989 */
2 /* { dg-do run } */
3 /* { dg-require-effective-target fenv_exceptions } */
4 /* { dg-options "-std=c2x" } */
5 /* { dg-add-options ieee } */
7 #include <fenv.h>
9 #if __FLT_MANT_DIG__ == 24
10 #if __BITINT_MAXWIDTH__ >= 135
11 __attribute__((noipa)) _BitInt(135)
12 testflt_135 (float d)
14 return d;
17 __attribute__((noipa)) unsigned _BitInt(135)
18 testfltu_135 (float d)
20 return d;
22 #endif
24 #if __BITINT_MAXWIDTH__ >= 192
25 __attribute__((noipa)) _BitInt(192)
26 testflt_192 (float d)
28 return d;
31 __attribute__((noipa)) unsigned _BitInt(192)
32 testfltu_192 (float d)
34 return d;
36 #endif
38 #if __BITINT_MAXWIDTH__ >= 575
39 __attribute__((noipa)) _BitInt(575)
40 testflt_575 (float d)
42 return d;
45 __attribute__((noipa)) unsigned _BitInt(575)
46 testfltu_575 (float d)
48 return d;
50 #endif
51 #endif
53 #if __DBL_MANT_DIG__ == 53
54 #if __BITINT_MAXWIDTH__ >= 135
55 __attribute__((noipa)) _BitInt(135)
56 testdbl_135 (double d)
58 return d;
61 __attribute__((noipa)) unsigned _BitInt(135)
62 testdblu_135 (double d)
64 return d;
66 #endif
68 #if __BITINT_MAXWIDTH__ >= 192
69 __attribute__((noipa)) _BitInt(192)
70 testdbl_192 (double d)
72 return d;
75 __attribute__((noipa)) unsigned _BitInt(192)
76 testdblu_192 (double d)
78 return d;
80 #endif
82 #if __BITINT_MAXWIDTH__ >= 575
83 __attribute__((noipa)) _BitInt(575)
84 testdbl_575 (double d)
86 return d;
89 __attribute__((noipa)) unsigned _BitInt(575)
90 testdblu_575 (double d)
92 return d;
94 #endif
95 #endif
97 #if __LDBL_MANT_DIG__ == 64
98 #if __BITINT_MAXWIDTH__ >= 135
99 __attribute__((noipa)) _BitInt(135)
100 testldbl_135 (long double d)
102 return d;
105 __attribute__((noipa)) unsigned _BitInt(135)
106 testldblu_135 (long double d)
108 return d;
110 #endif
112 #if __BITINT_MAXWIDTH__ >= 192
113 __attribute__((noipa)) _BitInt(192)
114 testldbl_192 (long double d)
116 return d;
119 __attribute__((noipa)) unsigned _BitInt(192)
120 testldblu_192 (long double d)
122 return d;
124 #endif
126 #if __BITINT_MAXWIDTH__ >= 575
127 __attribute__((noipa)) _BitInt(575)
128 testldbl_575 (long double d)
130 return d;
133 __attribute__((noipa)) unsigned _BitInt(575)
134 testldblu_575 (long double d)
136 return d;
138 #endif
139 #endif
141 #if __FLT128_MANT_DIG__ == 113
142 #if __BITINT_MAXWIDTH__ >= 135
143 __attribute__((noipa)) _BitInt(135)
144 testflt128_135 (_Float128 d)
146 return d;
149 __attribute__((noipa)) unsigned _BitInt(135)
150 testflt128u_135 (_Float128 d)
152 return d;
154 #endif
156 #if __BITINT_MAXWIDTH__ >= 192
157 __attribute__((noipa)) _BitInt(192)
158 testflt128_192 (_Float128 d)
160 return d;
163 __attribute__((noipa)) unsigned _BitInt(192)
164 testflt128u_192 (_Float128 d)
166 return d;
168 #endif
170 #if __BITINT_MAXWIDTH__ >= 575
171 __attribute__((noipa)) _BitInt(575)
172 testflt128_575 (_Float128 d)
174 return d;
177 __attribute__((noipa)) unsigned _BitInt(575)
178 testflt128u_575 (_Float128 d)
180 return d;
182 #endif
183 #endif
185 __attribute__((noipa)) void
186 check_inexact (int test, int inex)
188 if (!test)
189 __builtin_abort ();
190 if ((!fetestexcept (FE_INEXACT)) != (!inex))
191 __builtin_abort ();
192 feclearexcept (FE_INEXACT);
196 main ()
198 #if __FLT_MANT_DIG__ == 24
199 #if __BITINT_MAXWIDTH__ >= 135
200 check_inexact (testflt_135 (-85070591730234615865843651857942052864.0f) == -85070591730234615865843651857942052864wb, 0);
201 check_inexact (testflt_135 (0xffffffp+104f) == 340282346638528859811704183484516925440wb, 0);
202 check_inexact (testflt_135 (-0xffffffp+104f) == -340282346638528859811704183484516925440wb, 0);
203 check_inexact (testflt_135 (-0xffffffp-1f) == -8388607wb, 1);
204 check_inexact (testflt_135 (-0.f) == 0wb, 0);
205 check_inexact (testflt_135 (-0.f) == 0wb, 0);
206 check_inexact (testflt_135 (-0.9990234375f) == 0wb, 1);
207 check_inexact (testfltu_135 (0.f) == 0uwb, 0);
208 check_inexact (testfltu_135 (-0.9990234375f) == 0uwb, 1);
209 check_inexact (testfltu_135 (0xffffffp-1f) == 8388607uwb, 1);
210 check_inexact (testfltu_135 (0xffffffp+104f) == 340282346638528859811704183484516925440uwb, 0);
211 #endif
212 #if __BITINT_MAXWIDTH__ >= 192
213 check_inexact (testflt_192 (-85070591730234615865843651857942052864.0f) == -85070591730234615865843651857942052864wb, 0);
214 check_inexact (testflt_192 (0xffffffp+104f) == 340282346638528859811704183484516925440wb, 0);
215 check_inexact (testflt_192 (-0xffffffp+104f) == -340282346638528859811704183484516925440wb, 0);
216 check_inexact (testflt_192 (-0xffffffp-3f) == -2097151wb, 1);
217 check_inexact (testflt_192 (-0.f) == 0wb, 0);
218 check_inexact (testflt_192 (-0.9990234375f) == 0wb, 1);
219 check_inexact (testfltu_192 (0.f) == 0uwb, 0);
220 check_inexact (testfltu_192 (-0.9990234375f) == 0uwb, 1);
221 check_inexact (testfltu_192 (0xffffffp-3f) == 2097151uwb, 1);
222 check_inexact (testfltu_192 (0xffffffp+104f) == 340282346638528859811704183484516925440uwb, 0);
223 #endif
224 #if __BITINT_MAXWIDTH__ >= 575
225 check_inexact (testflt_575 (-85070591730234615865843651857942052864.0f) == -85070591730234615865843651857942052864wb, 0);
226 check_inexact (testflt_575 (0xffffffp+104f) == 340282346638528859811704183484516925440wb, 0);
227 check_inexact (testflt_575 (-0xffffffp+104f) == -340282346638528859811704183484516925440wb, 0);
228 check_inexact (testflt_575 (-0xffffffp-5f) == -524287wb, 1);
229 check_inexact (testflt_575 (0.f) == 0wb, 0);
230 check_inexact (testflt_575 (-0.9990234375f) == 0wb, 1);
231 check_inexact (testfltu_575 (-0.f) == 0uwb, 0);
232 check_inexact (testfltu_575 (-0.9990234375f) == 0uwb, 1);
233 check_inexact (testfltu_575 (0xffffffp-5f) == 524287uwb, 1);
234 check_inexact (testfltu_575 (0xffffffp+104f) == 340282346638528859811704183484516925440uwb, 0);
235 #endif
236 #endif
237 #if __DBL_MANT_DIG__ == 53
238 #if __BITINT_MAXWIDTH__ >= 135
239 check_inexact (testdbl_135 (-85070591730234615865843651857942052864.0) == -85070591730234615865843651857942052864wb, 0);
240 check_inexact (testdbl_135 (0x1fffffffffffffp+81) == 21778071482940059243804335646374816120832wb, 0);
241 check_inexact (testdbl_135 (-0x20000000000000p+81) == -21778071482940061661655974875633165533183wb - 1, 0);
242 check_inexact (testdbl_135 (-0x1fffffffffffffp-1) == -4503599627370495wb, 1);
243 check_inexact (testdbl_135 (-0.) == 0wb, 0);
244 check_inexact (testdbl_135 (-0.9990234375) == 0wb, 1);
245 check_inexact (testdblu_135 (0.) == 0uwb, 0);
246 check_inexact (testdblu_135 (-0.9990234375) == 0uwb, 1);
247 check_inexact (testdblu_135 (0x1fffffffffffffp-1) == 4503599627370495uwb, 1);
248 check_inexact (testdblu_135 (0x1fffffffffffffp+82) == 43556142965880118487608671292749632241664uwb, 0);
249 #endif
250 #if __BITINT_MAXWIDTH__ >= 192
251 check_inexact (testdbl_192 (-85070591730234615865843651857942052864.0) == -85070591730234615865843651857942052864wb, 0);
252 check_inexact (testdbl_192 (0x1fffffffffffffp+138) == 3138550867693340033468750984562846621555579712101368725504wb, 0);
253 check_inexact (testdbl_192 (-0x20000000000000p+138) == -3138550867693340381917894711603833208051177722232017256447wb - 1, 0);
254 check_inexact (testdbl_192 (-0x1fffffffffffffp-3) == -1125899906842623wb, 1);
255 check_inexact (testdbl_192 (0.) == 0wb, 0);
256 check_inexact (testdbl_192 (-0.9990234375) == 0wb, 1);
257 check_inexact (testdblu_192 (-0.) == 0uwb, 0);
258 check_inexact (testdblu_192 (-0.9990234375) == 0uwb, 1);
259 check_inexact (testdblu_192 (0x1fffffffffffffp-3) == 1125899906842623uwb, 1);
260 check_inexact (testdblu_192 (0x1fffffffffffffp+139) == 6277101735386680066937501969125693243111159424202737451008uwb, 0);
261 #endif
262 #if __BITINT_MAXWIDTH__ >= 575
263 check_inexact (testdbl_575 (-85070591730234615865843651857942052864.0) == -85070591730234615865843651857942052864wb, 0);
264 check_inexact (testdbl_575 (0x1fffffffffffffp+521) == 61832600368276126650327970124302082526882038193909742709080463879918896882169507607035916867654709124839777195049479857541529867095829765369898539058829479405123401922117632wb, 0);
265 check_inexact (testdbl_575 (-0x20000000000000p+521) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 0);
266 check_inexact (testdbl_575 (-0x1fffffffffffffp-5) == -281474976710655wb, 1);
267 check_inexact (testdbl_575 (-0.) == 0wb, 0);
268 check_inexact (testdbl_575 (-0.9990234375) == 0wb, 1);
269 check_inexact (testdblu_575 (0.) == 0uwb, 0);
270 check_inexact (testdblu_575 (-0.9990234375) == 0uwb, 1);
271 check_inexact (testdblu_575 (0x1fffffffffffffp-5) == 281474976710655uwb, 1);
272 check_inexact (testdblu_575 (0x1fffffffffffffp+522) == 123665200736552253300655940248604165053764076387819485418160927759837793764339015214071833735309418249679554390098959715083059734191659530739797078117658958810246803844235264uwb, 0);
273 #endif
274 #endif
275 #if __LDBL_MANT_DIG__ == 64
276 #if __BITINT_MAXWIDTH__ >= 135
277 check_inexact (testldbl_135 (-85070591730234615865843651857942052864.0L) == -85070591730234615865843651857942052864wb, 0);
278 check_inexact (testldbl_135 (0xffffffffffffffffp+70L) == 21778071482940061660475383254915754229760wb, 0);
279 check_inexact (testldbl_135 (-0x10000000000000000p+70L) == -21778071482940061661655974875633165533183wb - 1, 0);
280 check_inexact (testldbl_135 (-0xffffffffffffffffp-1L) == -9223372036854775807wb, 1);
281 check_inexact (testldbl_135 (-0.L) == 0wb, 0);
282 check_inexact (testldbl_135 (-0.9990234375L) == 0wb, 1);
283 check_inexact (testldblu_135 (0.L) == 0uwb, 0);
284 check_inexact (testldblu_135 (-0.9990234375L) == 0uwb, 1);
285 check_inexact (testldblu_135 (0xffffffffffffffffp-1L) == 9223372036854775807uwb, 1);
286 check_inexact (testldblu_135 (0xffffffffffffffffp+71L) == 43556142965880123320950766509831508459520uwb, 0);
287 #endif
288 #if __BITINT_MAXWIDTH__ >= 192
289 check_inexact (testldbl_192 (-85070591730234615865843651857942052864.0L) == -85070591730234615865843651857942052864wb, 0);
290 check_inexact (testldbl_192 (0xffffffffffffffffp+127L) == 3138550867693340381747753528143363976319490418516133150720wb, 0);
291 check_inexact (testldbl_192 (-0x10000000000000000p+127L) == -3138550867693340381917894711603833208051177722232017256447wb - 1, 0);
292 check_inexact (testldbl_192 (-0xffffffffffffffffp-2L) == -4611686018427387903wb, 1);
293 check_inexact (testldbl_192 (0.L) == 0wb, 0);
294 check_inexact (testldbl_192 (-0.9990234375L) == 0wb, 1);
295 check_inexact (testldblu_192 (-0.L) == 0uwb, 0);
296 check_inexact (testldblu_192 (-0.9990234375L) == 0uwb, 1);
297 check_inexact (testldblu_192 (0xffffffffffffffffp-2L) == 4611686018427387903uwb, 1);
298 check_inexact (testldblu_192 (0xffffffffffffffffp+128L) == 6277101735386680763495507056286727952638980837032266301440uwb, 0);
299 #endif
300 #if __BITINT_MAXWIDTH__ >= 575
301 check_inexact (testldbl_575 (-85070591730234615865843651857942052864.0L) == -85070591730234615865843651857942052864wb, 0);
302 check_inexact (testldbl_575 (0xffffffffffffffffp+510L) == 61832600368276133511773678272426148233889331025751498446645922568076207932202076431648659257792374503198949281962308977915333294030066289778448068072486649492543280785653760wb, 0);
303 check_inexact (testldbl_575 (-0x10000000000000000p+510L) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 0);
304 check_inexact (testldbl_575 (-0xffffffffffffffffp-4L) == -1152921504606846975wb, 1);
305 check_inexact (testldbl_575 (0.L) == 0wb, 0);
306 check_inexact (testldbl_575 (-0.9990234375L) == 0wb, 1);
307 check_inexact (testldblu_575 (-0.L) == 0uwb, 0);
308 check_inexact (testldblu_575 (-0.9990234375L) == 0uwb, 1);
309 check_inexact (testldblu_575 (0xffffffffffffffffp-4L) == 1152921504606846975uwb, 1);
310 check_inexact (testldblu_575 (0xffffffffffffffffp+511L) == 123665200736552267023547356544852296467778662051502996893291845136152415864404152863297318515584749006397898563924617955830666588060132579556896136144973298985086561571307520uwb, 0);
311 #endif
312 #endif
313 #if __FLT128_MANT_DIG__ == 113
314 #if __BITINT_MAXWIDTH__ >= 135
315 check_inexact (testflt128_135 (-85070591730234615865843651857942052864.0F128) == -85070591730234615865843651857942052864wb, 0);
316 check_inexact (testflt128_135 (0x1ffffffffffffffffffffffffffffp+21F128) == 21778071482940061661655974875633163436032wb, 0);
317 check_inexact (testflt128_135 (-0x20000000000000000000000000000p+21F128) == -21778071482940061661655974875633165533183wb - 1, 0);
318 check_inexact (testflt128_135 (-0x1ffffffffffffffffffffffffffffp-1F128) == -5192296858534827628530496329220095wb, 1);
319 check_inexact (testflt128_135 (-0.F128) == 0wb, 0);
320 check_inexact (testflt128_135 (-0.9990234375F128) == 0wb, 1);
321 check_inexact (testflt128u_135 (0.F128) == 0uwb, 0);
322 check_inexact (testflt128u_135 (-0.9990234375F128) == 0uwb, 1);
323 check_inexact (testflt128u_135 (0x1ffffffffffffffffffffffffffffp-1F128) == 5192296858534827628530496329220095uwb, 1);
324 check_inexact (testflt128u_135 (0x1ffffffffffffffffffffffffffffp+22F128) == 43556142965880123323311949751266326872064uwb, 0);
325 #endif
326 #if __BITINT_MAXWIDTH__ >= 192
327 check_inexact (testflt128_192 (-85070591730234615865843651857942052864.0F128) == -85070591730234615865843651857942052864wb, 0);
328 check_inexact (testflt128_192 (0x1ffffffffffffffffffffffffffffp+78F128) == 3138550867693340381917894711603832905819722818574723579904wb, 0);
329 check_inexact (testflt128_192 (-0x20000000000000000000000000000p+78F128) == -3138550867693340381917894711603833208051177722232017256447wb - 1, 0);
330 check_inexact (testflt128_192 (-0x1ffffffffffffffffffffffffffffp-4F128) == -649037107316853453566312041152511wb, 1);
331 check_inexact (testflt128_192 (-0.F128) == 0wb, 0);
332 check_inexact (testflt128_192 (-0.9990234375F128) == 0wb, 1);
333 check_inexact (testflt128u_192 (0.F128) == 0uwb, 0);
334 check_inexact (testflt128u_192 (-0.9990234375F128) == 0uwb, 1);
335 check_inexact (testflt128u_192 (0x1ffffffffffffffffffffffffffffp-4F128) == 649037107316853453566312041152511uwb, 1);
336 check_inexact (testflt128u_192 (0x1ffffffffffffffffffffffffffffp+79F128) == 6277101735386680763835789423207665811639445637149447159808uwb, 0);
337 #endif
338 #if __BITINT_MAXWIDTH__ >= 575
339 check_inexact (testflt128_575 (-85070591730234615865843651857942052864.0F128) == -85070591730234615865843651857942052864wb, 0);
340 check_inexact (testflt128_575 (0x1ffffffffffffffffffffffffffffp+461F128) == 61832600368276133515125630254911791554520007845691312598455129804691160851602940042069550439343049559602369631548246946680753811425558728725309540242943660463695151425912832wb, 0);
341 check_inexact (testflt128_575 (-0x20000000000000000000000000000p+461F128) == -61832600368276133515125630254911797508782837275302959978515764023224306276632966792579100265310761247399417856504034834837841258576687802491886538775473291979151693037174783wb - 1, 0);
342 check_inexact (testflt128_575 (-0x1ffffffffffffffffffffffffffffp-8F128) == -40564819207303340847894502572031wb, 1);
343 check_inexact (testflt128_575 (0.F128) == 0wb, 0);
344 check_inexact (testflt128_575 (-0.9990234375F128) == 0wb, 1);
345 check_inexact (testflt128u_575 (-0.F128) == 0uwb, 0);
346 check_inexact (testflt128u_575 (-0.9990234375F128) == 0uwb, 1);
347 check_inexact (testflt128u_575 (0x1ffffffffffffffffffffffffffffp-8F128) == 40564819207303340847894502572031uwb, 1);
348 check_inexact (testflt128u_575 (0x1ffffffffffffffffffffffffffffp+462F128) == 123665200736552267030251260509823583109040015691382625196910259609382321703205880084139100878686099119204739263096493893361507622851117457450619080485887320927390302851825664uwb, 0);
349 #endif
350 #endif