numeric_limits_qbk.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. // Copyright Paul A. Bristow 2013
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt
  5. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. // Program to list all numeric_limits items for any type to a file in Quickbook format.
  7. // C standard http://www.open-std.org/jtc1/sc22/wg11/docs/n507.pdf
  8. // SC22/WG11 N507 DRAFT INTERNATIONAL ISO/IEC STANDARD WD 10967-1
  9. // Information technology Language independent arithmetic Part 1: Integer and Floating point arithmetic
  10. /* E.3 C++
  11. The programming language C++ is defined by ISO/IEC 14882:1998, Programming languages C++ [18].
  12. An implementation should follow all the requirements of LIA-1 unless otherwise specified by
  13. this language binding.
  14. */
  15. // https://doi.org/10.1109/IEEESTD.1985.82928
  16. // http://www.cesura17.net/~will/Professional/Research/Papers/retrospective.pdf
  17. // http://www.exploringbinary.com/using-integers-to-check-a-floating-point-approximation/
  18. // http://stackoverflow.com/questions/12466745/how-to-convert-float-to-doubleboth-stored-in-ieee-754-representation-without-loss
  19. #ifdef _MSC_VER
  20. # pragma warning (disable : 4127) // conditional expression is constant.
  21. # pragma warning (disable : 4100) // unreferenced formal parameter.
  22. #endif
  23. #include <iostream>
  24. #include <iomanip>
  25. #include <string>
  26. #include <sstream>
  27. #include <fstream>
  28. #include <limits> // numeric_limits
  29. #include <typeinfo>
  30. #include <boost/version.hpp>
  31. #include <boost/config.hpp>
  32. // May need extra includes for other types, for example:
  33. #include <boost/multiprecision/cpp_dec_float.hpp> // is decimal.
  34. #include <boost/multiprecision/cpp_bin_float.hpp> // is binary.
  35. // Assume that this will be run on MSVC to get the 32 or 64 bit info.
  36. #ifdef _WIN32
  37. std::string bits32_64 = "32";
  38. std::string filename = "numeric_limits_32_tables.qbk";
  39. #else
  40. std::string bits32_64 = "64";
  41. std::string filename = "numeric_limits_64_tables.qbk";
  42. #endif
  43. #ifdef INT32_T_MAX
  44. int i = INT256_T_MAX;
  45. #endif
  46. std::array<std::string, 16> integer_type_names =
  47. {
  48. "bool",
  49. "char",
  50. "unsigned char",
  51. "char16_t",
  52. "char32_t",
  53. "short",
  54. "unsigned short",
  55. "int",
  56. "unsigned int",
  57. "long",
  58. "unsigned long",
  59. "long long",
  60. "unsigned long long",
  61. "int32_t",
  62. //"uint32_t",
  63. "int64_t",
  64. //"uint64_t",
  65. "int128_t",
  66. //"uint128_t" // Too big?
  67. //"int256_t",
  68. //"uint256_t"
  69. //"int512_t"
  70. };
  71. std::array<std::string, 6> float_type_names =
  72. {
  73. "function", "float", "double", "long double", "cpp_dec_50", "cpp_bin_128"
  74. };
  75. // Table headings for integer constants.
  76. std::array<std::string, 8> integer_constant_heads =
  77. {
  78. "type", "signed", "bound", "modulo", "round", "radix", "digits", "digits10", // "max_digits10"
  79. };
  80. // Table headings for integer functions.
  81. std::array<std::string, 2> integer_function_heads =
  82. {
  83. "max", // "lowest", assumes is same for all integer types, so not worth listing.
  84. "min"
  85. };
  86. // Table headings for float constants.
  87. std::array<std::string, 12> float_constant_heads =
  88. {
  89. "type", // "signed", "exact", "bound", // "modulo",
  90. "round", "radix", "digits", "digits10", "max_digits10", "min_exp", "min_exp10", "max_exp", "max_exp10", "tiny", "trap"
  91. };
  92. // Table headings for float functions.
  93. std::array<std::string, 10> float_function_heads =
  94. {
  95. "function", "max", "lowest", "min", "eps", "round", "infinity", "NaN", "sig_NaN", "denorm_min"
  96. };
  97. std::string versions()
  98. { // Build a string of info about Boost, platform, STL, etc.
  99. std::stringstream mess;
  100. //mess << "\n" << "Program:\n\" " __FILE__ << "\"\n"; // \n is mis-interpreted!
  101. mess << "\n" << "Program:\n numeric_limits_qbk.cpp \n";
  102. #ifdef __TIMESTAMP__
  103. mess << __TIMESTAMP__;
  104. #endif
  105. mess << "\nBuildInfo:\n" " Platform " << BOOST_PLATFORM;
  106. mess << "\n Compiler " BOOST_COMPILER;
  107. #ifdef _MSC_FULL_VER
  108. mess << "\n MSVC version "<< BOOST_STRINGIZE(_MSC_FULL_VER) << ".";
  109. #endif
  110. mess << "\n STL " BOOST_STDLIB;
  111. mess << "\n Boost version " << BOOST_VERSION/100000 << "." << BOOST_VERSION/100 % 1000 << "." << BOOST_VERSION % 100 << std::endl;
  112. return mess.str();
  113. } // std::string versions()
  114. template <typename T>
  115. void out_round_style(std::ostream& os)
  116. { //! Send short string describing STD::round_style to stream os.
  117. // os << "Round style is ";
  118. if (std::numeric_limits<T>::round_style == std::round_indeterminate)
  119. {
  120. os << "indeterminate" ;
  121. }
  122. else if (std::numeric_limits<T>::round_style == std::round_toward_zero)
  123. {
  124. os << "to zero" ;
  125. }
  126. else if (std::numeric_limits<T>::round_style == std::round_to_nearest)
  127. {
  128. os << "to nearest" ;
  129. }
  130. else if (std::numeric_limits<T>::round_style == std::round_toward_infinity)
  131. {
  132. os << "to infin[]"; // Or << "to \u221E" << "to infinity" ;
  133. }
  134. else if (std::numeric_limits<T>::round_style == std::round_toward_neg_infinity)
  135. {
  136. os << "to -infin[]" ;
  137. }
  138. else
  139. {
  140. os << "undefined!";
  141. std::cout << "std::numeric_limits<T>::round_style is undefined value!" << std::endl;
  142. }
  143. return;
  144. } // out_round_style(std::ostream& os);
  145. template<typename T>
  146. void integer_constants(std::string type_name, std::ostream& os)
  147. { //! Output a line of table integer constant values to ostream os.
  148. os << "\n["
  149. "[" << type_name << "]" ;
  150. os << "[" << (std::numeric_limits<T>::is_signed ? "signed" : "unsigned") << "]" ;
  151. // Is always exact for integer types, so removed:
  152. // os << "[" << (std::numeric_limits<T>::is_exact ? "exact" : "inexact") << "]" ;
  153. os << "[" << (std::numeric_limits<T>::is_bounded ? "bound" : "unbounded") << "]" ;
  154. os << "[" << (std::numeric_limits<T>::is_modulo ? "modulo" : "no") << "]" ;
  155. os << "[" ; out_round_style<T>(os); os << "]" ;
  156. os << "[" << std::numeric_limits<T>::radix << "]" ;
  157. os << "[" << std::numeric_limits<T>::digits << "]" ;
  158. os << "[" << std::numeric_limits<T>::digits10 << "]" ;
  159. // Undefined for integers, so removed:
  160. // os << "[" << std::numeric_limits<T>::max_digits10 << "]"
  161. os << "]";
  162. } // void integer_constants
  163. template<typename T>
  164. void float_constants(std::string type_name, std::ostream& os)
  165. { //! Output a row of table values to `ostream` os.
  166. os << "\n["
  167. "[" << type_name << "]" ;
  168. //os << "[" << (std::numeric_limits<T>::is_signed ? "signed" : "unsigned") << "]" ;
  169. //os << "[" << (std::numeric_limits<T>::is_exact ? "exact" : "inexact") << "]" ;
  170. //os << "[" << (std::numeric_limits<T>::is_bounded ? "bound" : "no") << "]" ;
  171. // os << "[" << (std::numeric_limits<T>::is_modulo ? "modulo" : "no") << "]" ;
  172. os << "[" ; out_round_style<T>(os); os << "]" ;
  173. os << "[" << std::numeric_limits<T>::radix << "]" ;
  174. os << "[" << std::numeric_limits<T>::digits << "]" ;
  175. os << "[" << std::numeric_limits<T>::digits10 << "]" ;
  176. os << "[" << std::numeric_limits<T>::max_digits10 << "]";
  177. os << "[" << std::numeric_limits<T>::min_exponent << "]" ;
  178. os << "[" << std::numeric_limits<T>::min_exponent10 << "]" ;
  179. os << "[" << std::numeric_limits<T>::max_exponent << "]" ;
  180. os << "[" << std::numeric_limits<T>::max_exponent10 << "]" ;
  181. os << "[" << (std::numeric_limits<T>::tinyness_before ? "tiny" : "no") << "]" ;
  182. os << "[" << (std::numeric_limits<T>::traps ? "traps" : "no") << "]" ;
  183. os << "]" "\n"; // end of row.
  184. } // void float_constants
  185. /* Types across and two functions down.
  186. template<typename T>
  187. void integer_functions(std::string type_name, std::ostream& os)
  188. { //! Output a line of table integer function values to `ostream` os.
  189. os << "\n["
  190. "[" << type_name << "]" ;
  191. os << "[" << std::numeric_limits<T>::max() << "]" ;
  192. //os << "[" << std::numeric_limits<T>::lowest() << "]" ; always == min for integer types,
  193. // so removed to save space.
  194. os << "[" << std::numeric_limits<T>::min() << "]"
  195. "]";
  196. } // void integer_functions
  197. */
  198. // Types down and two (or three) functions across.
  199. template<typename T>
  200. void integer_functions(std::string type_name, std::ostream& os)
  201. { //! Output a line of table integer function values to `ostream` os.
  202. os << "\n[" // start of row.
  203. "[" << type_name << "]" ;
  204. os << "[" << (std::numeric_limits<T>::max)() << "]" ;
  205. // os << "[" << std::numeric_limits<T>::lowest() << "]" ;
  206. os << "[" << (std::numeric_limits<T>::min)() << "]" ;
  207. os << "]"; // end of row.
  208. } // void integer_functions
  209. template<typename T>
  210. void float_functions(std::string type_name, std::ostream& os)
  211. { //! Output a line of table float-point function values to `ostream` os.
  212. os << "\n[" // start of row.
  213. "[" << type_name << "]" ;
  214. os << "[" << (std::numeric_limits<T>::max)() << "]" ;
  215. os << "[" << (std::numeric_limits<T>::lowest)() << "]" ;
  216. os << "[" << (std::numeric_limits<T>::min)() << "]"
  217. os << "[" << std::numeric_limits<T>::epsilon() << "]"
  218. os << "[" << std::numeric_limits<T>::round_error() << "]"
  219. os << "[" << std::numeric_limits<T>::infinity() << "]"
  220. os << "[" << std::numeric_limits<T>::quiet_NaN() << "]"
  221. os << "[" << std::numeric_limits<T>::signaling_NaN() << "]"
  222. os << "[" << std::numeric_limits<T>::denorm_min() << "]"
  223. "]"; // end of row.
  224. } // void float_functions
  225. template<typename T>
  226. int numeric_limits_list(std::string description)
  227. {//! Output numeric_limits for numeric_limits<T>, for example `numeric_limits_list<bool>()`.
  228. // This is not used for Quickbook format.
  229. // std::cout << versions() << std::endl;
  230. std::cout << "\n" << description << "\n" << std::endl; // int, int64_t rather than full long typeid(T).name().
  231. std::cout << "Type " << typeid(T).name() << " std::numeric_limits::<" << typeid(T).name() << ">\n" << std::endl;
  232. // ull long typeid(T).name()
  233. if (std::numeric_limits<T>::is_specialized == false)
  234. {
  235. std::cout << "type " << typeid(T).name() << " is not specialized for std::numeric_limits!" << std::endl;
  236. //return -1;
  237. }
  238. // Member constants.
  239. std::cout << (std::numeric_limits<T>::is_signed ? "is signed." : "unsigned.") << std::endl;
  240. std::cout << (std::numeric_limits<T>::is_integer ? "is integer." : "not integer (fixed or float-point).") << std::endl;
  241. std::cout << (std::numeric_limits<T>::is_exact ? "is exact." : "not exact.") << std::endl;
  242. std::cout << (std::numeric_limits<T>::has_infinity ? "has infinity." : "no infinity.") << std::endl;
  243. std::cout << (std::numeric_limits<T>::has_quiet_NaN ? "has quiet NaN." : "no quiet NaN.") << std::endl;
  244. std::cout << (std::numeric_limits<T>::has_signaling_NaN ? "has signaling NaN." : "no signaling NaN.") << std::endl;
  245. if (!std::numeric_limits<T>::is_integer)
  246. { // is floating_point
  247. std::cout << "Denorm style is " ;
  248. if (std::numeric_limits<T>::has_denorm == std::denorm_absent)
  249. {
  250. std::cout << "denorm_absent." << std::endl;
  251. }
  252. else if (std::numeric_limits<T>::has_denorm == std::denorm_present)
  253. {
  254. std::cout << "denorm_present." << std::endl;
  255. }
  256. else if (std::numeric_limits<T>::has_denorm == std::denorm_indeterminate)
  257. {
  258. std::cout << "denorm_indeterminate." << std::endl;
  259. }
  260. else
  261. {
  262. std::cout << "std::numeric_limits<T>::has_denorm unexpected value!" << std::endl;
  263. }
  264. std::cout << (std::numeric_limits<T>::has_denorm_loss ? "has denorm loss." : "no denorm loss.") << std::endl;
  265. // true if a loss of accuracy is detected as a denormalization loss, rather than an inexact result.
  266. std::cout << "Round style is ";
  267. if (std::numeric_limits<T>::round_style == std::round_indeterminate)
  268. {
  269. std::cout << "round_indeterminate!" << std::endl;
  270. }
  271. else if (std::numeric_limits<T>::round_style == std::round_toward_zero)
  272. {
  273. std::cout << "round_toward_zero." << std::endl;
  274. }
  275. else if (std::numeric_limits<T>::round_style == std::round_to_nearest)
  276. {
  277. std::cout << "round_to_nearest." << std::endl;
  278. }
  279. else if (std::numeric_limits<T>::round_style == std::round_toward_infinity)
  280. {
  281. std::cout << "round_toward_infinity." << std::endl;
  282. }
  283. else if (std::numeric_limits<T>::round_style == std::round_toward_neg_infinity)
  284. {
  285. std::cout << "round_toward_neg_infinity." << std::endl;
  286. }
  287. else
  288. {
  289. std::cout << "undefined value!" << std::endl;
  290. }
  291. } // is floating_point
  292. std::cout << (std::numeric_limits<T>::is_iec559 ? "is IEC599." : "not IEC599.") << std::endl;
  293. std::cout << (std::numeric_limits<T>::is_bounded ? "is bound." : "unbounded.") << std::endl;
  294. std::cout << (std::numeric_limits<T>::is_modulo ? "is modulo." : "no modulo.") << std::endl;
  295. std::cout << std::dec << "radix " << std::numeric_limits<T>::radix << std::endl;
  296. std::cout << "digits " << std::numeric_limits<T>::digits << std::endl;
  297. std::cout << "digits10 " << std::numeric_limits<T>::digits10 << std::endl;
  298. std::cout.precision(std::numeric_limits<T>::max_digits10); // Full precision for floating-point values like max, min ...
  299. std::cout << "max_digits10 " << std::numeric_limits<T>::max_digits10 << std::endl;
  300. std::cout << "min_exponent " << std::numeric_limits<T>::min_exponent << std::endl;
  301. std::cout << "min_exponent10 " << std::numeric_limits<T>::min_exponent10 << std::endl;
  302. std::cout << "max_exponent " << std::numeric_limits<T>::max_exponent << std::endl;
  303. std::cout << "max_exponent10 " << std::numeric_limits<T>::max_exponent10 << std::endl;
  304. std::cout << (std::numeric_limits<T>::tinyness_before ? "Can tiny values before rounding." : "no tinyness_before.") << std::endl;
  305. // true if the type can detect tiny values before rounding; false if it cannot.
  306. std::cout << (std::numeric_limits<T>::traps ? "traps" : "no trapping.") << std::endl;
  307. // Whether trapping that reports on arithmetic exceptions is implemented for a type.
  308. std::cout << "Member functions." << std::endl;
  309. // (assumes operator<< for type T is available).
  310. // If floating-point then hex format may not be available.
  311. std::cout << "max = " << (std::numeric_limits<T>::max)() << std::endl;
  312. //if (std::numeric_limits<T>::is_integer)
  313. //{
  314. // std::cout << " = " << std::hex << std::numeric_limits<T>::max() << std::endl;
  315. //}
  316. std::cout << "lowest = " << std::dec << std::numeric_limits<T>::lowest() << std::endl;
  317. //if (std::numeric_limits<T>::is_integer)
  318. //{
  319. // std::cout << " = " << std::hex << std::numeric_limits<T>::lowest() << std::endl;
  320. //}
  321. std::cout << "min = " << (std::dec << std::numeric_limits<T>::min)() << std::endl;
  322. //if (std::numeric_limits<T>::is_integer)
  323. //{
  324. // std::cout << " = " << std::hex << std::numeric_limits<T>::min() << std::endl;
  325. //}
  326. std::cout << "epsilon = " << std::dec << std::numeric_limits<T>::epsilon() << std::endl;
  327. //if (std::numeric_limits<T>::is_integer)
  328. //{
  329. // std::cout << " = " << std::hex << std::numeric_limits<T>::epsilon() << std::endl;
  330. //}
  331. // round_error is always zero for integer types.
  332. // round_error is usually 1/2 = (T)0.5 for floating-point types.
  333. // round_error is ? for fixed-point.
  334. std::cout << "round_error = " << std::numeric_limits<T>::round_error() << " ULP." << std::endl;
  335. std::cout << "infinity = " << std::dec << std::numeric_limits<T>::infinity() << std::endl;
  336. std::cout << " = " << std::hex << std::numeric_limits<T>::infinity() << std::endl;
  337. std::cout << "quiet_NaN = " << std::dec << std::numeric_limits<T>::quiet_NaN() << std::endl;
  338. std::cout << " = " << std::hex << std::numeric_limits<T>::quiet_NaN() << std::endl;
  339. std::cout << "signaling_NaN = " << std::dec << std::numeric_limits<T>::signaling_NaN() << std::endl;
  340. std::cout << " = " << std::hex << std::numeric_limits<T>::signaling_NaN() << std::endl;
  341. // Only meaningful if (std::numeric_limits<T>::has_denorm == std::denorm_present)
  342. // so might not bother to show if absent?
  343. std::cout << "denorm_min = " << std::numeric_limits<T>::denorm_min() << std::endl;
  344. std::cout << " = " << std::numeric_limits<T>::denorm_min() << std::endl;
  345. return 0;
  346. }
  347. int main()
  348. {
  349. try
  350. {
  351. using namespace boost::multiprecision;
  352. std::cout << versions() << std::endl;
  353. std::ofstream fout(filename, std::ios_base::out);
  354. if (!fout.is_open())
  355. {
  356. std::cout << "Unable to open file " << filename << " for output.\n" << std::endl;
  357. return -1; // boost::EXIT_FAILURE;
  358. }
  359. fout <<
  360. "[/""\n"
  361. "Copyright 2013 Paul A. Bristow.""\n"
  362. "Copyright 2013 John Maddock.""\n"
  363. "Distributed under the Boost Software License, Version 1.0.""\n"
  364. "(See accompanying file LICENSE_1_0.txt or copy at""\n"
  365. "http://www.boost.org/LICENSE_1_0.txt).""\n"
  366. "]""\n"
  367. << std::endl;
  368. fout << "[section:limits"<< bits32_64 << " Numeric limits for " << bits32_64 << "-bit platform]" << std::endl;
  369. // Output platform version info (32 or 64).
  370. fout << "These tables were generated using the following program and options:\n\n"
  371. "[pre""\n"
  372. << versions()
  373. << "]""\n"
  374. << std::endl;
  375. fout << "[table:integral_constants Integer types constants (`std::numeric_limits<T>::is_integer == true` && is_exact == true)" "\n"
  376. "[";
  377. for (size_t i = 0; i < integer_constant_heads.size(); i++)
  378. { // signed, bound, modulo ...
  379. fout << "[" << integer_constant_heads[i] << "]" ;
  380. }
  381. fout << "]";
  382. integer_constants<bool>("bool", fout);
  383. integer_constants<char>("char", fout);
  384. integer_constants<unsigned char>("unsigned char", fout);
  385. integer_constants<char16_t>("char16_t", fout);
  386. integer_constants<char32_t>("char32_t", fout);
  387. integer_constants<short>("short", fout);
  388. integer_constants<unsigned short>("unsigned short", fout);
  389. integer_constants<int>("int", fout);
  390. integer_constants<unsigned int>("unsigned", fout);
  391. integer_constants<long>("long", fout);
  392. integer_constants<unsigned long>("unsigned long", fout);
  393. integer_constants<long long>("long long", fout);
  394. integer_constants<unsigned long long>("unsigned long long", fout);
  395. integer_constants<int32_t>("int32_t", fout);
  396. integer_constants<uint32_t>("uint32_t", fout);
  397. integer_constants<int64_t>("int64_t", fout);
  398. integer_constants<uint64_t>("uint64_t", fout);
  399. integer_constants<int128_t>("int128_t", fout);
  400. integer_constants<uint128_t>("uint128_t", fout);
  401. integer_constants<int256_t>("int256_t", fout);
  402. integer_constants<uint256_t>("uint256_t", fout);
  403. // integer_constants<int512_t>("int512_t", fout);
  404. //integer_constants<uint512_t>("uint512_t", fout); // Too big?
  405. integer_constants<cpp_int>("cpp_int", fout);
  406. fout << "\n]\n\n";
  407. fout << "[table:integral_functions Integer types functions (`std::numeric_limits<T>::is_integer == true && std::numeric_limits<T>::min() == std::numeric_limits<T>::lowest()` )" "\n"
  408. "[";
  409. // Display types across the page, and 2 (or 3) functions as rows.
  410. fout << "[function]";
  411. for (size_t i = 0; i < integer_function_heads.size(); i++)
  412. {
  413. fout << "[" << integer_function_heads[i] << "]" ;
  414. }
  415. fout << "]"; // end of headings.
  416. integer_functions<bool>("bool", fout);
  417. //integer_functions<char>("char", fout); // Need int value not char.
  418. fout << "\n[" // start of row.
  419. "[" << "char"<< "]" ;
  420. fout << "[" << static_cast<int>(std::numeric_limits<char>::max)() << "]" ;
  421. // fout << "[" << (std::numeric_limits<T>::lowest)() << "]" ;
  422. fout << "[" << static_cast<int>(std::numeric_limits<char>::min)() << "]" ;
  423. fout << "]"; // end of row.
  424. //integer_functions<unsigned char>("unsigned char", fout); // Need int value not char.
  425. fout << "\n[" // start of row.
  426. "[" << "unsigned char"<< "]" ;
  427. fout << "[" << static_cast<int>(std::numeric_limits<unsigned char>::max)() << "]" ;
  428. // fout << "[" << std::numeric_limits<unsigned char>::lowest() << "]" ;
  429. fout << "[" << static_cast<int>(std::numeric_limits<unsigned char>::min)() << "]" ;
  430. fout << "]"; // end of row.
  431. integer_functions<char16_t>("char16_t", fout);
  432. integer_functions<char32_t>("char32_t", fout);
  433. integer_functions<short>("short", fout);
  434. integer_functions<unsigned short>("unsigned short", fout);
  435. integer_functions<int>("int", fout);
  436. integer_functions<unsigned int>("unsigned int", fout);
  437. integer_functions<long>("long", fout);
  438. integer_functions<unsigned long>("unsigned long", fout);
  439. integer_functions<long long>("long long", fout);
  440. integer_functions<unsigned long long>("unsigned long long", fout);
  441. integer_functions<int32_t>("int32_t", fout);
  442. integer_functions<int64_t>("int64_t", fout);
  443. integer_functions<int128_t>("int128_t", fout);
  444. fout << "]" "\n"; // end of table;
  445. //fout << "[[max]"
  446. // << "[" << std::numeric_limits<bool>::max() << "]"
  447. // << "[" << static_cast<int>(std::numeric_limits<char>::max()) << "]"
  448. // << "[" << static_cast<int>(std::numeric_limits<unsigned char>::max()) << "]"
  449. // << "[" << static_cast<int>(std::numeric_limits<char16_t>::max()) << "]"
  450. // << "[" << static_cast<int>(std::numeric_limits<char32_t>::max()) << "]"
  451. // << "[" << std::numeric_limits<short>::max() << "]"
  452. // << "[" << std::numeric_limits<unsigned short>::max() << "]"
  453. // << "[" << std::numeric_limits<int>::max() << "]"
  454. // << "[" << std::numeric_limits<unsigned int>::max() << "]"
  455. // << "[" << std::numeric_limits<long>::max() << "]"
  456. // << "[" << std::numeric_limits<unsigned long>::max() << "]"
  457. // << "[" << std::numeric_limits<long long>::max() << "]"
  458. // << "[" << std::numeric_limits<unsigned long long>::max() << "]"
  459. // << "[" << std::numeric_limits<int32_t>::max() << "]"
  460. // << "[" << std::numeric_limits<int64_t>::max() << "]"
  461. // << "[" << std::numeric_limits<int128_t>::max() << "]"
  462. // //<< "[" << std::numeric_limits<int256_t>::max() << "]" // too big?
  463. // //<< "[" << std::numeric_limits<int512_t>::max() << "]" // too big?
  464. // << "]" "\n";
  465. ///* Assume lowest() is not useful as == min for all integer types.
  466. // */
  467. //fout << "[[min]"
  468. // << "[" << std::numeric_limits<bool>::min() << "]"
  469. // << "[" << static_cast<int>(std::numeric_limits<char>::min()) << "]"
  470. // << "[" << static_cast<int>(std::numeric_limits<unsigned char>::min()) << "]"
  471. // << "[" << static_cast<int>(std::numeric_limits<char16_t>::min()) << "]"
  472. // << "[" << static_cast<int>(std::numeric_limits<char32_t>::min()) << "]"
  473. // << "[" << std::numeric_limits<short>::min() << "]"
  474. // << "[" << std::numeric_limits<unsigned short>::min() << "]"
  475. // << "[" << std::numeric_limits<int>::min() << "]"
  476. // << "[" << std::numeric_limits<unsigned int>::min() << "]"
  477. // << "[" << std::numeric_limits<long>::min() << "]"
  478. // << "[" << std::numeric_limits<unsigned long>::min() << "]"
  479. // << "[" << std::numeric_limits<long long>::min() << "]"
  480. // << "[" << std::numeric_limits<unsigned long long>::min() << "]"
  481. // << "[" << std::numeric_limits<int32_t>::min() << "]"
  482. // << "[" << std::numeric_limits<int64_t>::min() << "]"
  483. // << "[" << std::numeric_limits<int128_t>::min() << "]"
  484. // // << "[" << std::numeric_limits<int256_t>::min() << "]" // too big?
  485. // // << "[" << std::numeric_limits<int512_t>::min() << "]" // too big?
  486. // << "]""\n";
  487. // Floating-point
  488. typedef number<cpp_dec_float<50> > cpp_dec_float_50; // 50 decimal digits.
  489. typedef number<cpp_bin_float<113> > bin_128bit_double_type; // == Binary rare long double.
  490. fout <<
  491. //"[table:float_functions Floating-point types constants (`std::numeric_limits<T>::is_integer == false && std::numeric_limits<T>::is_modulo == false` )" "\n"
  492. "[table:float_functions Floating-point types constants (`std::numeric_limits<T>::is_integer==false && is_signed==true && is_modulo==false && is_exact==false && is_bound==true`)" "\n"
  493. "[";
  494. for (size_t i = 0; i < float_constant_heads.size(); i++)
  495. {
  496. fout << "[" << float_constant_heads[i] << "]" ;
  497. }
  498. fout << "]"; // end of headings.
  499. float_constants<float>("float", fout);
  500. float_constants<double>("double", fout);
  501. float_constants<long double>("long double", fout);
  502. float_constants<cpp_dec_float_50>("cpp_dec_float_50", fout);
  503. float_constants<bin_128bit_double_type>("bin_128bit_double_type", fout);
  504. fout << "]" "\n"; // end of table;
  505. fout <<
  506. "[table:float_functions Floating-point types functions (`std::numeric_limits<T>::is_integer == false`)" "\n"
  507. "[";
  508. for (size_t i = 0; i < float_type_names.size(); i++)
  509. {
  510. fout << "[" << float_type_names[i] << "]" ;
  511. }
  512. fout << "]"; // end of headings.
  513. fout << "[[max]"
  514. << "[" << (std::numeric_limits<float>::max)() << "]"
  515. << "[" << (std::numeric_limits<double>::max)() << "]"
  516. //#if LDBL_MANT_DIG > DBL_MANT_DIG
  517. // Perhaps to test Long double is not just a duplication of double (but need change is headings too).
  518. << "[" << (std::numeric_limits<long double>::max)() << "]"
  519. //#endif
  520. << "[" << (std::numeric_limits<cpp_dec_float_50>::max)() << "]"
  521. << "[" << (std::numeric_limits<bin_128bit_double_type >::max)() << "]"
  522. << "]" "\n"; // end of row.
  523. fout << "[[min]"
  524. << "[" << (std::numeric_limits<float>::min)() << "]"
  525. << "[" << (std::numeric_limits<double>::min)() << "]"
  526. //#if LDBL_MANT_DIG > DBL_MANT_DIG
  527. // Long double is not just a duplication of double.
  528. << "[" << (std::numeric_limits<long double>::min)() << "]"
  529. //#endif
  530. << "[" << (std::numeric_limits<cpp_dec_float_50 >::min)() << "]"
  531. << "[" << (std::numeric_limits<bin_128bit_double_type >::min)() << "]"
  532. << "]" "\n"; // end of row.
  533. fout << "[[epsilon]"
  534. << "[" << std::numeric_limits<float>::epsilon() << "]"
  535. << "[" << std::numeric_limits<double>::epsilon() << "]"
  536. //#if LDBL_MANT_DIG > DBL_MANT_DIG
  537. // Long double is not just a duplication of double.
  538. << "[" << std::numeric_limits<long double>::epsilon() << "]"
  539. //#endif
  540. << "[" << std::numeric_limits<cpp_dec_float_50 >::epsilon() << "]"
  541. << "[" << std::numeric_limits<bin_128bit_double_type >::epsilon() << "]"
  542. << "]" "\n"; // end of row.
  543. fout << "[[round_error]"
  544. << "[" << std::numeric_limits<float>::round_error() << "]"
  545. << "[" << std::numeric_limits<double>::round_error() << "]"
  546. //#if LDBL_MANT_DIG > DBL_MANT_DIG
  547. // Long double is not just a duplication of double.
  548. << "[" << std::numeric_limits<long double>::round_error() << "]"
  549. //#endif
  550. << "[" << std::numeric_limits<cpp_dec_float_50 >::round_error() << "]"
  551. << "[" << std::numeric_limits<bin_128bit_double_type >::round_error() << "]"
  552. << "]" "\n"; // end of row.
  553. fout << "[[infinity]"
  554. << "[" << std::numeric_limits<float>::infinity() << "]"
  555. << "[" << std::numeric_limits<double>::infinity() << "]"
  556. //#if LDBL_MANT_DIG > DBL_MANT_DIG
  557. // Long double is not just a duplication of double.
  558. << "[" << std::numeric_limits<long double>::infinity() << "]"
  559. //#endif
  560. << "[" << std::numeric_limits<cpp_dec_float_50 >::infinity() << "]"
  561. << "[" << std::numeric_limits<bin_128bit_double_type >::infinity() << "]"
  562. << "]" "\n"; // end of row.
  563. fout << "[[quiet_NaN]"
  564. << "[" << std::numeric_limits<float>::quiet_NaN() << "]"
  565. << "[" << std::numeric_limits<double>::quiet_NaN() << "]"
  566. //#if LDBL_MANT_DIG > DBL_MANT_DIG
  567. // Long double is not just a duplication of double.
  568. << "[" << std::numeric_limits<long double>::quiet_NaN() << "]"
  569. //#endif
  570. << "[" << std::numeric_limits<cpp_dec_float_50 >::quiet_NaN() << "]"
  571. << "[" << std::numeric_limits<bin_128bit_double_type >::quiet_NaN() << "]"
  572. << "]" "\n"; // end of row.
  573. fout << "[[signaling_NaN]"
  574. << "[" << std::numeric_limits<float>::signaling_NaN() << "]"
  575. << "[" << std::numeric_limits<double>::signaling_NaN() << "]"
  576. //#if LDBL_MANT_DIG > DBL_MANT_DIG
  577. // Long double is not just a duplication of double.
  578. << "[" << std::numeric_limits<long double>::signaling_NaN() << "]"
  579. //#endif
  580. << "[" << std::numeric_limits<cpp_dec_float_50 >::signaling_NaN() << "]"
  581. << "[" << std::numeric_limits<bin_128bit_double_type >::signaling_NaN() << "]"
  582. << "]" "\n"; // end of row.
  583. fout << "[[denorm_min]"
  584. << "[" << std::numeric_limits<float>::denorm_min() << "]"
  585. << "[" << std::numeric_limits<double>::denorm_min() << "]"
  586. //#if LDBL_MANT_DIG > DBL_MANT_DIG
  587. // Long double is not just a duplication of double.
  588. << "[" << std::numeric_limits<long double>::denorm_min() << "]"
  589. //#endif
  590. << "[" << std::numeric_limits<cpp_dec_float_50 >::denorm_min() << "]"
  591. << "[" << std::numeric_limits<bin_128bit_double_type >::denorm_min() << "]"
  592. << "]" "\n"; // end of row.
  593. fout << "]" "\n"; // end of table;
  594. fout << "\n\n"
  595. "[endsect] [/section:limits32 Numeric limits for 32-bit platform]" "\n" << std::endl;
  596. fout.close();
  597. }
  598. catch(std::exception ex)
  599. {
  600. std::cout << "exception thrown: " << ex.what() << std::endl;
  601. }
  602. } // int main()
  603. /*
  604. Description: Autorun "J:\Cpp\Misc\Debug\numeric_limits_qbk.exe"
  605. Program: I:\boost-sandbox\multiprecision.cpp_bin_float\libs\multiprecision\doc\numeric_limits_qbk.cpp
  606. Wed Aug 28 14:17:21 2013
  607. BuildInfo:
  608. Platform Win32
  609. Compiler Microsoft Visual C++ version 10.0
  610. MSVC version 160040219.
  611. STL Dinkumware standard library version 520
  612. Boost version 1.55.0
  613. */