Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

450 lines
14 KiB

  1. // limits standard header
  2. #ifndef _LIMITS_
  3. #define _LIMITS_
  4. #include <ymath.h>
  5. #include <cfloat>
  6. #include <climits>
  7. #include <cmath>
  8. #include <cwchar>
  9. #include <xstddef>
  10. #ifdef _MSC_VER
  11. #pragma pack(push,8)
  12. #endif /* _MSC_VER */
  13. // ASSUMES:
  14. // wraparound 2's complement integer arithmetic w/o traps
  15. // all CHAR_BITs of each byte used by integers
  16. // IEC559 (IEEE 754) floating-point arithmetic
  17. // floating-point errors can trap
  18. // tinyness detected before floating-point rounding
  19. _STD_BEGIN
  20. // ENUM float_round_style
  21. typedef enum {
  22. round_indeterminate = -1, round_toward_zero = 0,
  23. round_to_nearest = 1, round_toward_infinity = 2,
  24. round_toward_neg_infinity = 3} float_round_style;
  25. // STRUCT _Num_base
  26. struct _CRTIMP _Num_base {
  27. _STCONS(bool, has_denorm, false);
  28. _STCONS(bool, has_denorm_loss, false);
  29. _STCONS(bool, has_infinity, false);
  30. _STCONS(bool, has_quiet_NaN, false);
  31. _STCONS(bool, has_signaling_NaN, false);
  32. _STCONS(bool, is_bounded, false);
  33. _STCONS(bool, is_exact, false);
  34. _STCONS(bool, is_iec559, false);
  35. _STCONS(bool, is_integer, false);
  36. _STCONS(bool, is_modulo, false);
  37. _STCONS(bool, is_signed, false);
  38. _STCONS(bool, is_specialized, false);
  39. _STCONS(bool, tinyness_before, false);
  40. _STCONS(bool, traps, false);
  41. _STCONS(float_round_style, round_style, round_toward_zero);
  42. _STCONS(int, digits, 0);
  43. _STCONS(int, digits10, 0);
  44. _STCONS(int, max_exponent, 0);
  45. _STCONS(int, max_exponent10, 0);
  46. _STCONS(int, min_exponent, 0);
  47. _STCONS(int, min_exponent10, 0);
  48. _STCONS(int, radix, 0);
  49. };
  50. // TEMPLATE CLASS numeric_limits
  51. template<class _Ty> class numeric_limits : public _Num_base {
  52. public:
  53. static _Ty (__cdecl min)() _THROW0()
  54. {return (_Ty(0)); }
  55. static _Ty (__cdecl max)() _THROW0()
  56. {return (_Ty(0)); }
  57. static _Ty __cdecl epsilon() _THROW0()
  58. {return (_Ty(0)); }
  59. static _Ty __cdecl round_error() _THROW0()
  60. {return (_Ty(0)); }
  61. static _Ty __cdecl denorm_min() _THROW0()
  62. {return (_Ty(0)); }
  63. static _Ty __cdecl infinity() _THROW0()
  64. {return (_Ty(0)); }
  65. static _Ty __cdecl quiet_NaN() _THROW0()
  66. {return (_Ty(0)); }
  67. static _Ty __cdecl signaling_NaN() _THROW0()
  68. {return (_Ty(0)); }
  69. };
  70. // STRUCT _Num_int_base
  71. struct _CRTIMP _Num_int_base : public _Num_base {
  72. _STCONS(bool, is_bounded, true);
  73. _STCONS(bool, is_exact, true);
  74. _STCONS(bool, is_integer, true);
  75. _STCONS(bool, is_modulo, true);
  76. _STCONS(bool, is_specialized, true);
  77. _STCONS(int, radix, 2);
  78. };
  79. // STRUCT _Num_float_base
  80. struct _CRTIMP _Num_float_base : public _Num_base {
  81. _STCONS(bool, has_denorm, true);
  82. _STCONS(bool, has_denorm_loss, true);
  83. _STCONS(bool, has_infinity, true);
  84. _STCONS(bool, has_quiet_NaN, true);
  85. _STCONS(bool, has_signaling_NaN, true);
  86. _STCONS(bool, is_bounded, true);
  87. _STCONS(bool, is_exact, false);
  88. _STCONS(bool, is_iec559, true);
  89. _STCONS(bool, is_integer, false);
  90. _STCONS(bool, is_modulo, false);
  91. _STCONS(bool, is_signed, true);
  92. _STCONS(bool, is_specialized, true);
  93. _STCONS(bool, tinyness_before, true);
  94. _STCONS(bool, traps, true);
  95. _STCONS(float_round_style, round_style, round_to_nearest);
  96. _STCONS(int, radix, FLT_RADIX);
  97. };
  98. // CLASS numeric_limits<char>
  99. template <>
  100. class _CRTIMP numeric_limits<char> : public _Num_int_base {
  101. public:
  102. typedef char _Ty;
  103. static _Ty (__cdecl min)() _THROW0()
  104. {return (CHAR_MIN); }
  105. static _Ty (__cdecl max)() _THROW0()
  106. {return (CHAR_MAX); }
  107. static _Ty __cdecl epsilon() _THROW0()
  108. {return (0); }
  109. static _Ty __cdecl round_error() _THROW0()
  110. {return (0); }
  111. static _Ty __cdecl denorm_min() _THROW0()
  112. {return (0); }
  113. static _Ty __cdecl infinity() _THROW0()
  114. {return (0); }
  115. static _Ty __cdecl quiet_NaN() _THROW0()
  116. {return (0); }
  117. static _Ty __cdecl signaling_NaN() _THROW0()
  118. {return (0); }
  119. _STCONS(bool, is_signed, CHAR_MIN < 0);
  120. _STCONS(int, digits, CHAR_BIT - (CHAR_MIN < 0 ? 1 : 0));
  121. _STCONS(int, digits10, (CHAR_BIT - (CHAR_MIN < 0 ? 1 : 0))
  122. * 301L / 1000);
  123. };
  124. // CLASS numeric_limits<_Bool>
  125. template <>
  126. class _CRTIMP numeric_limits<_Bool> : public _Num_int_base {
  127. public:
  128. typedef bool _Ty;
  129. static _Ty (__cdecl min)() _THROW0()
  130. {return (false); }
  131. static _Ty (__cdecl max)() _THROW0()
  132. {return (true); }
  133. static _Ty __cdecl epsilon() _THROW0()
  134. {return (0); }
  135. static _Ty __cdecl round_error() _THROW0()
  136. {return (0); }
  137. static _Ty __cdecl denorm_min() _THROW0()
  138. {return (0); }
  139. static _Ty __cdecl infinity() _THROW0()
  140. {return (0); }
  141. static _Ty __cdecl quiet_NaN() _THROW0()
  142. {return (0); }
  143. static _Ty __cdecl signaling_NaN() _THROW0()
  144. {return (0); }
  145. _STCONS(bool, is_signed, false);
  146. _STCONS(int, digits, 1);
  147. _STCONS(int, digits10, 0);
  148. };
  149. // CLASS numeric_limits<signed char>
  150. template <>
  151. class _CRTIMP numeric_limits<signed char> : public _Num_int_base {
  152. public:
  153. typedef signed char _Ty;
  154. static _Ty (__cdecl min)() _THROW0()
  155. {return (SCHAR_MIN); }
  156. static _Ty (__cdecl max)() _THROW0()
  157. {return (SCHAR_MAX); }
  158. static _Ty __cdecl epsilon() _THROW0()
  159. {return (0); }
  160. static _Ty __cdecl round_error() _THROW0()
  161. {return (0); }
  162. static _Ty __cdecl denorm_min() _THROW0()
  163. {return (0); }
  164. static _Ty __cdecl infinity() _THROW0()
  165. {return (0); }
  166. static _Ty __cdecl quiet_NaN() _THROW0()
  167. {return (0); }
  168. static _Ty __cdecl signaling_NaN() _THROW0()
  169. {return (0); }
  170. _STCONS(bool, is_signed, true);
  171. _STCONS(int, digits, CHAR_BIT - 1);
  172. _STCONS(int, digits10, (CHAR_BIT - 1) * 301L / 1000);
  173. };
  174. // CLASS numeric_limits<unsigned char>
  175. template <>
  176. class _CRTIMP numeric_limits<unsigned char> : public _Num_int_base {
  177. public:
  178. typedef unsigned char _Ty;
  179. static _Ty (__cdecl min)() _THROW0()
  180. {return (0); }
  181. static _Ty (__cdecl max)() _THROW0()
  182. {return (UCHAR_MAX); }
  183. static _Ty __cdecl epsilon() _THROW0()
  184. {return (0); }
  185. static _Ty __cdecl round_error() _THROW0()
  186. {return (0); }
  187. static _Ty __cdecl denorm_min() _THROW0()
  188. {return (0); }
  189. static _Ty __cdecl infinity() _THROW0()
  190. {return (0); }
  191. static _Ty __cdecl quiet_NaN() _THROW0()
  192. {return (0); }
  193. static _Ty __cdecl signaling_NaN() _THROW0()
  194. {return (0); }
  195. _STCONS(bool, is_signed, false);
  196. _STCONS(int, digits, CHAR_BIT);
  197. _STCONS(int, digits10, (CHAR_BIT) * 301L / 1000);
  198. };
  199. // CLASS numeric_limits<short>
  200. template <>
  201. class _CRTIMP numeric_limits<short> : public _Num_int_base {
  202. public:
  203. typedef short _Ty;
  204. static _Ty (__cdecl min)() _THROW0()
  205. {return (SHRT_MIN); }
  206. static _Ty (__cdecl max)() _THROW0()
  207. {return (SHRT_MAX); }
  208. static _Ty __cdecl epsilon() _THROW0()
  209. {return (0); }
  210. static _Ty __cdecl round_error() _THROW0()
  211. {return (0); }
  212. static _Ty __cdecl denorm_min() _THROW0()
  213. {return (0); }
  214. static _Ty __cdecl infinity() _THROW0()
  215. {return (0); }
  216. static _Ty __cdecl quiet_NaN() _THROW0()
  217. {return (0); }
  218. static _Ty __cdecl signaling_NaN() _THROW0()
  219. {return (0); }
  220. _STCONS(bool, is_signed, true);
  221. _STCONS(int, digits, CHAR_BIT * sizeof (short) - 1);
  222. _STCONS(int, digits10, (CHAR_BIT * sizeof (short) - 1)
  223. * 301L / 1000);
  224. };
  225. // CLASS numeric_limits<unsigned short>
  226. template <>
  227. class _CRTIMP numeric_limits<unsigned short> : public _Num_int_base {
  228. public:
  229. typedef unsigned short _Ty;
  230. static _Ty (__cdecl min)() _THROW0()
  231. {return (0); }
  232. static _Ty (__cdecl max)() _THROW0()
  233. {return (USHRT_MAX); }
  234. static _Ty __cdecl epsilon() _THROW0()
  235. {return (0); }
  236. static _Ty __cdecl round_error() _THROW0()
  237. {return (0); }
  238. static _Ty __cdecl denorm_min() _THROW0()
  239. {return (0); }
  240. static _Ty __cdecl infinity() _THROW0()
  241. {return (0); }
  242. static _Ty __cdecl quiet_NaN() _THROW0()
  243. {return (0); }
  244. static _Ty __cdecl signaling_NaN() _THROW0()
  245. {return (0); }
  246. _STCONS(bool, is_signed, false);
  247. _STCONS(int, digits, CHAR_BIT * sizeof (unsigned short));
  248. _STCONS(int, digits10, (CHAR_BIT * sizeof (unsigned short))
  249. * 301L / 1000);
  250. };
  251. // CLASS numeric_limits<int>
  252. template <>
  253. class _CRTIMP numeric_limits<int> : public _Num_int_base {
  254. public:
  255. typedef int _Ty;
  256. static _Ty (__cdecl min)() _THROW0()
  257. {return (INT_MIN); }
  258. static _Ty (__cdecl max)() _THROW0()
  259. {return (INT_MAX); }
  260. static _Ty __cdecl epsilon() _THROW0()
  261. {return (0); }
  262. static _Ty __cdecl round_error() _THROW0()
  263. {return (0); }
  264. static _Ty __cdecl denorm_min() _THROW0()
  265. {return (0); }
  266. static _Ty __cdecl infinity() _THROW0()
  267. {return (0); }
  268. static _Ty __cdecl quiet_NaN() _THROW0()
  269. {return (0); }
  270. static _Ty __cdecl signaling_NaN() _THROW0()
  271. {return (0); }
  272. _STCONS(bool, is_signed, true);
  273. _STCONS(int, digits, CHAR_BIT * sizeof (int) - 1);
  274. _STCONS(int, digits10, (CHAR_BIT * sizeof (int) - 1)
  275. * 301L / 1000);
  276. };
  277. // CLASS numeric_limits<unsigned int>
  278. template <>
  279. class _CRTIMP numeric_limits<unsigned int> : public _Num_int_base {
  280. public:
  281. typedef unsigned int _Ty;
  282. static _Ty (__cdecl min)() _THROW0()
  283. {return (0); }
  284. static _Ty (__cdecl max)() _THROW0()
  285. {return (UINT_MAX); }
  286. static _Ty __cdecl epsilon() _THROW0()
  287. {return (0); }
  288. static _Ty __cdecl round_error() _THROW0()
  289. {return (0); }
  290. static _Ty __cdecl denorm_min() _THROW0()
  291. {return (0); }
  292. static _Ty __cdecl infinity() _THROW0()
  293. {return (0); }
  294. static _Ty __cdecl quiet_NaN() _THROW0()
  295. {return (0); }
  296. static _Ty __cdecl signaling_NaN() _THROW0()
  297. {return (0); }
  298. _STCONS(bool, is_signed, false);
  299. _STCONS(int, digits, CHAR_BIT * sizeof (unsigned int));
  300. _STCONS(int, digits10, (CHAR_BIT * sizeof (unsigned int))
  301. * 301L / 1000);
  302. };
  303. // CLASS numeric_limits<long>
  304. template <>
  305. class _CRTIMP numeric_limits<long> : public _Num_int_base {
  306. public:
  307. typedef long _Ty;
  308. static _Ty (__cdecl min)() _THROW0()
  309. {return (LONG_MIN); }
  310. static _Ty (__cdecl max)() _THROW0()
  311. {return (LONG_MAX); }
  312. static _Ty __cdecl epsilon() _THROW0()
  313. {return (0); }
  314. static _Ty __cdecl round_error() _THROW0()
  315. {return (0); }
  316. static _Ty __cdecl denorm_min() _THROW0()
  317. {return (0); }
  318. static _Ty __cdecl infinity() _THROW0()
  319. {return (0); }
  320. static _Ty __cdecl quiet_NaN() _THROW0()
  321. {return (0); }
  322. static _Ty __cdecl signaling_NaN() _THROW0()
  323. {return (0); }
  324. _STCONS(bool, is_signed, true);
  325. _STCONS(int, digits, CHAR_BIT * sizeof (long) - 1);
  326. _STCONS(int, digits10, (CHAR_BIT * sizeof (long) - 1)
  327. * 301L / 1000);
  328. };
  329. // CLASS numeric_limits<unsigned long>
  330. template <>
  331. class _CRTIMP numeric_limits<unsigned long> : public _Num_int_base {
  332. public:
  333. typedef unsigned long _Ty;
  334. static _Ty (__cdecl min)() _THROW0()
  335. {return (0); }
  336. static _Ty (__cdecl max)() _THROW0()
  337. {return (ULONG_MAX); }
  338. static _Ty __cdecl epsilon() _THROW0()
  339. {return (0); }
  340. static _Ty __cdecl round_error() _THROW0()
  341. {return (0); }
  342. static _Ty __cdecl denorm_min() _THROW0()
  343. {return (0); }
  344. static _Ty __cdecl infinity() _THROW0()
  345. {return (0); }
  346. static _Ty __cdecl quiet_NaN() _THROW0()
  347. {return (0); }
  348. static _Ty __cdecl signaling_NaN() _THROW0()
  349. {return (0); }
  350. _STCONS(bool, is_signed, false);
  351. _STCONS(int, digits, CHAR_BIT * sizeof (unsigned long));
  352. _STCONS(int, digits10, (CHAR_BIT * sizeof (unsigned long))
  353. * 301L / 1000);
  354. };
  355. // CLASS numeric_limits<float>
  356. template <>
  357. class _CRTIMP numeric_limits<float> : public _Num_float_base {
  358. public:
  359. typedef float _Ty;
  360. static _Ty (__cdecl min)() _THROW0()
  361. {return (FLT_MIN); }
  362. static _Ty (__cdecl max)() _THROW0()
  363. {return (FLT_MAX); }
  364. static _Ty __cdecl epsilon() _THROW0()
  365. {return (FLT_EPSILON); }
  366. static _Ty __cdecl round_error() _THROW0()
  367. {return (0.5); }
  368. static _Ty __cdecl denorm_min() _THROW0()
  369. {return (_FDenorm._F); }
  370. static _Ty __cdecl infinity() _THROW0()
  371. {return (_FInf._F); }
  372. static _Ty __cdecl quiet_NaN() _THROW0()
  373. {return (_FNan._F); }
  374. static _Ty __cdecl signaling_NaN() _THROW0()
  375. {return (_FSnan._F); }
  376. _STCONS(int, digits, FLT_MANT_DIG);
  377. _STCONS(int, digits10, FLT_DIG);
  378. _STCONS(int, max_exponent, FLT_MAX_EXP);
  379. _STCONS(int, max_exponent10, FLT_MAX_10_EXP);
  380. _STCONS(int, min_exponent, FLT_MIN_EXP);
  381. _STCONS(int, min_exponent10, FLT_MIN_10_EXP);
  382. };
  383. // CLASS numeric_limits<double>
  384. template <>
  385. class _CRTIMP numeric_limits<double> : public _Num_float_base {
  386. public:
  387. typedef double _Ty;
  388. static _Ty (__cdecl min)() _THROW0()
  389. {return (DBL_MIN); }
  390. static _Ty (__cdecl max)() _THROW0()
  391. {return (DBL_MAX); }
  392. static _Ty __cdecl epsilon() _THROW0()
  393. {return (DBL_EPSILON); }
  394. static _Ty __cdecl round_error() _THROW0()
  395. {return (0.5); }
  396. static _Ty __cdecl denorm_min() _THROW0()
  397. {return (_Denorm._D); }
  398. static _Ty __cdecl infinity() _THROW0()
  399. {return (_Inf._D); }
  400. static _Ty __cdecl quiet_NaN() _THROW0()
  401. {return (_Nan._D); }
  402. static _Ty __cdecl signaling_NaN() _THROW0()
  403. {return (_Snan._D); }
  404. _STCONS(int, digits, DBL_MANT_DIG);
  405. _STCONS(int, digits10, DBL_DIG);
  406. _STCONS(int, max_exponent, DBL_MAX_EXP);
  407. _STCONS(int, max_exponent10, DBL_MAX_10_EXP);
  408. _STCONS(int, min_exponent, DBL_MIN_EXP);
  409. _STCONS(int, min_exponent10, DBL_MIN_10_EXP);
  410. };
  411. // CLASS numeric_limits<long double>
  412. template <>
  413. class _CRTIMP numeric_limits<long double> : public _Num_float_base {
  414. public:
  415. typedef long double _Ty;
  416. static _Ty (__cdecl min)() _THROW0()
  417. {return (LDBL_MIN); }
  418. static _Ty (__cdecl max)() _THROW0()
  419. {return (LDBL_MAX); }
  420. static _Ty __cdecl epsilon() _THROW0()
  421. {return (LDBL_EPSILON); }
  422. static _Ty __cdecl round_error() _THROW0()
  423. {return (0.5); }
  424. static _Ty __cdecl denorm_min() _THROW0()
  425. {return (_LDenorm._L); }
  426. static _Ty __cdecl infinity() _THROW0()
  427. {return (_LInf._L); }
  428. static _Ty __cdecl quiet_NaN() _THROW0()
  429. {return (_LNan._L); }
  430. static _Ty __cdecl signaling_NaN() _THROW0()
  431. {return (_LSnan._L); }
  432. _STCONS(int, digits, LDBL_MANT_DIG);
  433. _STCONS(int, digits10, LDBL_DIG);
  434. _STCONS(int, max_exponent, LDBL_MAX_EXP);
  435. _STCONS(int, max_exponent10, LDBL_MAX_10_EXP);
  436. _STCONS(int, min_exponent, LDBL_MIN_EXP);
  437. _STCONS(int, min_exponent10, LDBL_MIN_10_EXP);
  438. };
  439. _STD_END
  440. #ifdef _MSC_VER
  441. #pragma pack(pop)
  442. #endif /* _MSC_VER */
  443. #endif /* _LIMITS_ */
  444. /*
  445. * Copyright (c) 1995 by P.J. Plauger. ALL RIGHTS RESERVED.
  446. * Consult your license regarding permissions and restrictions.
  447. */