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