Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
limits_bits.cpp
Go to the documentation of this file.
1
29#define _RWSTD_LIB_SRC
30
31#include <float.h> // for INFINITY, NAN
32#include <stdlib.h> // for atof()
33
34// must not #include <limits> to avoid colliding with symbols
35// declared there with a different type than what they are
36// defined with here
37// #include <limits>
38
39#include <rw/_defs.h>
40
41
43
44#ifndef _RWSTD_NO_INFINITY
45
46# if !defined (_RWSTD_DBL_INF_BITS)
47# error one of _RWSTD_NO_INFINITY and _RWSTD_DBL_INF_BITS must be #defined
48# endif
49
50
51union _FltBits {
52 char _C_bits [sizeof (float)];
53 float _C_val;
54};
55
56
57union _DblBits {
58 char _C_bits [sizeof (double)];
59 double _C_val;
60};
61
62
63# ifndef _RWSTD_NO_LONG_DOUBLE
64
65union _LDblBits {
66 char _C_bits [sizeof (long double)];
67 long double _C_val;
68};
69
70# endif // _RWSTD_NO_LONG_DOUBLE
71
72# ifndef _RWSTD_NO_OBJECT_MANGLING
73
74extern "C" {
75
76# else // if defined (_RWSTD_NO_OBJECT_MANGLING)
77
78extern "C++" {
79
80# endif // _RWSTD_NO_OBJECT_MANGLING
81
82// The constants below are declared in <limits> but with a different
83// type. C linkage is (conditionally) used to defeat MSVC and other
84// "clever" compilers that mangle the type of objects into their names.
85
86// infinity computed at config time
87_RWSTD_EXPORT extern const _DblBits
88__rw_dbl_infinity = { _RWSTD_DBL_INF_BITS };
89
90
91_RWSTD_EXPORT extern const _FltBits
92__rw_flt_infinity = { _RWSTD_FLT_INF_BITS };
93
94
95# ifndef _RWSTD_NO_LONG_DOUBLE
96
97_RWSTD_EXPORT extern const _LDblBits
98__rw_ldbl_infinity = { _RWSTD_LDBL_INF_BITS };
99
100
101# endif // _RWSTD_NO_LONG_DOUBLE
102
103
104// quiet NaN computed at config time
105_RWSTD_EXPORT extern const _DblBits
106__rw_dbl_qNaN = { _RWSTD_DBL_QNAN_BITS };
107
108
109_RWSTD_EXPORT extern const _FltBits
110__rw_flt_qNaN = { _RWSTD_FLT_QNAN_BITS };
111
112
113# ifndef _RWSTD_NO_LONG_DOUBLE
114
115_RWSTD_EXPORT extern const _LDblBits
116__rw_ldbl_qNaN = { _RWSTD_LDBL_QNAN_BITS };
117
118
119# endif // _RWSTD_NO_LONG_DOUBLE
120
121
122// signaling NaN computed at config time
123_RWSTD_EXPORT extern const _DblBits
124__rw_dbl_sNaN = { _RWSTD_DBL_SNAN_BITS };
125
126
127_RWSTD_EXPORT extern const _FltBits
128__rw_flt_sNaN = { _RWSTD_FLT_SNAN_BITS };
129
130
131# ifndef _RWSTD_NO_LONG_DOUBLE
132
133_RWSTD_EXPORT extern const _LDblBits
134__rw_ldbl_sNaN = { _RWSTD_LDBL_SNAN_BITS };
135
136
137# endif // _RWSTD_NO_LONG_DOUBLE
138
139
140// denormalized minima computed at config time
141_RWSTD_EXPORT extern const _DblBits
142__rw_dbl_denorm_min = { _RWSTD_DBL_DENORM_MIN_BITS };
143
144
145_RWSTD_EXPORT extern const _FltBits
146__rw_flt_denorm_min = { _RWSTD_FLT_DENORM_MIN_BITS };
147
148
149# ifndef _RWSTD_NO_LONG_DOUBLE
150
151_RWSTD_EXPORT extern const _LDblBits
152__rw_ldbl_denorm_min = { _RWSTD_LDBL_DENORM_MIN_BITS };
153
154
155# endif // _RWSTD_NO_LONG_DOUBLE
156
157} // extern "C"/"C++"
158
159
160# if _RWSTD_VER_MAJOR < 5 && defined (_MSC_VER) && defined (_DLL)
161
162// The constants below are defined with C++ linkage
163// to be exported as floating constants with mangled
164// names for binary compatibility with stdcxx 4.1.x
165
166extern const _FltBits
167__rw_flt_infinity_vc = { _RWSTD_FLT_INF_BITS };
168
169extern const _FltBits
170__rw_flt_qNaN_vc = { _RWSTD_FLT_QNAN_BITS };
171
172extern const _FltBits
173__rw_flt_sNaN_vc = { _RWSTD_FLT_SNAN_BITS };
174
175extern const _FltBits
176__rw_flt_denorm_min_vc = { _RWSTD_FLT_DENORM_MIN_BITS };
177
178
179extern const _DblBits
180__rw_dbl_infinity_vc = { _RWSTD_DBL_INF_BITS };
181
182extern const _DblBits
183__rw_dbl_qNaN_vc = { _RWSTD_DBL_QNAN_BITS };
184
185extern const _DblBits
186__rw_dbl_sNaN_vc = { _RWSTD_DBL_SNAN_BITS };
187
188extern const _DblBits
189__rw_dbl_denorm_min_vc = { _RWSTD_DBL_DENORM_MIN_BITS };
190
191
192# ifndef _RWSTD_NO_LONG_DOUBLE
193
194extern const _LDblBits
195__rw_ldbl_infinity_vc = { _RWSTD_LDBL_INF_BITS };
196
197extern const _LDblBits
198__rw_ldbl_qNaN_vc = { _RWSTD_LDBL_QNAN_BITS };
199
200extern const _LDblBits
201__rw_ldbl_sNaN_vc = { _RWSTD_LDBL_SNAN_BITS };
202
203extern const _LDblBits
204__rw_ldbl_denorm_min_vc = { _RWSTD_LDBL_DENORM_MIN_BITS };
205
206# endif // _RWSTD_NO_LONG_DOUBLE
207
208
209# pragma comment (linker, "/EXPORT:?__rw_flt_infinity@__rw@@3MB=?__rw_flt_infinity_vc@__rw@@3T_FltBits@1@B,DATA")
210# pragma comment (linker, "/EXPORT:?__rw_flt_qNaN@__rw@@3MB=?__rw_flt_qNaN_vc@__rw@@3T_FltBits@1@B,DATA")
211# pragma comment (linker, "/EXPORT:?__rw_flt_sNaN@__rw@@3MB=?__rw_flt_sNaN_vc@__rw@@3T_FltBits@1@B,DATA")
212# pragma comment (linker, "/EXPORT:?__rw_flt_denorm_min@__rw@@3MB=?__rw_flt_denorm_min_vc@__rw@@3T_FltBits@1@B,DATA")
213
214# pragma comment (linker, "/EXPORT:?__rw_dbl_infinity@__rw@@3NB=?__rw_dbl_infinity_vc@__rw@@3T_DblBits@1@B,DATA")
215# pragma comment (linker, "/EXPORT:?__rw_dbl_qNaN@__rw@@3NB=?__rw_dbl_qNaN_vc@__rw@@3T_DblBits@1@B,DATA")
216# pragma comment (linker, "/EXPORT:?__rw_dbl_sNaN@__rw@@3NB=?__rw_dbl_sNaN_vc@__rw@@3T_DblBits@1@B,DATA")
217# pragma comment (linker, "/EXPORT:?__rw_dbl_denorm_min@__rw@@3NB=?__rw_dbl_denorm_min_vc@__rw@@3T_DblBits@1@B,DATA")
218
219# ifndef _RWSTD_NO_LONG_DOUBLE
220# pragma comment (linker, "/EXPORT:?__rw_ldbl_infinity@__rw@@3OB=?__rw_ldbl_infinity_vc@__rw@@3T_LDblBits@1@B,DATA")
221# pragma comment (linker, "/EXPORT:?__rw_ldbl_qNaN@__rw@@3OB=?__rw_ldbl_qNaN_vc@__rw@@3T_LDblBits@1@B,DATA")
222# pragma comment (linker, "/EXPORT:?__rw_ldbl_sNaN@__rw@@3OB=?__rw_ldbl_sNaN_vc@__rw@@3T_LDblBits@1@B,DATA")
223# pragma comment (linker, "/EXPORT:?__rw_ldbl_denorm_min@__rw@@3OB=?__rw_ldbl_denorm_min_vc@__rw@@3T_LDblBits@1@B,DATA")
224# endif // _RWSTD_NO_LONG_DOUBLE
225
226#endif // _RWSTD_VER_MAJOR < 5 && _MSC_VER && _DLL
227
228#else // if defined (_RWSTD_NO_INFINITY)
229
230
231# ifndef _RWSTD_NO_OBJECT_MANGLING
232
233extern "C" {
234
235# else // if defined (_RWSTD_NO_OBJECT_MANGLING)
236
237extern "C++" {
238
239# endif // _RWSTD_NO_OBJECT_MANGLING
240
241
242// as the last resort compute values at dynamic initialization time
243_RWSTD_EXPORT extern const float __rw_flt_infinity =
244
245# if defined (INFINITY)
246
247 INFINITY;
248
249# elif defined (FLT_INFINITY)
250
251 FLT_INFINITY;
252
253# elif defined (__osf__)
254
255 0.0f; // prevent SIGFPE at startup (PR #23163)
256
257# else // if !defined (__osf__)
258
259_RWSTD_STATIC_CAST (float, atof ("INF"));
260
261# endif // __osf__
262
263_RWSTD_EXPORT extern const double __rw_dbl_infinity = __rw_flt_infinity;
264
265# ifndef _RWSTD_NO_LONG_DOUBLE
266
267_RWSTD_EXPORT extern const long double __rw_ldbl_infinity = __rw_flt_infinity;
268
269# endif // _RWSTD_NO_LONG_DOUBLE
270
271_RWSTD_EXPORT extern const float __rw_flt_qNaN =
272
273# if defined (NAN)
274
275 NAN;
276
277# elif defined (FLT_QNAN)
278
279 FLT_QNAN;
280
281# elif defined (__osf__)
282
283 0.0; // prevent SIGFPE at startup (PR #23163)
284
285# else // if !defined (__osf__)
286
287_RWSTD_STATIC_CAST (float, atof ("NAN"));
288
289# endif // __osf__
290
291_RWSTD_EXPORT extern const float __rw_flt_sNaN =
292
293# if defined (FLT_SNAN)
294 FLT_SNAN;
295# else // if !defined (FLT_SNAN)
296 __rw_flt_qNaN;
297# endif // FLT_SNAN
298
299_RWSTD_EXPORT extern const double __rw_dbl_qNaN = __rw_flt_qNaN;
300_RWSTD_EXPORT extern const double __rw_dbl_sNaN = __rw_flt_sNaN;
301
302_RWSTD_EXPORT extern const float __rw_flt_denorm_min = 0;
303_RWSTD_EXPORT extern const float __rw_dbl_denorm_min = 0;
304
305# ifndef _RWSTD_NO_LONG_DOUBLE
306
307_RWSTD_EXPORT extern const long double __rw_ldbl_qNaN = __rw_dbl_qNaN;
308_RWSTD_EXPORT extern const long double __rw_ldbl_sNaN = __rw_dbl_sNaN;
309
310_RWSTD_EXPORT extern const long double __rw_ldbl_denorm_min = 0;
311
312# endif // _RWSTD_NO_LONG_DOUBLE
313
314} // extern "C"/"C++"
315
316#endif // _RWSTD_NO_INFINITY
317
318
319} // namespace __rw
#define _RWSTD_EXPORT
Definition _defs.h:485
#define _RWSTD_STATIC_CAST(T, x)
Definition _defs.h:534
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567