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
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.
15 C11, 5.2.4.2.2p11, pp. 30
16 C99, 5.2.4.2.2p9, pp. 25
22 #error "Mandatory macro FLT_RADIX is missing."
24 #error "Mandatory macro FLT_RADIX is invalid."
29 #error "Mandatory macro FLT_MANT_DIG is missing."
30 #elif FLT_MANT_DIG < 2
31 #error "Mandatory macro FLT_MANT_DIG is invalid."
34 #error "Mandatory macro DBL_MANT_DIG is missing."
35 #elif DBL_MANT_DIG < 2
36 #error "Mandatory macro DBL_MANT_DIG is invalid."
39 #error "Mandatory macro LDBL_MANT_DIG is missing."
40 #elif LDBL_MANT_DIG < 2
41 #error "Mandatory macro LDBL_MANT_DIG is invalid."
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."
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."
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."
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."
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."
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."
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."
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."
83 #ifdef FLT_DECIMAL_DIG
84 #error "Macro FLT_DECIMAL_DIG should not be defined."
86 #ifdef DBL_DECIMAL_DIG
87 #error "Macro DBL_DECIMAL_DIG should not be defined."
89 #ifdef LDBL_DECIMAL_DIG
90 #error "Macro LDBL_DECIMAL_DIG should not be defined."
92 #ifdef FLT_HAS_SUBNORM
93 #error "Macro FLT_HAS_SUBNORM should not be defined."
95 #ifdef DBL_HAS_SUBNORM
96 #error "Macro DBL_HAS_SUBNORM should not be defined."
98 #ifdef LDBL_HAS_SUBNORM
99 #error "Macro LDBL_HAS_SUBNORM should not be defined."
104 #if __STDC_VERSION__ >= 199901L || !defined(__STRICT_ANSI__) || __cplusplus >= 201103L
106 #error "Mandatory macro DECIMAL_DIG is missing."
107 #elif DECIMAL_DIG < 10
108 #error "Mandatory macro DECIMAL_DIG is invalid."
112 #error "Macro DECIMAL_DIG should not be defined."
118 #error "Mandatory macro FLT_DIG is missing."
120 #error "Mandatory macro FLT_DIG is invalid."
123 #error "Mandatory macro DBL_DIG is missing."
125 #error "Mandatory macro DBL_DIG is invalid."
128 #error "Mandatory macro LDBL_DIG is missing."
130 #error "Mandatory macro LDBL_DIG is invalid."
132 #if ((FLT_DIG > DBL_DIG) || (DBL_DIG > LDBL_DIG))
133 #error "Mandatory macros {FLT,DBL,LDBL}_DIG, are invalid."
138 #error "Mandatory macro FLT_MIN_EXP is missing."
139 #elif FLT_MIN_EXP > -1
140 #error "Mandatory macro FLT_MIN_EXP is invalid."
143 #error "Mandatory macro DBL_MIN_EXP is missing."
144 #elif DBL_MIN_EXP > -1
145 #error "Mandatory macro DBL_MIN_EXP is invalid."
148 #error "Mandatory macro LDBL_MIN_EXP is missing."
149 #elif LDBL_MIN_EXP > -1
150 #error "Mandatory macro LDBL_MIN_EXP is invalid."
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."
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."
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."
172 #error "Mandatory macro FLT_MAX_EXP is missing."
173 #elif FLT_MAX_EXP < 1
174 #error "Mandatory macro FLT_MAX_EXP is invalid."
177 #error "Mandatory macro DBL_MAX_EXP is missing."
178 #elif DBL_MAX_EXP < 1
179 #error "Mandatory macro DBL_MAX_EXP is invalid."
182 #error "Mandatory macro LDBL_MAX_EXP is missing."
183 #elif LDBL_MAX_EXP < 1
184 #error "Mandatory macro LDBL_MAX_EXP is invalid."
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."
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."
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."
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."
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."
211 /* Internal consistency checks */
212 _Static_assert(FLT_RADIX
== __FLT_RADIX__
, "");
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__
, "");
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__
, "");
224 #if __STDC_VERSION__ >= 199901L || !defined(__STRICT_ANSI__) || __cplusplus >= 201103L
225 _Static_assert(DECIMAL_DIG
== __DECIMAL_DIG__
, "");
228 _Static_assert(FLT_DIG
== __FLT_DIG__
, "");
229 _Static_assert(DBL_DIG
== __DBL_DIG__
, "");
230 _Static_assert(LDBL_DIG
== __LDBL_DIG__
, "");
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__
, "");
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__
, "");
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__
, "");
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__
, "");