limits 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_LIMITS
  10. #define _LIBCPP_LIMITS
  11. /*
  12. limits synopsis
  13. namespace std
  14. {
  15. template<class T>
  16. class numeric_limits
  17. {
  18. public:
  19. static constexpr bool is_specialized = false;
  20. static constexpr T min() noexcept;
  21. static constexpr T max() noexcept;
  22. static constexpr T lowest() noexcept;
  23. static constexpr int digits = 0;
  24. static constexpr int digits10 = 0;
  25. static constexpr int max_digits10 = 0;
  26. static constexpr bool is_signed = false;
  27. static constexpr bool is_integer = false;
  28. static constexpr bool is_exact = false;
  29. static constexpr int radix = 0;
  30. static constexpr T epsilon() noexcept;
  31. static constexpr T round_error() noexcept;
  32. static constexpr int min_exponent = 0;
  33. static constexpr int min_exponent10 = 0;
  34. static constexpr int max_exponent = 0;
  35. static constexpr int max_exponent10 = 0;
  36. static constexpr bool has_infinity = false;
  37. static constexpr bool has_quiet_NaN = false;
  38. static constexpr bool has_signaling_NaN = false;
  39. static constexpr float_denorm_style has_denorm = denorm_absent; // deprecated in C++23
  40. static constexpr bool has_denorm_loss = false; // deprecated in C++23
  41. static constexpr T infinity() noexcept;
  42. static constexpr T quiet_NaN() noexcept;
  43. static constexpr T signaling_NaN() noexcept;
  44. static constexpr T denorm_min() noexcept;
  45. static constexpr bool is_iec559 = false;
  46. static constexpr bool is_bounded = false;
  47. static constexpr bool is_modulo = false;
  48. static constexpr bool traps = false;
  49. static constexpr bool tinyness_before = false;
  50. static constexpr float_round_style round_style = round_toward_zero;
  51. };
  52. enum float_round_style
  53. {
  54. round_indeterminate = -1,
  55. round_toward_zero = 0,
  56. round_to_nearest = 1,
  57. round_toward_infinity = 2,
  58. round_toward_neg_infinity = 3
  59. };
  60. enum float_denorm_style // deprecated in C++23
  61. {
  62. denorm_indeterminate = -1,
  63. denorm_absent = 0,
  64. denorm_present = 1
  65. };
  66. template<> class numeric_limits<cv bool>;
  67. template<> class numeric_limits<cv char>;
  68. template<> class numeric_limits<cv signed char>;
  69. template<> class numeric_limits<cv unsigned char>;
  70. template<> class numeric_limits<cv wchar_t>;
  71. template<> class numeric_limits<cv char8_t>; // C++20
  72. template<> class numeric_limits<cv char16_t>;
  73. template<> class numeric_limits<cv char32_t>;
  74. template<> class numeric_limits<cv short>;
  75. template<> class numeric_limits<cv int>;
  76. template<> class numeric_limits<cv long>;
  77. template<> class numeric_limits<cv long long>;
  78. template<> class numeric_limits<cv unsigned short>;
  79. template<> class numeric_limits<cv unsigned int>;
  80. template<> class numeric_limits<cv unsigned long>;
  81. template<> class numeric_limits<cv unsigned long long>;
  82. template<> class numeric_limits<cv float>;
  83. template<> class numeric_limits<cv double>;
  84. template<> class numeric_limits<cv long double>;
  85. } // std
  86. */
  87. #include <__config>
  88. #include <__type_traits/is_arithmetic.h>
  89. #include <__type_traits/is_signed.h>
  90. #include <__type_traits/remove_cv.h>
  91. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  92. # pragma GCC system_header
  93. #endif
  94. _LIBCPP_PUSH_MACROS
  95. #include <__undef_macros>
  96. #include <version>
  97. _LIBCPP_BEGIN_NAMESPACE_STD
  98. enum float_round_style {
  99. round_indeterminate = -1,
  100. round_toward_zero = 0,
  101. round_to_nearest = 1,
  102. round_toward_infinity = 2,
  103. round_toward_neg_infinity = 3
  104. };
  105. enum _LIBCPP_DEPRECATED_IN_CXX23 float_denorm_style {
  106. denorm_indeterminate = -1,
  107. denorm_absent = 0,
  108. denorm_present = 1
  109. };
  110. template <class _Tp, bool = is_arithmetic<_Tp>::value>
  111. class __libcpp_numeric_limits {
  112. protected:
  113. typedef _Tp type;
  114. static _LIBCPP_CONSTEXPR const bool is_specialized = false;
  115. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return type(); }
  116. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return type(); }
  117. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return type(); }
  118. static _LIBCPP_CONSTEXPR const int digits = 0;
  119. static _LIBCPP_CONSTEXPR const int digits10 = 0;
  120. static _LIBCPP_CONSTEXPR const int max_digits10 = 0;
  121. static _LIBCPP_CONSTEXPR const bool is_signed = false;
  122. static _LIBCPP_CONSTEXPR const bool is_integer = false;
  123. static _LIBCPP_CONSTEXPR const bool is_exact = false;
  124. static _LIBCPP_CONSTEXPR const int radix = 0;
  125. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(); }
  126. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(); }
  127. static _LIBCPP_CONSTEXPR const int min_exponent = 0;
  128. static _LIBCPP_CONSTEXPR const int min_exponent10 = 0;
  129. static _LIBCPP_CONSTEXPR const int max_exponent = 0;
  130. static _LIBCPP_CONSTEXPR const int max_exponent10 = 0;
  131. static _LIBCPP_CONSTEXPR const bool has_infinity = false;
  132. static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false;
  133. static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false;
  134. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent;
  135. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
  136. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(); }
  137. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(); }
  138. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(); }
  139. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(); }
  140. static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
  141. static _LIBCPP_CONSTEXPR const bool is_bounded = false;
  142. static _LIBCPP_CONSTEXPR const bool is_modulo = false;
  143. static _LIBCPP_CONSTEXPR const bool traps = false;
  144. static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
  145. static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero;
  146. };
  147. template <class _Tp, int __digits, bool _IsSigned>
  148. struct __libcpp_compute_min {
  149. static _LIBCPP_CONSTEXPR const _Tp value = _Tp(_Tp(1) << __digits);
  150. };
  151. template <class _Tp, int __digits>
  152. struct __libcpp_compute_min<_Tp, __digits, false> {
  153. static _LIBCPP_CONSTEXPR const _Tp value = _Tp(0);
  154. };
  155. template <class _Tp>
  156. class __libcpp_numeric_limits<_Tp, true> {
  157. protected:
  158. typedef _Tp type;
  159. static _LIBCPP_CONSTEXPR const bool is_specialized = true;
  160. static _LIBCPP_CONSTEXPR const bool is_signed = type(-1) < type(0);
  161. static _LIBCPP_CONSTEXPR const int digits = static_cast<int>(sizeof(type) * __CHAR_BIT__ - is_signed);
  162. static _LIBCPP_CONSTEXPR const int digits10 = digits * 3 / 10;
  163. static _LIBCPP_CONSTEXPR const int max_digits10 = 0;
  164. static _LIBCPP_CONSTEXPR const type __min = __libcpp_compute_min<type, digits, is_signed>::value;
  165. static _LIBCPP_CONSTEXPR const type __max = is_signed ? type(type(~0) ^ __min) : type(~0);
  166. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __min; }
  167. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __max; }
  168. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return min(); }
  169. static _LIBCPP_CONSTEXPR const bool is_integer = true;
  170. static _LIBCPP_CONSTEXPR const bool is_exact = true;
  171. static _LIBCPP_CONSTEXPR const int radix = 2;
  172. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(0); }
  173. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(0); }
  174. static _LIBCPP_CONSTEXPR const int min_exponent = 0;
  175. static _LIBCPP_CONSTEXPR const int min_exponent10 = 0;
  176. static _LIBCPP_CONSTEXPR const int max_exponent = 0;
  177. static _LIBCPP_CONSTEXPR const int max_exponent10 = 0;
  178. static _LIBCPP_CONSTEXPR const bool has_infinity = false;
  179. static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false;
  180. static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false;
  181. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent;
  182. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
  183. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(0); }
  184. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(0); }
  185. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(0); }
  186. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(0); }
  187. static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
  188. static _LIBCPP_CONSTEXPR const bool is_bounded = true;
  189. static _LIBCPP_CONSTEXPR const bool is_modulo = !std::is_signed<_Tp>::value;
  190. #if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) || defined(__wasm__)
  191. static _LIBCPP_CONSTEXPR const bool traps = true;
  192. #else
  193. static _LIBCPP_CONSTEXPR const bool traps = false;
  194. #endif
  195. static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
  196. static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero;
  197. };
  198. template <>
  199. class __libcpp_numeric_limits<bool, true> {
  200. protected:
  201. typedef bool type;
  202. static _LIBCPP_CONSTEXPR const bool is_specialized = true;
  203. static _LIBCPP_CONSTEXPR const bool is_signed = false;
  204. static _LIBCPP_CONSTEXPR const int digits = 1;
  205. static _LIBCPP_CONSTEXPR const int digits10 = 0;
  206. static _LIBCPP_CONSTEXPR const int max_digits10 = 0;
  207. static _LIBCPP_CONSTEXPR const type __min = false;
  208. static _LIBCPP_CONSTEXPR const type __max = true;
  209. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __min; }
  210. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __max; }
  211. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return min(); }
  212. static _LIBCPP_CONSTEXPR const bool is_integer = true;
  213. static _LIBCPP_CONSTEXPR const bool is_exact = true;
  214. static _LIBCPP_CONSTEXPR const int radix = 2;
  215. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(0); }
  216. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(0); }
  217. static _LIBCPP_CONSTEXPR const int min_exponent = 0;
  218. static _LIBCPP_CONSTEXPR const int min_exponent10 = 0;
  219. static _LIBCPP_CONSTEXPR const int max_exponent = 0;
  220. static _LIBCPP_CONSTEXPR const int max_exponent10 = 0;
  221. static _LIBCPP_CONSTEXPR const bool has_infinity = false;
  222. static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false;
  223. static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false;
  224. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent;
  225. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
  226. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(0); }
  227. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(0); }
  228. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(0); }
  229. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(0); }
  230. static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
  231. static _LIBCPP_CONSTEXPR const bool is_bounded = true;
  232. static _LIBCPP_CONSTEXPR const bool is_modulo = false;
  233. static _LIBCPP_CONSTEXPR const bool traps = false;
  234. static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
  235. static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero;
  236. };
  237. template <>
  238. class __libcpp_numeric_limits<float, true> {
  239. protected:
  240. typedef float type;
  241. static _LIBCPP_CONSTEXPR const bool is_specialized = true;
  242. static _LIBCPP_CONSTEXPR const bool is_signed = true;
  243. static _LIBCPP_CONSTEXPR const int digits = __FLT_MANT_DIG__;
  244. static _LIBCPP_CONSTEXPR const int digits10 = __FLT_DIG__;
  245. static _LIBCPP_CONSTEXPR const int max_digits10 = 2 + (digits * 30103l) / 100000l;
  246. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __FLT_MIN__; }
  247. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __FLT_MAX__; }
  248. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); }
  249. static _LIBCPP_CONSTEXPR const bool is_integer = false;
  250. static _LIBCPP_CONSTEXPR const bool is_exact = false;
  251. static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__;
  252. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __FLT_EPSILON__; }
  253. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5F; }
  254. static _LIBCPP_CONSTEXPR const int min_exponent = __FLT_MIN_EXP__;
  255. static _LIBCPP_CONSTEXPR const int min_exponent10 = __FLT_MIN_10_EXP__;
  256. static _LIBCPP_CONSTEXPR const int max_exponent = __FLT_MAX_EXP__;
  257. static _LIBCPP_CONSTEXPR const int max_exponent10 = __FLT_MAX_10_EXP__;
  258. static _LIBCPP_CONSTEXPR const bool has_infinity = true;
  259. static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true;
  260. static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true;
  261. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present;
  262. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
  263. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return __builtin_huge_valf(); }
  264. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return __builtin_nanf(""); }
  265. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return __builtin_nansf(""); }
  266. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return __FLT_DENORM_MIN__; }
  267. static _LIBCPP_CONSTEXPR const bool is_iec559 = true;
  268. static _LIBCPP_CONSTEXPR const bool is_bounded = true;
  269. static _LIBCPP_CONSTEXPR const bool is_modulo = false;
  270. static _LIBCPP_CONSTEXPR const bool traps = false;
  271. #if (defined(__arm__) || defined(__aarch64__))
  272. static _LIBCPP_CONSTEXPR const bool tinyness_before = true;
  273. #else
  274. static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
  275. #endif
  276. static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
  277. };
  278. template <>
  279. class __libcpp_numeric_limits<double, true> {
  280. protected:
  281. typedef double type;
  282. static _LIBCPP_CONSTEXPR const bool is_specialized = true;
  283. static _LIBCPP_CONSTEXPR const bool is_signed = true;
  284. static _LIBCPP_CONSTEXPR const int digits = __DBL_MANT_DIG__;
  285. static _LIBCPP_CONSTEXPR const int digits10 = __DBL_DIG__;
  286. static _LIBCPP_CONSTEXPR const int max_digits10 = 2 + (digits * 30103l) / 100000l;
  287. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __DBL_MIN__; }
  288. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __DBL_MAX__; }
  289. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); }
  290. static _LIBCPP_CONSTEXPR const bool is_integer = false;
  291. static _LIBCPP_CONSTEXPR const bool is_exact = false;
  292. static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__;
  293. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __DBL_EPSILON__; }
  294. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5; }
  295. static _LIBCPP_CONSTEXPR const int min_exponent = __DBL_MIN_EXP__;
  296. static _LIBCPP_CONSTEXPR const int min_exponent10 = __DBL_MIN_10_EXP__;
  297. static _LIBCPP_CONSTEXPR const int max_exponent = __DBL_MAX_EXP__;
  298. static _LIBCPP_CONSTEXPR const int max_exponent10 = __DBL_MAX_10_EXP__;
  299. static _LIBCPP_CONSTEXPR const bool has_infinity = true;
  300. static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true;
  301. static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true;
  302. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present;
  303. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
  304. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return __builtin_huge_val(); }
  305. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return __builtin_nan(""); }
  306. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return __builtin_nans(""); }
  307. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return __DBL_DENORM_MIN__; }
  308. static _LIBCPP_CONSTEXPR const bool is_iec559 = true;
  309. static _LIBCPP_CONSTEXPR const bool is_bounded = true;
  310. static _LIBCPP_CONSTEXPR const bool is_modulo = false;
  311. static _LIBCPP_CONSTEXPR const bool traps = false;
  312. #if (defined(__arm__) || defined(__aarch64__))
  313. static _LIBCPP_CONSTEXPR const bool tinyness_before = true;
  314. #else
  315. static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
  316. #endif
  317. static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
  318. };
  319. template <>
  320. class __libcpp_numeric_limits<long double, true> {
  321. protected:
  322. typedef long double type;
  323. static _LIBCPP_CONSTEXPR const bool is_specialized = true;
  324. static _LIBCPP_CONSTEXPR const bool is_signed = true;
  325. static _LIBCPP_CONSTEXPR const int digits = __LDBL_MANT_DIG__;
  326. static _LIBCPP_CONSTEXPR const int digits10 = __LDBL_DIG__;
  327. static _LIBCPP_CONSTEXPR const int max_digits10 = 2 + (digits * 30103l) / 100000l;
  328. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __LDBL_MIN__; }
  329. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __LDBL_MAX__; }
  330. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); }
  331. static _LIBCPP_CONSTEXPR const bool is_integer = false;
  332. static _LIBCPP_CONSTEXPR const bool is_exact = false;
  333. static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__;
  334. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __LDBL_EPSILON__; }
  335. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5L; }
  336. static _LIBCPP_CONSTEXPR const int min_exponent = __LDBL_MIN_EXP__;
  337. static _LIBCPP_CONSTEXPR const int min_exponent10 = __LDBL_MIN_10_EXP__;
  338. static _LIBCPP_CONSTEXPR const int max_exponent = __LDBL_MAX_EXP__;
  339. static _LIBCPP_CONSTEXPR const int max_exponent10 = __LDBL_MAX_10_EXP__;
  340. static _LIBCPP_CONSTEXPR const bool has_infinity = true;
  341. static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true;
  342. static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true;
  343. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present;
  344. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
  345. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return __builtin_huge_vall(); }
  346. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return __builtin_nanl(""); }
  347. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return __builtin_nansl(""); }
  348. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return __LDBL_DENORM_MIN__; }
  349. #if defined(__powerpc__) && defined(__LONG_DOUBLE_IBM128__)
  350. static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
  351. #else
  352. static _LIBCPP_CONSTEXPR const bool is_iec559 = true;
  353. #endif
  354. static _LIBCPP_CONSTEXPR const bool is_bounded = true;
  355. static _LIBCPP_CONSTEXPR const bool is_modulo = false;
  356. static _LIBCPP_CONSTEXPR const bool traps = false;
  357. #if (defined(__arm__) || defined(__aarch64__))
  358. static _LIBCPP_CONSTEXPR const bool tinyness_before = true;
  359. #else
  360. static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
  361. #endif
  362. static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
  363. };
  364. template <class _Tp>
  365. class _LIBCPP_TEMPLATE_VIS numeric_limits : private __libcpp_numeric_limits<_Tp> {
  366. typedef __libcpp_numeric_limits<_Tp> __base;
  367. typedef typename __base::type type;
  368. public:
  369. static _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized;
  370. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __base::min(); }
  371. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __base::max(); }
  372. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return __base::lowest(); }
  373. static _LIBCPP_CONSTEXPR const int digits = __base::digits;
  374. static _LIBCPP_CONSTEXPR const int digits10 = __base::digits10;
  375. static _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10;
  376. static _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed;
  377. static _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer;
  378. static _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact;
  379. static _LIBCPP_CONSTEXPR const int radix = __base::radix;
  380. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __base::epsilon(); }
  381. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return __base::round_error(); }
  382. static _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent;
  383. static _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10;
  384. static _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent;
  385. static _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10;
  386. static _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity;
  387. static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN;
  388. static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN;
  389. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  390. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm;
  391. static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss;
  392. _LIBCPP_SUPPRESS_DEPRECATED_POP
  393. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return __base::infinity(); }
  394. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return __base::quiet_NaN(); }
  395. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return __base::signaling_NaN(); }
  396. _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return __base::denorm_min(); }
  397. static _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559;
  398. static _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded;
  399. static _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo;
  400. static _LIBCPP_CONSTEXPR const bool traps = __base::traps;
  401. static _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before;
  402. static _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style;
  403. };
  404. template <class _Tp>
  405. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_specialized;
  406. template <class _Tp>
  407. _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::digits;
  408. template <class _Tp>
  409. _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::digits10;
  410. template <class _Tp>
  411. _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_digits10;
  412. template <class _Tp>
  413. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_signed;
  414. template <class _Tp>
  415. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_integer;
  416. template <class _Tp>
  417. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_exact;
  418. template <class _Tp>
  419. _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::radix;
  420. template <class _Tp>
  421. _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::min_exponent;
  422. template <class _Tp>
  423. _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::min_exponent10;
  424. template <class _Tp>
  425. _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_exponent;
  426. template <class _Tp>
  427. _LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_exponent10;
  428. template <class _Tp>
  429. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_infinity;
  430. template <class _Tp>
  431. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_quiet_NaN;
  432. template <class _Tp>
  433. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_signaling_NaN;
  434. template <class _Tp>
  435. _LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<_Tp>::has_denorm;
  436. template <class _Tp>
  437. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_denorm_loss;
  438. template <class _Tp>
  439. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_iec559;
  440. template <class _Tp>
  441. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_bounded;
  442. template <class _Tp>
  443. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_modulo;
  444. template <class _Tp>
  445. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::traps;
  446. template <class _Tp>
  447. _LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::tinyness_before;
  448. template <class _Tp>
  449. _LIBCPP_CONSTEXPR const float_round_style numeric_limits<_Tp>::round_style;
  450. template <class _Tp>
  451. class _LIBCPP_TEMPLATE_VIS numeric_limits<const _Tp> : public numeric_limits<_Tp> {};
  452. template <class _Tp>
  453. class _LIBCPP_TEMPLATE_VIS numeric_limits<volatile _Tp> : public numeric_limits<_Tp> {};
  454. template <class _Tp>
  455. class _LIBCPP_TEMPLATE_VIS numeric_limits<const volatile _Tp> : public numeric_limits<_Tp> {};
  456. _LIBCPP_END_NAMESPACE_STD
  457. _LIBCPP_POP_MACROS
  458. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  459. # include <type_traits>
  460. #endif
  461. #endif // _LIBCPP_LIMITS