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