limits 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. // The template and inlines for the numeric_limits classes. -*- C++ -*-
  2. // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
  3. // 2008, 2009 Free Software Foundation, Inc.
  4. //
  5. // This file is part of the GNU ISO C++ Library. This library is free
  6. // software; you can redistribute it and/or modify it under the
  7. // terms of the GNU General Public License as published by the
  8. // Free Software Foundation; either version 3, or (at your option)
  9. // any later version.
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. // Under Section 7 of GPL version 3, you are granted additional
  15. // permissions described in the GCC Runtime Library Exception, version
  16. // 3.1, as published by the Free Software Foundation.
  17. // You should have received a copy of the GNU General Public License and
  18. // a copy of the GCC Runtime Library Exception along with this program;
  19. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  20. // <http://www.gnu.org/licenses/>.
  21. /** @file limits
  22. * This is a Standard C++ Library header.
  23. */
  24. // Note: this is not a conforming implementation.
  25. // Written by Gabriel Dos Reis <gdr@codesourcery.com>
  26. //
  27. // ISO 14882:1998
  28. // 18.2.1
  29. //
  30. #ifndef _GLIBCXX_NUMERIC_LIMITS
  31. #define _GLIBCXX_NUMERIC_LIMITS 1
  32. #pragma GCC system_header
  33. #include <bits/c++config.h>
  34. //
  35. // The numeric_limits<> traits document implementation-defined aspects
  36. // of fundamental arithmetic data types (integers and floating points).
  37. // From Standard C++ point of view, there are 13 such types:
  38. // * integers
  39. // bool (1)
  40. // char, signed char, unsigned char (3)
  41. // short, unsigned short (2)
  42. // int, unsigned (2)
  43. // long, unsigned long (2)
  44. //
  45. // * floating points
  46. // float (1)
  47. // double (1)
  48. // long double (1)
  49. //
  50. // GNU C++ understands (where supported by the host C-library)
  51. // * integer
  52. // long long, unsigned long long (2)
  53. //
  54. // which brings us to 15 fundamental arithmetic data types in GNU C++.
  55. //
  56. //
  57. // Since a numeric_limits<> is a bit tricky to get right, we rely on
  58. // an interface composed of macros which should be defined in config/os
  59. // or config/cpu when they differ from the generic (read arbitrary)
  60. // definitions given here.
  61. //
  62. // These values can be overridden in the target configuration file.
  63. // The default values are appropriate for many 32-bit targets.
  64. // GCC only intrinsically supports modulo integral types. The only remaining
  65. // integral exceptional values is division by zero. Only targets that do not
  66. // signal division by zero in some "hard to ignore" way should use false.
  67. #ifndef __glibcxx_integral_traps
  68. # define __glibcxx_integral_traps true
  69. #endif
  70. // float
  71. //
  72. // Default values. Should be overridden in configuration files if necessary.
  73. #ifndef __glibcxx_float_has_denorm_loss
  74. # define __glibcxx_float_has_denorm_loss false
  75. #endif
  76. #ifndef __glibcxx_float_traps
  77. # define __glibcxx_float_traps false
  78. #endif
  79. #ifndef __glibcxx_float_tinyness_before
  80. # define __glibcxx_float_tinyness_before false
  81. #endif
  82. // double
  83. // Default values. Should be overridden in configuration files if necessary.
  84. #ifndef __glibcxx_double_has_denorm_loss
  85. # define __glibcxx_double_has_denorm_loss false
  86. #endif
  87. #ifndef __glibcxx_double_traps
  88. # define __glibcxx_double_traps false
  89. #endif
  90. #ifndef __glibcxx_double_tinyness_before
  91. # define __glibcxx_double_tinyness_before false
  92. #endif
  93. // long double
  94. // Default values. Should be overridden in configuration files if necessary.
  95. #ifndef __glibcxx_long_double_has_denorm_loss
  96. # define __glibcxx_long_double_has_denorm_loss false
  97. #endif
  98. #ifndef __glibcxx_long_double_traps
  99. # define __glibcxx_long_double_traps false
  100. #endif
  101. #ifndef __glibcxx_long_double_tinyness_before
  102. # define __glibcxx_long_double_tinyness_before false
  103. #endif
  104. // You should not need to define any macros below this point.
  105. #define __glibcxx_signed(T) ((T)(-1) < 0)
  106. #define __glibcxx_min(T) \
  107. (__glibcxx_signed (T) ? (T)1 << __glibcxx_digits (T) : (T)0)
  108. #define __glibcxx_max(T) \
  109. (__glibcxx_signed (T) ? \
  110. (((((T)1 << (__glibcxx_digits (T) - 1)) - 1) << 1) + 1) : ~(T)0)
  111. #define __glibcxx_digits(T) \
  112. (sizeof(T) * __CHAR_BIT__ - __glibcxx_signed (T))
  113. // The fraction 643/2136 approximates log10(2) to 7 significant digits.
  114. #define __glibcxx_digits10(T) \
  115. (__glibcxx_digits (T) * 643 / 2136)
  116. _GLIBCXX_BEGIN_NAMESPACE(std)
  117. /**
  118. * @brief Describes the rounding style for floating-point types.
  119. *
  120. * This is used in the std::numeric_limits class.
  121. */
  122. enum float_round_style
  123. {
  124. round_indeterminate = -1, ///< Self-explanatory.
  125. round_toward_zero = 0, ///< Self-explanatory.
  126. round_to_nearest = 1, ///< To the nearest representable value.
  127. round_toward_infinity = 2, ///< Self-explanatory.
  128. round_toward_neg_infinity = 3 ///< Self-explanatory.
  129. };
  130. /**
  131. * @brief Describes the denormalization for floating-point types.
  132. *
  133. * These values represent the presence or absence of a variable number
  134. * of exponent bits. This type is used in the std::numeric_limits class.
  135. */
  136. enum float_denorm_style
  137. {
  138. /// Indeterminate at compile time whether denormalized values are allowed.
  139. denorm_indeterminate = -1,
  140. /// The type does not allow denormalized values.
  141. denorm_absent = 0,
  142. /// The type allows denormalized values.
  143. denorm_present = 1
  144. };
  145. /**
  146. * @brief Part of std::numeric_limits.
  147. *
  148. * The @c static @c const members are usable as integral constant
  149. * expressions.
  150. *
  151. * @note This is a separate class for purposes of efficiency; you
  152. * should only access these members as part of an instantiation
  153. * of the std::numeric_limits class.
  154. */
  155. struct __numeric_limits_base
  156. {
  157. /** This will be true for all fundamental types (which have
  158. specializations), and false for everything else. */
  159. static const bool is_specialized = false;
  160. /** The number of @c radix digits that be represented without change: for
  161. integer types, the number of non-sign bits in the mantissa; for
  162. floating types, the number of @c radix digits in the mantissa. */
  163. static const int digits = 0;
  164. /** The number of base 10 digits that can be represented without change. */
  165. static const int digits10 = 0;
  166. /** True if the type is signed. */
  167. static const bool is_signed = false;
  168. /** True if the type is integer.
  169. * Is this supposed to be "if the type is integral"?
  170. */
  171. static const bool is_integer = false;
  172. /** True if the type uses an exact representation. "All integer types are
  173. exact, but not all exact types are integer. For example, rational and
  174. fixed-exponent representations are exact but not integer."
  175. [18.2.1.2]/15 */
  176. static const bool is_exact = false;
  177. /** For integer types, specifies the base of the representation. For
  178. floating types, specifies the base of the exponent representation. */
  179. static const int radix = 0;
  180. /** The minimum negative integer such that @c radix raised to the power of
  181. (one less than that integer) is a normalized floating point number. */
  182. static const int min_exponent = 0;
  183. /** The minimum negative integer such that 10 raised to that power is in
  184. the range of normalized floating point numbers. */
  185. static const int min_exponent10 = 0;
  186. /** The maximum positive integer such that @c radix raised to the power of
  187. (one less than that integer) is a representable finite floating point
  188. number. */
  189. static const int max_exponent = 0;
  190. /** The maximum positive integer such that 10 raised to that power is in
  191. the range of representable finite floating point numbers. */
  192. static const int max_exponent10 = 0;
  193. /** True if the type has a representation for positive infinity. */
  194. static const bool has_infinity = false;
  195. /** True if the type has a representation for a quiet (non-signaling)
  196. "Not a Number." */
  197. static const bool has_quiet_NaN = false;
  198. /** True if the type has a representation for a signaling
  199. "Not a Number." */
  200. static const bool has_signaling_NaN = false;
  201. /** See std::float_denorm_style for more information. */
  202. static const float_denorm_style has_denorm = denorm_absent;
  203. /** "True if loss of accuracy is detected as a denormalization loss,
  204. rather than as an inexact result." [18.2.1.2]/42 */
  205. static const bool has_denorm_loss = false;
  206. /** True if-and-only-if the type adheres to the IEC 559 standard, also
  207. known as IEEE 754. (Only makes sense for floating point types.) */
  208. static const bool is_iec559 = false;
  209. /** "True if the set of values representable by the type is finite. All
  210. built-in types are bounded, this member would be false for arbitrary
  211. precision types." [18.2.1.2]/54 */
  212. static const bool is_bounded = false;
  213. /** True if the type is @e modulo, that is, if it is possible to add two
  214. positive numbers and have a result that wraps around to a third number
  215. that is less. Typically false for floating types, true for unsigned
  216. integers, and true for signed integers. */
  217. static const bool is_modulo = false;
  218. /** True if trapping is implemented for this type. */
  219. static const bool traps = false;
  220. /** True if tininess is detected before rounding. (see IEC 559) */
  221. static const bool tinyness_before = false;
  222. /** See std::float_round_style for more information. This is only
  223. meaningful for floating types; integer types will all be
  224. round_toward_zero. */
  225. static const float_round_style round_style = round_toward_zero;
  226. };
  227. /**
  228. * @brief Properties of fundamental types.
  229. *
  230. * This class allows a program to obtain information about the
  231. * representation of a fundamental type on a given platform. For
  232. * non-fundamental types, the functions will return 0 and the data
  233. * members will all be @c false.
  234. *
  235. * _GLIBCXX_RESOLVE_LIB_DEFECTS: DRs 201 and 184 (hi Gaby!) are
  236. * noted, but not incorporated in this documented (yet).
  237. */
  238. template<typename _Tp>
  239. struct numeric_limits : public __numeric_limits_base
  240. {
  241. /** The minimum finite value, or for floating types with
  242. denormalization, the minimum positive normalized value. */
  243. static _Tp min() throw() { return static_cast<_Tp>(0); }
  244. /** The maximum finite value. */
  245. static _Tp max() throw() { return static_cast<_Tp>(0); }
  246. /** The @e machine @e epsilon: the difference between 1 and the least
  247. value greater than 1 that is representable. */
  248. static _Tp epsilon() throw() { return static_cast<_Tp>(0); }
  249. /** The maximum rounding error measurement (see LIA-1). */
  250. static _Tp round_error() throw() { return static_cast<_Tp>(0); }
  251. /** The representation of positive infinity, if @c has_infinity. */
  252. static _Tp infinity() throw() { return static_cast<_Tp>(0); }
  253. /** The representation of a quiet "Not a Number," if @c has_quiet_NaN. */
  254. static _Tp quiet_NaN() throw() { return static_cast<_Tp>(0); }
  255. /** The representation of a signaling "Not a Number," if
  256. @c has_signaling_NaN. */
  257. static _Tp signaling_NaN() throw() { return static_cast<_Tp>(0); }
  258. /** The minimum positive denormalized value. For types where
  259. @c has_denorm is false, this is the minimum positive normalized
  260. value. */
  261. static _Tp denorm_min() throw() { return static_cast<_Tp>(0); }
  262. };
  263. // Now there follow 15 explicit specializations. Yes, 15. Make sure
  264. // you get the count right.
  265. /// numeric_limits<bool> specialization.
  266. template<>
  267. struct numeric_limits<bool>
  268. {
  269. static const bool is_specialized = true;
  270. static bool min() throw()
  271. { return false; }
  272. static bool max() throw()
  273. { return true; }
  274. static const int digits = 1;
  275. static const int digits10 = 0;
  276. static const bool is_signed = false;
  277. static const bool is_integer = true;
  278. static const bool is_exact = true;
  279. static const int radix = 2;
  280. static bool epsilon() throw()
  281. { return false; }
  282. static bool round_error() throw()
  283. { return false; }
  284. static const int min_exponent = 0;
  285. static const int min_exponent10 = 0;
  286. static const int max_exponent = 0;
  287. static const int max_exponent10 = 0;
  288. static const bool has_infinity = false;
  289. static const bool has_quiet_NaN = false;
  290. static const bool has_signaling_NaN = false;
  291. static const float_denorm_style has_denorm = denorm_absent;
  292. static const bool has_denorm_loss = false;
  293. static bool infinity() throw()
  294. { return false; }
  295. static bool quiet_NaN() throw()
  296. { return false; }
  297. static bool signaling_NaN() throw()
  298. { return false; }
  299. static bool denorm_min() throw()
  300. { return false; }
  301. static const bool is_iec559 = false;
  302. static const bool is_bounded = true;
  303. static const bool is_modulo = false;
  304. // It is not clear what it means for a boolean type to trap.
  305. // This is a DR on the LWG issue list. Here, I use integer
  306. // promotion semantics.
  307. static const bool traps = __glibcxx_integral_traps;
  308. static const bool tinyness_before = false;
  309. static const float_round_style round_style = round_toward_zero;
  310. };
  311. /// numeric_limits<char> specialization.
  312. template<>
  313. struct numeric_limits<char>
  314. {
  315. static const bool is_specialized = true;
  316. static char min() throw()
  317. { return __glibcxx_min(char); }
  318. static char max() throw()
  319. { return __glibcxx_max(char); }
  320. static const int digits = __glibcxx_digits (char);
  321. static const int digits10 = __glibcxx_digits10 (char);
  322. static const bool is_signed = __glibcxx_signed (char);
  323. static const bool is_integer = true;
  324. static const bool is_exact = true;
  325. static const int radix = 2;
  326. static char epsilon() throw()
  327. { return 0; }
  328. static char round_error() throw()
  329. { return 0; }
  330. static const int min_exponent = 0;
  331. static const int min_exponent10 = 0;
  332. static const int max_exponent = 0;
  333. static const int max_exponent10 = 0;
  334. static const bool has_infinity = false;
  335. static const bool has_quiet_NaN = false;
  336. static const bool has_signaling_NaN = false;
  337. static const float_denorm_style has_denorm = denorm_absent;
  338. static const bool has_denorm_loss = false;
  339. static char infinity() throw()
  340. { return char(); }
  341. static char quiet_NaN() throw()
  342. { return char(); }
  343. static char signaling_NaN() throw()
  344. { return char(); }
  345. static char denorm_min() throw()
  346. { return static_cast<char>(0); }
  347. static const bool is_iec559 = false;
  348. static const bool is_bounded = true;
  349. static const bool is_modulo = true;
  350. static const bool traps = __glibcxx_integral_traps;
  351. static const bool tinyness_before = false;
  352. static const float_round_style round_style = round_toward_zero;
  353. };
  354. /// numeric_limits<signed char> specialization.
  355. template<>
  356. struct numeric_limits<signed char>
  357. {
  358. static const bool is_specialized = true;
  359. static signed char min() throw()
  360. { return -__SCHAR_MAX__ - 1; }
  361. static signed char max() throw()
  362. { return __SCHAR_MAX__; }
  363. static const int digits = __glibcxx_digits (signed char);
  364. static const int digits10 = __glibcxx_digits10 (signed char);
  365. static const bool is_signed = true;
  366. static const bool is_integer = true;
  367. static const bool is_exact = true;
  368. static const int radix = 2;
  369. static signed char epsilon() throw()
  370. { return 0; }
  371. static signed char round_error() throw()
  372. { return 0; }
  373. static const int min_exponent = 0;
  374. static const int min_exponent10 = 0;
  375. static const int max_exponent = 0;
  376. static const int max_exponent10 = 0;
  377. static const bool has_infinity = false;
  378. static const bool has_quiet_NaN = false;
  379. static const bool has_signaling_NaN = false;
  380. static const float_denorm_style has_denorm = denorm_absent;
  381. static const bool has_denorm_loss = false;
  382. static signed char infinity() throw()
  383. { return static_cast<signed char>(0); }
  384. static signed char quiet_NaN() throw()
  385. { return static_cast<signed char>(0); }
  386. static signed char signaling_NaN() throw()
  387. { return static_cast<signed char>(0); }
  388. static signed char denorm_min() throw()
  389. { return static_cast<signed char>(0); }
  390. static const bool is_iec559 = false;
  391. static const bool is_bounded = true;
  392. static const bool is_modulo = true;
  393. static const bool traps = __glibcxx_integral_traps;
  394. static const bool tinyness_before = false;
  395. static const float_round_style round_style = round_toward_zero;
  396. };
  397. /// numeric_limits<unsigned char> specialization.
  398. template<>
  399. struct numeric_limits<unsigned char>
  400. {
  401. static const bool is_specialized = true;
  402. static unsigned char min() throw()
  403. { return 0; }
  404. static unsigned char max() throw()
  405. { return __SCHAR_MAX__ * 2U + 1; }
  406. static const int digits = __glibcxx_digits (unsigned char);
  407. static const int digits10 = __glibcxx_digits10 (unsigned char);
  408. static const bool is_signed = false;
  409. static const bool is_integer = true;
  410. static const bool is_exact = true;
  411. static const int radix = 2;
  412. static unsigned char epsilon() throw()
  413. { return 0; }
  414. static unsigned char round_error() throw()
  415. { return 0; }
  416. static const int min_exponent = 0;
  417. static const int min_exponent10 = 0;
  418. static const int max_exponent = 0;
  419. static const int max_exponent10 = 0;
  420. static const bool has_infinity = false;
  421. static const bool has_quiet_NaN = false;
  422. static const bool has_signaling_NaN = false;
  423. static const float_denorm_style has_denorm = denorm_absent;
  424. static const bool has_denorm_loss = false;
  425. static unsigned char infinity() throw()
  426. { return static_cast<unsigned char>(0); }
  427. static unsigned char quiet_NaN() throw()
  428. { return static_cast<unsigned char>(0); }
  429. static unsigned char signaling_NaN() throw()
  430. { return static_cast<unsigned char>(0); }
  431. static unsigned char denorm_min() throw()
  432. { return static_cast<unsigned char>(0); }
  433. static const bool is_iec559 = false;
  434. static const bool is_bounded = true;
  435. static const bool is_modulo = true;
  436. static const bool traps = __glibcxx_integral_traps;
  437. static const bool tinyness_before = false;
  438. static const float_round_style round_style = round_toward_zero;
  439. };
  440. /// numeric_limits<wchar_t> specialization.
  441. template<>
  442. struct numeric_limits<wchar_t>
  443. {
  444. static const bool is_specialized = true;
  445. static wchar_t min() throw()
  446. { return __glibcxx_min (wchar_t); }
  447. static wchar_t max() throw()
  448. { return __glibcxx_max (wchar_t); }
  449. static const int digits = __glibcxx_digits (wchar_t);
  450. static const int digits10 = __glibcxx_digits10 (wchar_t);
  451. static const bool is_signed = __glibcxx_signed (wchar_t);
  452. static const bool is_integer = true;
  453. static const bool is_exact = true;
  454. static const int radix = 2;
  455. static wchar_t epsilon() throw()
  456. { return 0; }
  457. static wchar_t round_error() throw()
  458. { return 0; }
  459. static const int min_exponent = 0;
  460. static const int min_exponent10 = 0;
  461. static const int max_exponent = 0;
  462. static const int max_exponent10 = 0;
  463. static const bool has_infinity = false;
  464. static const bool has_quiet_NaN = false;
  465. static const bool has_signaling_NaN = false;
  466. static const float_denorm_style has_denorm = denorm_absent;
  467. static const bool has_denorm_loss = false;
  468. static wchar_t infinity() throw()
  469. { return wchar_t(); }
  470. static wchar_t quiet_NaN() throw()
  471. { return wchar_t(); }
  472. static wchar_t signaling_NaN() throw()
  473. { return wchar_t(); }
  474. static wchar_t denorm_min() throw()
  475. { return wchar_t(); }
  476. static const bool is_iec559 = false;
  477. static const bool is_bounded = true;
  478. static const bool is_modulo = true;
  479. static const bool traps = __glibcxx_integral_traps;
  480. static const bool tinyness_before = false;
  481. static const float_round_style round_style = round_toward_zero;
  482. };
  483. #ifdef __GXX_EXPERIMENTAL_CXX0X__
  484. /// numeric_limits<char16_t> specialization.
  485. template<>
  486. struct numeric_limits<char16_t>
  487. {
  488. static const bool is_specialized = true;
  489. static char16_t min() throw()
  490. { return __glibcxx_min (char16_t); }
  491. static char16_t max() throw()
  492. { return __glibcxx_max (char16_t); }
  493. static const int digits = __glibcxx_digits (char16_t);
  494. static const int digits10 = __glibcxx_digits10 (char16_t);
  495. static const bool is_signed = __glibcxx_signed (char16_t);
  496. static const bool is_integer = true;
  497. static const bool is_exact = true;
  498. static const int radix = 2;
  499. static char16_t epsilon() throw()
  500. { return 0; }
  501. static char16_t round_error() throw()
  502. { return 0; }
  503. static const int min_exponent = 0;
  504. static const int min_exponent10 = 0;
  505. static const int max_exponent = 0;
  506. static const int max_exponent10 = 0;
  507. static const bool has_infinity = false;
  508. static const bool has_quiet_NaN = false;
  509. static const bool has_signaling_NaN = false;
  510. static const float_denorm_style has_denorm = denorm_absent;
  511. static const bool has_denorm_loss = false;
  512. static char16_t infinity() throw()
  513. { return char16_t(); }
  514. static char16_t quiet_NaN() throw()
  515. { return char16_t(); }
  516. static char16_t signaling_NaN() throw()
  517. { return char16_t(); }
  518. static char16_t denorm_min() throw()
  519. { return char16_t(); }
  520. static const bool is_iec559 = false;
  521. static const bool is_bounded = true;
  522. static const bool is_modulo = true;
  523. static const bool traps = __glibcxx_integral_traps;
  524. static const bool tinyness_before = false;
  525. static const float_round_style round_style = round_toward_zero;
  526. };
  527. /// numeric_limits<char32_t> specialization.
  528. template<>
  529. struct numeric_limits<char32_t>
  530. {
  531. static const bool is_specialized = true;
  532. static char32_t min() throw()
  533. { return __glibcxx_min (char32_t); }
  534. static char32_t max() throw()
  535. { return __glibcxx_max (char32_t); }
  536. static const int digits = __glibcxx_digits (char32_t);
  537. static const int digits10 = __glibcxx_digits10 (char32_t);
  538. static const bool is_signed = __glibcxx_signed (char32_t);
  539. static const bool is_integer = true;
  540. static const bool is_exact = true;
  541. static const int radix = 2;
  542. static char32_t epsilon() throw()
  543. { return 0; }
  544. static char32_t round_error() throw()
  545. { return 0; }
  546. static const int min_exponent = 0;
  547. static const int min_exponent10 = 0;
  548. static const int max_exponent = 0;
  549. static const int max_exponent10 = 0;
  550. static const bool has_infinity = false;
  551. static const bool has_quiet_NaN = false;
  552. static const bool has_signaling_NaN = false;
  553. static const float_denorm_style has_denorm = denorm_absent;
  554. static const bool has_denorm_loss = false;
  555. static char32_t infinity() throw()
  556. { return char32_t(); }
  557. static char32_t quiet_NaN() throw()
  558. { return char32_t(); }
  559. static char32_t signaling_NaN() throw()
  560. { return char32_t(); }
  561. static char32_t denorm_min() throw()
  562. { return char32_t(); }
  563. static const bool is_iec559 = false;
  564. static const bool is_bounded = true;
  565. static const bool is_modulo = true;
  566. static const bool traps = __glibcxx_integral_traps;
  567. static const bool tinyness_before = false;
  568. static const float_round_style round_style = round_toward_zero;
  569. };
  570. #endif
  571. /// numeric_limits<short> specialization.
  572. template<>
  573. struct numeric_limits<short>
  574. {
  575. static const bool is_specialized = true;
  576. static short min() throw()
  577. { return -__SHRT_MAX__ - 1; }
  578. static short max() throw()
  579. { return __SHRT_MAX__; }
  580. static const int digits = __glibcxx_digits (short);
  581. static const int digits10 = __glibcxx_digits10 (short);
  582. static const bool is_signed = true;
  583. static const bool is_integer = true;
  584. static const bool is_exact = true;
  585. static const int radix = 2;
  586. static short epsilon() throw()
  587. { return 0; }
  588. static short round_error() throw()
  589. { return 0; }
  590. static const int min_exponent = 0;
  591. static const int min_exponent10 = 0;
  592. static const int max_exponent = 0;
  593. static const int max_exponent10 = 0;
  594. static const bool has_infinity = false;
  595. static const bool has_quiet_NaN = false;
  596. static const bool has_signaling_NaN = false;
  597. static const float_denorm_style has_denorm = denorm_absent;
  598. static const bool has_denorm_loss = false;
  599. static short infinity() throw()
  600. { return short(); }
  601. static short quiet_NaN() throw()
  602. { return short(); }
  603. static short signaling_NaN() throw()
  604. { return short(); }
  605. static short denorm_min() throw()
  606. { return short(); }
  607. static const bool is_iec559 = false;
  608. static const bool is_bounded = true;
  609. static const bool is_modulo = true;
  610. static const bool traps = __glibcxx_integral_traps;
  611. static const bool tinyness_before = false;
  612. static const float_round_style round_style = round_toward_zero;
  613. };
  614. /// numeric_limits<unsigned short> specialization.
  615. template<>
  616. struct numeric_limits<unsigned short>
  617. {
  618. static const bool is_specialized = true;
  619. static unsigned short min() throw()
  620. { return 0; }
  621. static unsigned short max() throw()
  622. { return __SHRT_MAX__ * 2U + 1; }
  623. static const int digits = __glibcxx_digits (unsigned short);
  624. static const int digits10 = __glibcxx_digits10 (unsigned short);
  625. static const bool is_signed = false;
  626. static const bool is_integer = true;
  627. static const bool is_exact = true;
  628. static const int radix = 2;
  629. static unsigned short epsilon() throw()
  630. { return 0; }
  631. static unsigned short round_error() throw()
  632. { return 0; }
  633. static const int min_exponent = 0;
  634. static const int min_exponent10 = 0;
  635. static const int max_exponent = 0;
  636. static const int max_exponent10 = 0;
  637. static const bool has_infinity = false;
  638. static const bool has_quiet_NaN = false;
  639. static const bool has_signaling_NaN = false;
  640. static const float_denorm_style has_denorm = denorm_absent;
  641. static const bool has_denorm_loss = false;
  642. static unsigned short infinity() throw()
  643. { return static_cast<unsigned short>(0); }
  644. static unsigned short quiet_NaN() throw()
  645. { return static_cast<unsigned short>(0); }
  646. static unsigned short signaling_NaN() throw()
  647. { return static_cast<unsigned short>(0); }
  648. static unsigned short denorm_min() throw()
  649. { return static_cast<unsigned short>(0); }
  650. static const bool is_iec559 = false;
  651. static const bool is_bounded = true;
  652. static const bool is_modulo = true;
  653. static const bool traps = __glibcxx_integral_traps;
  654. static const bool tinyness_before = false;
  655. static const float_round_style round_style = round_toward_zero;
  656. };
  657. /// numeric_limits<int> specialization.
  658. template<>
  659. struct numeric_limits<int>
  660. {
  661. static const bool is_specialized = true;
  662. static int min() throw()
  663. { return -__INT_MAX__ - 1; }
  664. static int max() throw()
  665. { return __INT_MAX__; }
  666. static const int digits = __glibcxx_digits (int);
  667. static const int digits10 = __glibcxx_digits10 (int);
  668. static const bool is_signed = true;
  669. static const bool is_integer = true;
  670. static const bool is_exact = true;
  671. static const int radix = 2;
  672. static int epsilon() throw()
  673. { return 0; }
  674. static int round_error() throw()
  675. { return 0; }
  676. static const int min_exponent = 0;
  677. static const int min_exponent10 = 0;
  678. static const int max_exponent = 0;
  679. static const int max_exponent10 = 0;
  680. static const bool has_infinity = false;
  681. static const bool has_quiet_NaN = false;
  682. static const bool has_signaling_NaN = false;
  683. static const float_denorm_style has_denorm = denorm_absent;
  684. static const bool has_denorm_loss = false;
  685. static int infinity() throw()
  686. { return static_cast<int>(0); }
  687. static int quiet_NaN() throw()
  688. { return static_cast<int>(0); }
  689. static int signaling_NaN() throw()
  690. { return static_cast<int>(0); }
  691. static int denorm_min() throw()
  692. { return static_cast<int>(0); }
  693. static const bool is_iec559 = false;
  694. static const bool is_bounded = true;
  695. static const bool is_modulo = true;
  696. static const bool traps = __glibcxx_integral_traps;
  697. static const bool tinyness_before = false;
  698. static const float_round_style round_style = round_toward_zero;
  699. };
  700. /// numeric_limits<unsigned int> specialization.
  701. template<>
  702. struct numeric_limits<unsigned int>
  703. {
  704. static const bool is_specialized = true;
  705. static unsigned int min() throw()
  706. { return 0; }
  707. static unsigned int max() throw()
  708. { return __INT_MAX__ * 2U + 1; }
  709. static const int digits = __glibcxx_digits (unsigned int);
  710. static const int digits10 = __glibcxx_digits10 (unsigned int);
  711. static const bool is_signed = false;
  712. static const bool is_integer = true;
  713. static const bool is_exact = true;
  714. static const int radix = 2;
  715. static unsigned int epsilon() throw()
  716. { return 0; }
  717. static unsigned int round_error() throw()
  718. { return 0; }
  719. static const int min_exponent = 0;
  720. static const int min_exponent10 = 0;
  721. static const int max_exponent = 0;
  722. static const int max_exponent10 = 0;
  723. static const bool has_infinity = false;
  724. static const bool has_quiet_NaN = false;
  725. static const bool has_signaling_NaN = false;
  726. static const float_denorm_style has_denorm = denorm_absent;
  727. static const bool has_denorm_loss = false;
  728. static unsigned int infinity() throw()
  729. { return static_cast<unsigned int>(0); }
  730. static unsigned int quiet_NaN() throw()
  731. { return static_cast<unsigned int>(0); }
  732. static unsigned int signaling_NaN() throw()
  733. { return static_cast<unsigned int>(0); }
  734. static unsigned int denorm_min() throw()
  735. { return static_cast<unsigned int>(0); }
  736. static const bool is_iec559 = false;
  737. static const bool is_bounded = true;
  738. static const bool is_modulo = true;
  739. static const bool traps = __glibcxx_integral_traps;
  740. static const bool tinyness_before = false;
  741. static const float_round_style round_style = round_toward_zero;
  742. };
  743. /// numeric_limits<long> specialization.
  744. template<>
  745. struct numeric_limits<long>
  746. {
  747. static const bool is_specialized = true;
  748. static long min() throw()
  749. { return -__LONG_MAX__ - 1; }
  750. static long max() throw()
  751. { return __LONG_MAX__; }
  752. static const int digits = __glibcxx_digits (long);
  753. static const int digits10 = __glibcxx_digits10 (long);
  754. static const bool is_signed = true;
  755. static const bool is_integer = true;
  756. static const bool is_exact = true;
  757. static const int radix = 2;
  758. static long epsilon() throw()
  759. { return 0; }
  760. static long round_error() throw()
  761. { return 0; }
  762. static const int min_exponent = 0;
  763. static const int min_exponent10 = 0;
  764. static const int max_exponent = 0;
  765. static const int max_exponent10 = 0;
  766. static const bool has_infinity = false;
  767. static const bool has_quiet_NaN = false;
  768. static const bool has_signaling_NaN = false;
  769. static const float_denorm_style has_denorm = denorm_absent;
  770. static const bool has_denorm_loss = false;
  771. static long infinity() throw()
  772. { return static_cast<long>(0); }
  773. static long quiet_NaN() throw()
  774. { return static_cast<long>(0); }
  775. static long signaling_NaN() throw()
  776. { return static_cast<long>(0); }
  777. static long denorm_min() throw()
  778. { return static_cast<long>(0); }
  779. static const bool is_iec559 = false;
  780. static const bool is_bounded = true;
  781. static const bool is_modulo = true;
  782. static const bool traps = __glibcxx_integral_traps;
  783. static const bool tinyness_before = false;
  784. static const float_round_style round_style = round_toward_zero;
  785. };
  786. /// numeric_limits<unsigned long> specialization.
  787. template<>
  788. struct numeric_limits<unsigned long>
  789. {
  790. static const bool is_specialized = true;
  791. static unsigned long min() throw()
  792. { return 0; }
  793. static unsigned long max() throw()
  794. { return __LONG_MAX__ * 2UL + 1; }
  795. static const int digits = __glibcxx_digits (unsigned long);
  796. static const int digits10 = __glibcxx_digits10 (unsigned long);
  797. static const bool is_signed = false;
  798. static const bool is_integer = true;
  799. static const bool is_exact = true;
  800. static const int radix = 2;
  801. static unsigned long epsilon() throw()
  802. { return 0; }
  803. static unsigned long round_error() throw()
  804. { return 0; }
  805. static const int min_exponent = 0;
  806. static const int min_exponent10 = 0;
  807. static const int max_exponent = 0;
  808. static const int max_exponent10 = 0;
  809. static const bool has_infinity = false;
  810. static const bool has_quiet_NaN = false;
  811. static const bool has_signaling_NaN = false;
  812. static const float_denorm_style has_denorm = denorm_absent;
  813. static const bool has_denorm_loss = false;
  814. static unsigned long infinity() throw()
  815. { return static_cast<unsigned long>(0); }
  816. static unsigned long quiet_NaN() throw()
  817. { return static_cast<unsigned long>(0); }
  818. static unsigned long signaling_NaN() throw()
  819. { return static_cast<unsigned long>(0); }
  820. static unsigned long denorm_min() throw()
  821. { return static_cast<unsigned long>(0); }
  822. static const bool is_iec559 = false;
  823. static const bool is_bounded = true;
  824. static const bool is_modulo = true;
  825. static const bool traps = __glibcxx_integral_traps;
  826. static const bool tinyness_before = false;
  827. static const float_round_style round_style = round_toward_zero;
  828. };
  829. /// numeric_limits<long long> specialization.
  830. template<>
  831. struct numeric_limits<long long>
  832. {
  833. static const bool is_specialized = true;
  834. static long long min() throw()
  835. { return -__LONG_LONG_MAX__ - 1; }
  836. static long long max() throw()
  837. { return __LONG_LONG_MAX__; }
  838. static const int digits = __glibcxx_digits (long long);
  839. static const int digits10 = __glibcxx_digits10 (long long);
  840. static const bool is_signed = true;
  841. static const bool is_integer = true;
  842. static const bool is_exact = true;
  843. static const int radix = 2;
  844. static long long epsilon() throw()
  845. { return 0; }
  846. static long long round_error() throw()
  847. { return 0; }
  848. static const int min_exponent = 0;
  849. static const int min_exponent10 = 0;
  850. static const int max_exponent = 0;
  851. static const int max_exponent10 = 0;
  852. static const bool has_infinity = false;
  853. static const bool has_quiet_NaN = false;
  854. static const bool has_signaling_NaN = false;
  855. static const float_denorm_style has_denorm = denorm_absent;
  856. static const bool has_denorm_loss = false;
  857. static long long infinity() throw()
  858. { return static_cast<long long>(0); }
  859. static long long quiet_NaN() throw()
  860. { return static_cast<long long>(0); }
  861. static long long signaling_NaN() throw()
  862. { return static_cast<long long>(0); }
  863. static long long denorm_min() throw()
  864. { return static_cast<long long>(0); }
  865. static const bool is_iec559 = false;
  866. static const bool is_bounded = true;
  867. static const bool is_modulo = true;
  868. static const bool traps = __glibcxx_integral_traps;
  869. static const bool tinyness_before = false;
  870. static const float_round_style round_style = round_toward_zero;
  871. };
  872. /// numeric_limits<unsigned long long> specialization.
  873. template<>
  874. struct numeric_limits<unsigned long long>
  875. {
  876. static const bool is_specialized = true;
  877. static unsigned long long min() throw()
  878. { return 0; }
  879. static unsigned long long max() throw()
  880. { return __LONG_LONG_MAX__ * 2ULL + 1; }
  881. static const int digits = __glibcxx_digits (unsigned long long);
  882. static const int digits10 = __glibcxx_digits10 (unsigned long long);
  883. static const bool is_signed = false;
  884. static const bool is_integer = true;
  885. static const bool is_exact = true;
  886. static const int radix = 2;
  887. static unsigned long long epsilon() throw()
  888. { return 0; }
  889. static unsigned long long round_error() throw()
  890. { return 0; }
  891. static const int min_exponent = 0;
  892. static const int min_exponent10 = 0;
  893. static const int max_exponent = 0;
  894. static const int max_exponent10 = 0;
  895. static const bool has_infinity = false;
  896. static const bool has_quiet_NaN = false;
  897. static const bool has_signaling_NaN = false;
  898. static const float_denorm_style has_denorm = denorm_absent;
  899. static const bool has_denorm_loss = false;
  900. static unsigned long long infinity() throw()
  901. { return static_cast<unsigned long long>(0); }
  902. static unsigned long long quiet_NaN() throw()
  903. { return static_cast<unsigned long long>(0); }
  904. static unsigned long long signaling_NaN() throw()
  905. { return static_cast<unsigned long long>(0); }
  906. static unsigned long long denorm_min() throw()
  907. { return static_cast<unsigned long long>(0); }
  908. static const bool is_iec559 = false;
  909. static const bool is_bounded = true;
  910. static const bool is_modulo = true;
  911. static const bool traps = __glibcxx_integral_traps;
  912. static const bool tinyness_before = false;
  913. static const float_round_style round_style = round_toward_zero;
  914. };
  915. /// numeric_limits<float> specialization.
  916. template<>
  917. struct numeric_limits<float>
  918. {
  919. static const bool is_specialized = true;
  920. static float min() throw()
  921. { return __FLT_MIN__; }
  922. static float max() throw()
  923. { return __FLT_MAX__; }
  924. static const int digits = __FLT_MANT_DIG__;
  925. static const int digits10 = __FLT_DIG__;
  926. static const bool is_signed = true;
  927. static const bool is_integer = false;
  928. static const bool is_exact = false;
  929. static const int radix = __FLT_RADIX__;
  930. static float epsilon() throw()
  931. { return __FLT_EPSILON__; }
  932. static float round_error() throw()
  933. { return 0.5F; }
  934. static const int min_exponent = __FLT_MIN_EXP__;
  935. static const int min_exponent10 = __FLT_MIN_10_EXP__;
  936. static const int max_exponent = __FLT_MAX_EXP__;
  937. static const int max_exponent10 = __FLT_MAX_10_EXP__;
  938. static const bool has_infinity = __FLT_HAS_INFINITY__;
  939. static const bool has_quiet_NaN = __FLT_HAS_QUIET_NAN__;
  940. static const bool has_signaling_NaN = has_quiet_NaN;
  941. static const float_denorm_style has_denorm
  942. = bool(__FLT_HAS_DENORM__) ? denorm_present : denorm_absent;
  943. static const bool has_denorm_loss = __glibcxx_float_has_denorm_loss;
  944. static float infinity() throw()
  945. { return __builtin_huge_valf (); }
  946. static float quiet_NaN() throw()
  947. { return __builtin_nanf (""); }
  948. static float signaling_NaN() throw()
  949. { return __builtin_nansf (""); }
  950. static float denorm_min() throw()
  951. { return __FLT_DENORM_MIN__; }
  952. static const bool is_iec559
  953. = has_infinity && has_quiet_NaN && has_denorm == denorm_present;
  954. static const bool is_bounded = true;
  955. static const bool is_modulo = false;
  956. static const bool traps = __glibcxx_float_traps;
  957. static const bool tinyness_before = __glibcxx_float_tinyness_before;
  958. static const float_round_style round_style = round_to_nearest;
  959. };
  960. #undef __glibcxx_float_has_denorm_loss
  961. #undef __glibcxx_float_traps
  962. #undef __glibcxx_float_tinyness_before
  963. /// numeric_limits<double> specialization.
  964. template<>
  965. struct numeric_limits<double>
  966. {
  967. static const bool is_specialized = true;
  968. static double min() throw()
  969. { return __DBL_MIN__; }
  970. static double max() throw()
  971. { return __DBL_MAX__; }
  972. static const int digits = __DBL_MANT_DIG__;
  973. static const int digits10 = __DBL_DIG__;
  974. static const bool is_signed = true;
  975. static const bool is_integer = false;
  976. static const bool is_exact = false;
  977. static const int radix = __FLT_RADIX__;
  978. static double epsilon() throw()
  979. { return __DBL_EPSILON__; }
  980. static double round_error() throw()
  981. { return 0.5; }
  982. static const int min_exponent = __DBL_MIN_EXP__;
  983. static const int min_exponent10 = __DBL_MIN_10_EXP__;
  984. static const int max_exponent = __DBL_MAX_EXP__;
  985. static const int max_exponent10 = __DBL_MAX_10_EXP__;
  986. static const bool has_infinity = __DBL_HAS_INFINITY__;
  987. static const bool has_quiet_NaN = __DBL_HAS_QUIET_NAN__;
  988. static const bool has_signaling_NaN = has_quiet_NaN;
  989. static const float_denorm_style has_denorm
  990. = bool(__DBL_HAS_DENORM__) ? denorm_present : denorm_absent;
  991. static const bool has_denorm_loss = __glibcxx_double_has_denorm_loss;
  992. static double infinity() throw()
  993. { return __builtin_huge_val(); }
  994. static double quiet_NaN() throw()
  995. { return __builtin_nan (""); }
  996. static double signaling_NaN() throw()
  997. { return __builtin_nans (""); }
  998. static double denorm_min() throw()
  999. { return __DBL_DENORM_MIN__; }
  1000. static const bool is_iec559
  1001. = has_infinity && has_quiet_NaN && has_denorm == denorm_present;
  1002. static const bool is_bounded = true;
  1003. static const bool is_modulo = false;
  1004. static const bool traps = __glibcxx_double_traps;
  1005. static const bool tinyness_before = __glibcxx_double_tinyness_before;
  1006. static const float_round_style round_style = round_to_nearest;
  1007. };
  1008. #undef __glibcxx_double_has_denorm_loss
  1009. #undef __glibcxx_double_traps
  1010. #undef __glibcxx_double_tinyness_before
  1011. /// numeric_limits<long double> specialization.
  1012. template<>
  1013. struct numeric_limits<long double>
  1014. {
  1015. static const bool is_specialized = true;
  1016. static long double min() throw()
  1017. { return __LDBL_MIN__; }
  1018. static long double max() throw()
  1019. { return __LDBL_MAX__; }
  1020. static const int digits = __LDBL_MANT_DIG__;
  1021. static const int digits10 = __LDBL_DIG__;
  1022. static const bool is_signed = true;
  1023. static const bool is_integer = false;
  1024. static const bool is_exact = false;
  1025. static const int radix = __FLT_RADIX__;
  1026. static long double epsilon() throw()
  1027. { return __LDBL_EPSILON__; }
  1028. static long double round_error() throw()
  1029. { return 0.5L; }
  1030. static const int min_exponent = __LDBL_MIN_EXP__;
  1031. static const int min_exponent10 = __LDBL_MIN_10_EXP__;
  1032. static const int max_exponent = __LDBL_MAX_EXP__;
  1033. static const int max_exponent10 = __LDBL_MAX_10_EXP__;
  1034. static const bool has_infinity = __LDBL_HAS_INFINITY__;
  1035. static const bool has_quiet_NaN = __LDBL_HAS_QUIET_NAN__;
  1036. static const bool has_signaling_NaN = has_quiet_NaN;
  1037. static const float_denorm_style has_denorm
  1038. = bool(__LDBL_HAS_DENORM__) ? denorm_present : denorm_absent;
  1039. static const bool has_denorm_loss
  1040. = __glibcxx_long_double_has_denorm_loss;
  1041. static long double infinity() throw()
  1042. { return __builtin_huge_vall (); }
  1043. static long double quiet_NaN() throw()
  1044. { return __builtin_nanl (""); }
  1045. static long double signaling_NaN() throw()
  1046. { return __builtin_nansl (""); }
  1047. static long double denorm_min() throw()
  1048. { return __LDBL_DENORM_MIN__; }
  1049. static const bool is_iec559
  1050. = has_infinity && has_quiet_NaN && has_denorm == denorm_present;
  1051. static const bool is_bounded = true;
  1052. static const bool is_modulo = false;
  1053. static const bool traps = __glibcxx_long_double_traps;
  1054. static const bool tinyness_before = __glibcxx_long_double_tinyness_before;
  1055. static const float_round_style round_style = round_to_nearest;
  1056. };
  1057. #undef __glibcxx_long_double_has_denorm_loss
  1058. #undef __glibcxx_long_double_traps
  1059. #undef __glibcxx_long_double_tinyness_before
  1060. _GLIBCXX_END_NAMESPACE
  1061. #undef __glibcxx_signed
  1062. #undef __glibcxx_min
  1063. #undef __glibcxx_max
  1064. #undef __glibcxx_digits
  1065. #undef __glibcxx_digits10
  1066. #endif // _GLIBCXX_NUMERIC_LIMITS