1 /* Tests for _FloatN / _FloatNx types: test conversions. */
2 /* { dg-do run } */
3 /* { dg-options "" } */
4 /* { dg-add-options float16 } */
5 /* { dg-add-options float32 } */
6 /* { dg-add-options float64 } */
7 /* { dg-add-options float128 } */
8 /* { dg-add-options float32x } */
9 /* { dg-add-options float64x } */
10 /* { dg-add-options float128x } */
11 /* { dg-require-effective-target float32 } */
12 /* { dg-require-effective-target floatn_nx_runtime } */
13
14 #define __STDC_WANT_IEC_60559_TYPES_EXT__
15 #include <float.h>
16
17 #ifndef FLT16_MAX
18 # define _Float16 _Float32
19 # define FLT16_MAX FLT32_MAX
20 # define FLT16_MANT_DIG FLT32_MANT_DIG
21 # define FLT16_EPSILON FLT32_EPSILON
22 #endif
23
24 #ifndef FLT64_MAX
25 # define _Float64 _Float32
26 # define FLT64_MAX FLT32_MAX
27 # define FLT64_MANT_DIG FLT32_MANT_DIG
28 # define FLT64_EPSILON FLT32_EPSILON
29 #endif
30
31 #ifndef FLT128_MAX
32 # define _Float128 _Float32
33 # define FLT128_MAX FLT32_MAX
34 # define FLT128_MANT_DIG FLT32_MANT_DIG
35 # define FLT128_EPSILON FLT32_EPSILON
36 #endif
37
38 #ifndef FLT32X_MAX
39 # define _Float32x _Float32
40 # define FLT32X_MAX FLT32_MAX
41 # define FLT32X_MANT_DIG FLT32_MANT_DIG
42 # define FLT32X_EPSILON FLT32_EPSILON
43 #endif
44
45 #ifndef FLT64X_MAX
46 # define _Float64x _Float32
47 # define FLT64X_MAX FLT32_MAX
48 # define FLT64X_MANT_DIG FLT32_MANT_DIG
49 # define FLT64X_EPSILON FLT32_EPSILON
50 #endif
51
52 #ifndef FLT128X_MAX
53 # define _Float128x _Float32
54 # define FLT128X_MAX FLT32_MAX
55 # define FLT128X_MANT_DIG FLT32_MANT_DIG
56 # define FLT128X_EPSILON FLT32_EPSILON
57 #endif
58
59 #define CONCATX(X, Y) X ## Y
60 #define CONCAT(X, Y) CONCATX (X, Y)
61
62 extern void exit (int);
63 extern void abort (void);
64
65 #define DO_TEST(TYPE1, PFX1, TYPE2, PFX2) \
66 do \
67 { \
68 volatile TYPE1 a = (TYPE1) 1 + CONCAT (PFX1, _EPSILON); \
69 volatile TYPE2 b = (TYPE2) a; \
70 volatile TYPE2 expected; \
71 if (CONCAT (PFX2, _MANT_DIG) < CONCAT (PFX1, _MANT_DIG)) \
72 expected = (TYPE2) 1; \
73 else \
74 expected = (TYPE2) 1 + (TYPE2) CONCAT (PFX1, _EPSILON); \
75 if (b != expected) \
76 abort (); \
77 } \
78 while (0)
79
80 #define DO_TEST1(TYPE1, PFX1) \
81 do \
82 { \
83 DO_TEST (TYPE1, PFX1, _Float16, FLT16); \
84 DO_TEST (TYPE1, PFX1, _Float32, FLT32); \
85 DO_TEST (TYPE1, PFX1, _Float64, FLT64); \
86 DO_TEST (TYPE1, PFX1, _Float128, FLT128); \
87 DO_TEST (TYPE1, PFX1, _Float32x, FLT32X); \
88 DO_TEST (TYPE1, PFX1, _Float64x, FLT64X); \
89 DO_TEST (TYPE1, PFX1, _Float128x, FLT128X); \
90 } \
91 while (0)
92
93 int
main(void)94 main (void)
95 {
96 DO_TEST1 (_Float16, FLT16);
97 DO_TEST1 (_Float32, FLT32);
98 DO_TEST1 (_Float64, FLT64);
99 DO_TEST1 (_Float128, FLT128);
100 DO_TEST1 (_Float32x, FLT32X);
101 DO_TEST1 (_Float64x, FLT64X);
102 DO_TEST1 (_Float128x, FLT128X);
103 exit (0);
104 }
105