1 // limits standard header
2 #pragma once
3 #ifndef _LIMITS_
4 #define _LIMITS_
5 #ifndef RC_INVOKED
6 #include <ymath.h>
7 #include <cfloat>
8 #include <climits>
9 #include <cmath>
10 #include <cwchar>
11 #include <xstddef>
12
13 #ifdef _MSC_VER
14  #pragma pack(push,_CRT_PACKING)
15  #pragma warning(push,3)
16 #endif  /* _MSC_VER */
17
18 _STD_BEGIN
19
20 //    ASSUMES:
21 //    wraparound 2's complement integer arithmetic w/o traps
22 //    all CHAR_BITs of each byte used by integers
23 //    IEC559 (IEEE 754) floating-point arithmetic
24 //    floating-point errors can trap
25 //    tinyness detected before floating-point rounding
26 //    64-bit long long (if _LONGLONG defined)
27
28         // ENUM float_denorm_style
29 typedef enum
30     {    // constants for different IEEE float denormalization styles
31     denorm_indeterminate = -1,
32     denorm_absent = 0,
33     denorm_present = 1}
34         float_denorm_style;
35
36         // ENUM float_round_style
37 typedef enum
38     {    // constants for different IEEE rounding styles
39     round_indeterminate = -1,
40     round_toward_zero = 0,
41     round_to_nearest = 1,
42     round_toward_infinity = 2,
43     round_toward_neg_infinity = 3}
44         float_round_style;
45
46         // STRUCT _Num_base
47 struct _CRTIMP2_PURE _Num_base
48     {    // base for all types, with common defaults
49     _STCONS(float_denorm_style, has_denorm, denorm_absent);
50     _STCONS(bool, has_denorm_loss, false);
51     _STCONS(bool, has_infinity, false);
52     _STCONS(bool, has_quiet_NaN, false);
53     _STCONS(bool, has_signaling_NaN, false);
54     _STCONS(bool, is_bounded, false);
55     _STCONS(bool, is_exact, false);
56     _STCONS(bool, is_iec559, false);
57     _STCONS(bool, is_integer, false);
58     _STCONS(bool, is_modulo, false);
59     _STCONS(bool, is_signed, false);
60     _STCONS(bool, is_specialized, false);
61     _STCONS(bool, tinyness_before, false);
62     _STCONS(bool, traps, false);
63     _STCONS(float_round_style, round_style, round_toward_zero);
64     _STCONS(int, digits, 0);
65     _STCONS(int, digits10, 0);
66     _STCONS(int, max_exponent, 0);
67     _STCONS(int, max_exponent10, 0);
68     _STCONS(int, min_exponent, 0);
69     _STCONS(int, min_exponent10, 0);
70     _STCONS(int, radix, 0);
71     };
72
73 _STCONSDEF(_Num_base, float_denorm_style, has_denorm)
74 _STCONSDEF(_Num_base, bool, has_denorm_loss)
75 _STCONSDEF(_Num_base, bool, has_infinity)
76 _STCONSDEF(_Num_base, bool, has_quiet_NaN)
77 _STCONSDEF(_Num_base, bool, has_signaling_NaN)
78 _STCONSDEF(_Num_base, bool, is_bounded)
79 _STCONSDEF(_Num_base, bool, is_exact)
80 _STCONSDEF(_Num_base, bool, is_iec559)
81 _STCONSDEF(_Num_base, bool, is_integer)
82 _STCONSDEF(_Num_base, bool, is_modulo)
83 _STCONSDEF(_Num_base, bool, is_signed)
84 _STCONSDEF(_Num_base, bool, is_specialized)
85 _STCONSDEF(_Num_base, bool, tinyness_before)
86 _STCONSDEF(_Num_base, bool, traps)
87 _STCONSDEF(_Num_base, float_round_style, round_style)
88 _STCONSDEF(_Num_base, int, digits)
89 _STCONSDEF(_Num_base, int, digits10)
90 _STCONSDEF(_Num_base, int, max_exponent)
91 _STCONSDEF(_Num_base, int, max_exponent10)
92 _STCONSDEF(_Num_base, int, min_exponent)
93 _STCONSDEF(_Num_base, int, min_exponent10)
94 _STCONSDEF(_Num_base, int, radix)
95
96         // TEMPLATE CLASS numeric_limits
97 template<class _Ty>
98     class numeric_limits
99         : public _Num_base
100     {    // numeric limits for arbitrary type _Ty (say little or nothing)
101 public:
102     static _Ty (__CRTDECL min)() _THROW0()
103         {    // return minimum value
104         return (_Ty(0));
105         }
106
107     static _Ty (__CRTDECL max)() _THROW0()
108         {    // return maximum value
109         return (_Ty(0));
110         }
111
112     static _Ty __CRTDECL epsilon() _THROW0()
113         {    // return smallest effective increment from 1.0
114         return (_Ty(0));
115         }
116
117     static _Ty __CRTDECL round_error() _THROW0()
118         {    // return largest rounding error
119         return (_Ty(0));
120         }
121
122     static _Ty __CRTDECL denorm_min() _THROW0()
123         {    // return minimum denormalized value
124         return (_Ty(0));
125         }
126
127     static _Ty __CRTDECL infinity() _THROW0()
128         {    // return positive infinity
129         return (_Ty(0));
130         }
131
132     static _Ty __CRTDECL quiet_NaN() _THROW0()
133         {    // return non-signaling NaN
134         return (_Ty(0));
135         }
136
137     static _Ty __CRTDECL signaling_NaN() _THROW0()
138         {    // return signaling NaN
139         return (_Ty(0));
140         }
141     };
142
143         // STRUCT _Num_int_base
144 struct _CRTIMP2_PURE _Num_int_base
145     : public _Num_base
146     {    // base for integer types
147     _STCONS(bool, is_bounded, true);
148     _STCONS(bool, is_exact, true);
149     _STCONS(bool, is_integer, true);
150     _STCONS(bool, is_modulo, true);
151     _STCONS(bool, is_specialized, true);
152     _STCONS(int, radix, 2);
153     };
154
155 _STCONSDEF(_Num_int_base, bool, is_bounded)
156 _STCONSDEF(_Num_int_base, bool, is_exact)
157 _STCONSDEF(_Num_int_base, bool, is_integer)
158 _STCONSDEF(_Num_int_base, bool, is_modulo)
159 _STCONSDEF(_Num_int_base, bool, is_specialized)
160 _STCONSDEF(_Num_int_base, int, radix)
161
162         // STRUCT _Num_float_base
163 struct _CRTIMP2_PURE _Num_float_base
164     : public _Num_base
165     {    // base for floating-point types
166     _STCONS(float_denorm_style, has_denorm, denorm_present);
167     _STCONS(bool, has_denorm_loss, true);
168     _STCONS(bool, has_infinity, true);
169     _STCONS(bool, has_quiet_NaN, true);
170     _STCONS(bool, has_signaling_NaN, true);
171     _STCONS(bool, is_bounded, true);
172     _STCONS(bool, is_exact, false);
173     _STCONS(bool, is_iec559, true);
174     _STCONS(bool, is_integer, false);
175     _STCONS(bool, is_modulo, false);
176     _STCONS(bool, is_signed, true);
177     _STCONS(bool, is_specialized, true);
178     _STCONS(bool, tinyness_before, true);
179     _STCONS(bool, traps, true);
180     _STCONS(float_round_style, round_style, round_to_nearest);
181     _STCONS(int, radix, FLT_RADIX);
182     };
183
184 _STCONSDEF(_Num_float_base, float_denorm_style, has_denorm)
185 _STCONSDEF(_Num_float_base, bool, has_denorm_loss)
186 _STCONSDEF(_Num_float_base, bool, has_infinity)
187 _STCONSDEF(_Num_float_base, bool, has_quiet_NaN)
188 _STCONSDEF(_Num_float_base, bool, has_signaling_NaN)
189 _STCONSDEF(_Num_float_base, bool, is_bounded)
190 _STCONSDEF(_Num_float_base, bool, is_exact)
191 _STCONSDEF(_Num_float_base, bool, is_iec559)
192 _STCONSDEF(_Num_float_base, bool, is_integer)
193 _STCONSDEF(_Num_float_base, bool, is_modulo)
194 _STCONSDEF(_Num_float_base, bool, is_signed)
195 _STCONSDEF(_Num_float_base, bool, is_specialized)
196 _STCONSDEF(_Num_float_base, bool, tinyness_before)
197 _STCONSDEF(_Num_float_base, bool, traps)
198 _STCONSDEF(_Num_float_base, float_round_style, round_style)
199 _STCONSDEF(_Num_float_base, int, radix)
200
201         // CLASS numeric_limits<char>
202 template<> class _CRTIMP2_PURE numeric_limits<char>
203     : public _Num_int_base
204     {    // limits for type char
205 public:
206     typedef char _Ty;
207
208     static _Ty (__CRTDECL min)() _THROW0()
209         {    // return minimum value
210         return (CHAR_MIN);
211         }
212
213     static _Ty (__CRTDECL max)() _THROW0()
214         {    // return maximum value
215         return (CHAR_MAX);
216         }
217
218     static _Ty __CRTDECL epsilon() _THROW0()
219         {    // return smallest effective increment from 1.0
220         return (0);
221         }
222
223     static _Ty __CRTDECL round_error() _THROW0()
224         {    // return largest rounding error
225         return (0);
226         }
227
228     static _Ty __CRTDECL denorm_min() _THROW0()
229         {    // return minimum denormalized value
230         return (0);
231         }
232
233     static _Ty __CRTDECL infinity() _THROW0()
234         {    // return positive infinity
235         return (0);
236         }
237
238     static _Ty __CRTDECL quiet_NaN() _THROW0()
239         {    // return non-signaling NaN
240         return (0);
241         }
242
243     static _Ty __CRTDECL signaling_NaN() _THROW0()
244         {    // return signaling NaN
245         return (0);
246         }
247
248     _STCONS(bool, is_signed, CHAR_MIN != 0);
249     _STCONS(int, digits, CHAR_BIT - (CHAR_MIN != 0 ? 1 : 0));
250     _STCONS(int, digits10, (CHAR_BIT - (CHAR_MIN != 0 ? 1 : 0))
251         * 301L / 1000);
252     };
253
254 _STCONSDEF(numeric_limits<char>, bool, is_signed)
255 _STCONSDEF(numeric_limits<char>, int, digits)
256 _STCONSDEF(numeric_limits<char>, int, digits10)
257
258  #ifdef _NATIVE_WCHAR_T_DEFINED
259         // CLASS numeric_limits<wchar_t>
260 template<> class _CRTIMP2_PURE numeric_limits<wchar_t>
261     : public _Num_int_base
262     {    // limits for type wchar_t
263 public:
264     typedef wchar_t _Ty;
265
266     static _Ty (__CRTDECL min)() _THROW0()
267         {    // return minimum value
268         return ((_Ty)WCHAR_MIN);
269         }
270
271     static _Ty (__CRTDECL max)() _THROW0()
272         {    // return maximum value
273         return ((_Ty)WCHAR_MAX);
274         }
275
276     static _Ty __CRTDECL epsilon() _THROW0()
277         {    // return smallest effective increment from 1.0
278         return (0);
279         }
280
281     static _Ty __CRTDECL round_error() _THROW0()
282         {    // return largest rounding error
283         return (0);
284         }
285
286     static _Ty __CRTDECL denorm_min() _THROW0()
287         {    // return minimum denormalized value
288         return (0);
289         }
290
291     static _Ty __CRTDECL infinity() _THROW0()
292         {    // return positive infinity
293         return (0);
294         }
295
296     static _Ty __CRTDECL quiet_NaN() _THROW0()
297         {    // return non-signaling NaN
298         return (0);
299         }
300
301     static _Ty __CRTDECL signaling_NaN() _THROW0()
302         {    // return signaling NaN
303         return (0);
304         }
305
306     _STCONS(bool, is_signed, WCHAR_MIN != 0);
307     _STCONS(int, digits, CHAR_BIT * sizeof (wchar_t)
308         - (WCHAR_MIN != 0 ? 1 : 0));
Lines 309 ... 780 are skipped.
781         {    // return minimum value
782         return (0);
783         }
784
785     static _Ty (__CRTDECL max)() _THROW0()
786         {    // return maximum value
787         return (ULONG_MAX);
788         }
789
790     static _Ty __CRTDECL epsilon() _THROW0()
791         {    // return smallest effective increment from 1.0
792         return (0);
793         }
794
795     static _Ty __CRTDECL round_error() _THROW0()
796         {    // return largest rounding error
797         return (0);
798         }
799
800     static _Ty __CRTDECL denorm_min() _THROW0()
801         {    // return minimum denormalized value
802         return (0);
803         }
804
805     static _Ty __CRTDECL infinity() _THROW0()
806         {    // return positive infinity
807         return (0);
808         }
809
810     static _Ty __CRTDECL quiet_NaN() _THROW0()
811         {    // return non-signaling NaN
812         return (0);
813         }
814
815     static _Ty __CRTDECL signaling_NaN() _THROW0()
816         {    // return signaling NaN
817         return (0);
818         }
819
820     _STCONS(bool, is_signed, false);
821     _STCONS(int, digits, CHAR_BIT * sizeof (unsigned long));
822     _STCONS(int, digits10, (CHAR_BIT * sizeof (unsigned long))
823         * 301L / 1000);
824     };
825
826 _STCONSDEF(numeric_limits<unsigned long>, bool, is_signed)
827 _STCONSDEF(numeric_limits<unsigned long>, int, digits)
828 _STCONSDEF(numeric_limits<unsigned long>, int, digits10)
829
830  #ifdef _LONGLONG
831         // CLASS numeric_limits<_LONGLONG>
832 template<> class _CRTIMP2_PURE numeric_limits<_LONGLONG>
833     : public _Num_int_base
834     {    // limits for type long long
835 public:
836     typedef _LONGLONG _Ty;
837
838     static _Ty (__CRTDECL min)() _THROW0()
839         {    // return minimum value
840         return (-_LLONG_MAX - _C2);
841         }
842
843     static _Ty (__CRTDECL max)() _THROW0()
844         {    // return maximum value
845         return (_LLONG_MAX);
846         }
847
848     static _Ty __CRTDECL epsilon() _THROW0()
849         {    // return smallest effective increment from 1.0
850         return (0);
851         }
852
853     static _Ty __CRTDECL round_error() _THROW0()
854         {    // return largest rounding error
855         return (0);
856         }
857
858     static _Ty __CRTDECL denorm_min() _THROW0()
859         {    // return minimum denormalized value
860         return (0);
861         }
862
863     static _Ty __CRTDECL infinity() _THROW0()
864         {    // return positive infinity
865         return (0);
866         }
867
868     static _Ty __CRTDECL quiet_NaN() _THROW0()
869         {    // return non-signaling NaN
870         return (0);
871         }
872
873     static _Ty __CRTDECL signaling_NaN() _THROW0()
874         {    // return signaling NaN
875         return (0);
876         }
877
878     _STCONS(bool, is_signed, true);
879     _STCONS(int, digits, CHAR_BIT * sizeof (_LONGLONG) - 1);
880     _STCONS(int, digits10, (CHAR_BIT * sizeof (_LONGLONG) - 1)
Lines 881 ... 1084 are skipped.
1085         return (LDBL_MAX);
1086         }
1087
1088     static _Ty __CRTDECL epsilon() _THROW0()
1089         {    // return smallest effective increment from 1.0
1090         return (LDBL_EPSILON);
1091         }
1092
1093     static _Ty __CRTDECL round_error() _THROW0()
1094         {    // return largest rounding error
1095         return (0.5);
1096         }
1097
1098     static _Ty __CRTDECL denorm_min() _THROW0()
1099         {    // return minimum denormalized value
1100         return (::_LDenorm._Long_double);
1101         }
1102
1103     static _Ty __CRTDECL infinity() _THROW0()
1104         {    // return positive infinity
1105         return (::_LInf._Long_double);
1106         }
1107
1108     static _Ty __CRTDECL quiet_NaN() _THROW0()
1109         {    // return non-signaling NaN
1110         return (::_LNan._Long_double);
1111         }
1112
1113     static _Ty __CRTDECL signaling_NaN() _THROW0()
1114         {    // return signaling NaN
1115         return (::_LSnan._Long_double);
1116         }
1117
1118     _STCONS(int, digits, LDBL_MANT_DIG);
1119     _STCONS(int, digits10, LDBL_DIG);
1120     _STCONS(int, max_exponent, (int)LDBL_MAX_EXP);
1121     _STCONS(int, max_exponent10, (int)LDBL_MAX_10_EXP);
1122     _STCONS(int, min_exponent, (int)LDBL_MIN_EXP);
1123     _STCONS(int, min_exponent10, (int)LDBL_MIN_10_EXP);
1124     };
1125
1126 _STCONSDEF(numeric_limits<long double>, int, digits)
1127 _STCONSDEF(numeric_limits<long double>, int, digits10)
1128 _STCONSDEF(numeric_limits<long double>, int, max_exponent)
1129 _STCONSDEF(numeric_limits<long double>, int, max_exponent10)
1130 _STCONSDEF(numeric_limits<long double>, int, min_exponent)
1131 _STCONSDEF(numeric_limits<long double>, int, min_exponent10)
1132
1133 _STD_END
1134 #ifdef _MSC_VER
1135  #pragma warning(pop)
1136  #pragma pack(pop)
1137 #endif  /* _MSC_VER */
1138
1139 #endif /* RC_INVOKED */
1140 #endif /* _LIMITS_ */
1141
1142 /*
1143  * Copyright (c) 1992-2006 by P.J. Plauger.  ALL RIGHTS RESERVED.
1144  * Consult your license regarding permissions and restrictions.
1145  V5.02:0009 */
1146