1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -ffreestanding %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -ffreestanding %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -ffreestanding %s
4 // RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++11 -ffreestanding %s
5 // RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++14 -ffreestanding %s
6 // RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++17 -ffreestanding %s
7 // expected-no-diagnostics
8 
9 /* Basic floating point conformance checks against:
10     - N1570 draft of C11 Std.
11     - N1256 draft of C99 Std.
12     - http://port70.net/~nsz/c/c89/c89-draft.html draft of C89/C90 Std.
13 */
14 /*
15     C11,    5.2.4.2.2p11,   pp. 30
16     C99,    5.2.4.2.2p9,    pp. 25
17     C89,    2.2.4.2
18 */
19 #include <float.h>
20 
21 #ifndef FLT_RADIX
22     #error "Mandatory macro FLT_RADIX is missing."
23 #elif   FLT_RADIX < 2
24     #error "Mandatory macro FLT_RADIX is invalid."
25 #endif
26 
27 
28 #ifndef FLT_MANT_DIG
29     #error "Mandatory macro FLT_MANT_DIG is missing."
30 #elif   FLT_MANT_DIG < 2
31     #error "Mandatory macro FLT_MANT_DIG is invalid."
32 #endif
33 #ifndef DBL_MANT_DIG
34     #error "Mandatory macro DBL_MANT_DIG is missing."
35 #elif   DBL_MANT_DIG < 2
36     #error "Mandatory macro DBL_MANT_DIG is invalid."
37 #endif
38 #ifndef LDBL_MANT_DIG
39     #error "Mandatory macro LDBL_MANT_DIG is missing."
40 #elif   LDBL_MANT_DIG < 2
41     #error "Mandatory macro LDBL_MANT_DIG is invalid."
42 #endif
43 #if ((FLT_MANT_DIG > DBL_MANT_DIG) || (DBL_MANT_DIG > LDBL_MANT_DIG))
44     #error "Mandatory macros {FLT,DBL,LDBL}_MANT_DIG are invalid."
45 #endif
46 
47 
48 #if __STDC_VERSION__ >= 201112L || !defined(__STRICT_ANSI__) || __cplusplus >= 201703L
49     #ifndef FLT_DECIMAL_DIG
50         #error "Mandatory macro FLT_DECIMAL_DIG is missing."
51     #elif   FLT_DECIMAL_DIG < 6
52         #error "Mandatory macro FLT_DECIMAL_DIG is invalid."
53     #endif
54     #ifndef DBL_DECIMAL_DIG
55         #error "Mandatory macro DBL_DECIMAL_DIG is missing."
56     #elif   DBL_DECIMAL_DIG < 10
57         #error "Mandatory macro DBL_DECIMAL_DIG is invalid."
58     #endif
59     #ifndef LDBL_DECIMAL_DIG
60         #error "Mandatory macro LDBL_DECIMAL_DIG is missing."
61     #elif   LDBL_DECIMAL_DIG < 10
62         #error "Mandatory macro LDBL_DECIMAL_DIG is invalid."
63     #endif
64     #if ((FLT_DECIMAL_DIG > DBL_DECIMAL_DIG) || (DBL_DECIMAL_DIG > LDBL_DECIMAL_DIG))
65         #error "Mandatory macros {FLT,DBL,LDBL}_DECIMAL_DIG are invalid."
66     #endif
67     #ifndef FLT_HAS_SUBNORM
68         #error "Mandatory macro FLT_HAS_SUBNORM is missing."
69     #elif FLT_HAS_SUBNORM != __FLT_HAS_DENORM__
70         #error "Mandatory macro FLT_HAS_SUBNORM is invalid."
71     #endif
72     #ifndef LDBL_HAS_SUBNORM
73         #error "Mandatory macro LDBL_HAS_SUBNORM is missing."
74     #elif LDBL_HAS_SUBNORM != __LDBL_HAS_DENORM__
75         #error "Mandatory macro LDBL_HAS_SUBNORM is invalid."
76     #endif
77     #ifndef DBL_HAS_SUBNORM
78         #error "Mandatory macro DBL_HAS_SUBNORM is missing."
79     #elif DBL_HAS_SUBNORM != __DBL_HAS_DENORM__
80         #error "Mandatory macro DBL_HAS_SUBNORM is invalid."
81     #endif
82 #else
83     #ifdef FLT_DECIMAL_DIG
84         #error "Macro FLT_DECIMAL_DIG should not be defined."
85     #endif
86     #ifdef DBL_DECIMAL_DIG
87         #error "Macro DBL_DECIMAL_DIG should not be defined."
88     #endif
89     #ifdef LDBL_DECIMAL_DIG
90         #error "Macro LDBL_DECIMAL_DIG should not be defined."
91     #endif
92     #ifdef FLT_HAS_SUBNORM
93         #error "Macro FLT_HAS_SUBNORM should not be defined."
94     #endif
95     #ifdef DBL_HAS_SUBNORM
96         #error "Macro DBL_HAS_SUBNORM should not be defined."
97     #endif
98     #ifdef LDBL_HAS_SUBNORM
99         #error "Macro LDBL_HAS_SUBNORM should not be defined."
100     #endif
101 #endif
102 
103 
104 #if __STDC_VERSION__ >= 199901L || !defined(__STRICT_ANSI__) || __cplusplus >= 201103L
105     #ifndef DECIMAL_DIG
106         #error "Mandatory macro DECIMAL_DIG is missing."
107     #elif   DECIMAL_DIG < 10
108         #error "Mandatory macro DECIMAL_DIG is invalid."
109     #endif
110 #else
111     #ifdef DECIMAL_DIG
112         #error "Macro DECIMAL_DIG should not be defined."
113     #endif
114 #endif
115 
116 
117 #ifndef FLT_DIG
118     #error "Mandatory macro FLT_DIG is missing."
119 #elif   FLT_DIG < 6
120     #error "Mandatory macro FLT_DIG is invalid."
121 #endif
122 #ifndef DBL_DIG
123     #error "Mandatory macro DBL_DIG is missing."
124 #elif   DBL_DIG < 10
125     #error "Mandatory macro DBL_DIG is invalid."
126 #endif
127 #ifndef LDBL_DIG
128     #error "Mandatory macro LDBL_DIG is missing."
129 #elif   LDBL_DIG < 10
130     #error "Mandatory macro LDBL_DIG is invalid."
131 #endif
132 #if ((FLT_DIG > DBL_DIG) || (DBL_DIG > LDBL_DIG))
133     #error "Mandatory macros {FLT,DBL,LDBL}_DIG, are invalid."
134 #endif
135 
136 
137 #ifndef FLT_MIN_EXP
138     #error "Mandatory macro FLT_MIN_EXP is missing."
139 #elif   FLT_MIN_EXP > -1
140     #error "Mandatory macro FLT_MIN_EXP is invalid."
141 #endif
142 #ifndef DBL_MIN_EXP
143     #error "Mandatory macro DBL_MIN_EXP is missing."
144 #elif   DBL_MIN_EXP > -1
145     #error "Mandatory macro DBL_MIN_EXP is invalid."
146 #endif
147 #ifndef LDBL_MIN_EXP
148     #error "Mandatory macro LDBL_MIN_EXP is missing."
149 #elif   LDBL_MIN_EXP > -1
150     #error "Mandatory macro LDBL_MIN_EXP is invalid."
151 #endif
152 
153 
154 #ifndef FLT_MIN_10_EXP
155     #error "Mandatory macro FLT_MIN_10_EXP is missing."
156 #elif   FLT_MIN_10_EXP > -37
157     #error "Mandatory macro FLT_MIN_10_EXP is invalid."
158 #endif
159 #ifndef DBL_MIN_10_EXP
160     #error "Mandatory macro DBL_MIN_10_EXP is missing."
161 #elif   DBL_MIN_10_EXP > -37
162     #error "Mandatory macro DBL_MIN_10_EXP is invalid."
163 #endif
164 #ifndef LDBL_MIN_10_EXP
165     #error "Mandatory macro LDBL_MIN_10_EXP is missing."
166 #elif   LDBL_MIN_10_EXP > -37
167     #error "Mandatory macro LDBL_MIN_10_EXP is invalid."
168 #endif
169 
170 
171 #ifndef FLT_MAX_EXP
172     #error "Mandatory macro FLT_MAX_EXP is missing."
173 #elif   FLT_MAX_EXP < 1
174     #error "Mandatory macro FLT_MAX_EXP is invalid."
175 #endif
176 #ifndef DBL_MAX_EXP
177     #error "Mandatory macro DBL_MAX_EXP is missing."
178 #elif   DBL_MAX_EXP < 1
179     #error "Mandatory macro DBL_MAX_EXP is invalid."
180 #endif
181 #ifndef LDBL_MAX_EXP
182     #error "Mandatory macro LDBL_MAX_EXP is missing."
183 #elif   LDBL_MAX_EXP < 1
184     #error "Mandatory macro LDBL_MAX_EXP is invalid."
185 #endif
186 #if ((FLT_MAX_EXP > DBL_MAX_EXP) || (DBL_MAX_EXP > LDBL_MAX_EXP))
187     #error "Mandatory macros {FLT,DBL,LDBL}_MAX_EXP are invalid."
188 #endif
189 
190 
191 #ifndef FLT_MAX_10_EXP
192     #error "Mandatory macro FLT_MAX_10_EXP is missing."
193 #elif   FLT_MAX_10_EXP < 37
194     #error "Mandatory macro FLT_MAX_10_EXP is invalid."
195 #endif
196 #ifndef DBL_MAX_10_EXP
197     #error "Mandatory macro DBL_MAX_10_EXP is missing."
198 #elif   DBL_MAX_10_EXP < 37
199     #error "Mandatory macro DBL_MAX_10_EXP is invalid."
200 #endif
201 #ifndef LDBL_MAX_10_EXP
202     #error "Mandatory macro LDBL_MAX_10_EXP is missing."
203 #elif   LDBL_MAX_10_EXP < 37
204     #error "Mandatory macro LDBL_MAX_10_EXP is invalid."
205 #endif
206 #if ((FLT_MAX_10_EXP > DBL_MAX_10_EXP) || (DBL_MAX_10_EXP > LDBL_MAX_10_EXP))
207     #error "Mandatory macros {FLT,DBL,LDBL}_MAX_10_EXP are invalid."
208 #endif
209 
210 
211 /* Internal consistency checks */
212 _Static_assert(FLT_RADIX == __FLT_RADIX__, "");
213 
214 _Static_assert(FLT_MANT_DIG == __FLT_MANT_DIG__, "");
215 _Static_assert(DBL_MANT_DIG == __DBL_MANT_DIG__, "");
216 _Static_assert(LDBL_MANT_DIG == __LDBL_MANT_DIG__, "");
217 
218 #if __STDC_VERSION__ >= 201112L || !defined(__STRICT_ANSI__) || __cplusplus >= 201703L
219 _Static_assert(FLT_DECIMAL_DIG == __FLT_DECIMAL_DIG__, "");
220 _Static_assert(DBL_DECIMAL_DIG == __DBL_DECIMAL_DIG__, "");
221 _Static_assert(LDBL_DECIMAL_DIG == __LDBL_DECIMAL_DIG__, "");
222 #endif
223 
224 #if __STDC_VERSION__ >= 199901L || !defined(__STRICT_ANSI__) || __cplusplus >= 201103L
225 _Static_assert(DECIMAL_DIG == __DECIMAL_DIG__, "");
226 #endif
227 
228 _Static_assert(FLT_DIG == __FLT_DIG__, "");
229 _Static_assert(DBL_DIG == __DBL_DIG__, "");
230 _Static_assert(LDBL_DIG == __LDBL_DIG__, "");
231 
232 _Static_assert(FLT_MIN_EXP == __FLT_MIN_EXP__, "");
233 _Static_assert(DBL_MIN_EXP == __DBL_MIN_EXP__, "");
234 _Static_assert(LDBL_MIN_EXP == __LDBL_MIN_EXP__, "");
235 
236 _Static_assert(FLT_MIN_10_EXP == __FLT_MIN_10_EXP__, "");
237 _Static_assert(DBL_MIN_10_EXP == __DBL_MIN_10_EXP__, "");
238 _Static_assert(LDBL_MIN_10_EXP == __LDBL_MIN_10_EXP__, "");
239 
240 _Static_assert(FLT_MAX_EXP == __FLT_MAX_EXP__, "");
241 _Static_assert(DBL_MAX_EXP == __DBL_MAX_EXP__, "");
242 _Static_assert(LDBL_MAX_EXP == __LDBL_MAX_EXP__, "");
243 
244 _Static_assert(FLT_MAX_10_EXP == __FLT_MAX_10_EXP__, "");
245 _Static_assert(DBL_MAX_10_EXP == __DBL_MAX_10_EXP__, "");
246 _Static_assert(LDBL_MAX_10_EXP == __LDBL_MAX_10_EXP__, "");
247