greatest_typdefs.html 8.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4. <title>Greatest-width floating-point typedef</title>
  5. <link rel="stylesheet" href="../math.css" type="text/css">
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
  7. <link rel="home" href="../index.html" title="Math Toolkit 2.11.0">
  8. <link rel="up" href="../cstdfloat.html" title="Chapter&#160;3.&#160;Specified-width floating-point typedefs">
  9. <link rel="prev" href="fastest_typdefs.html" title="Fastest floating-point typedefs">
  10. <link rel="next" href="macros.html" title="Floating-Point Constant Macros">
  11. </head>
  12. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  13. <table cellpadding="2" width="100%"><tr>
  14. <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
  15. <td align="center"><a href="../../../../../index.html">Home</a></td>
  16. <td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
  17. <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
  18. <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
  19. <td align="center"><a href="../../../../../more/index.htm">More</a></td>
  20. </tr></table>
  21. <hr>
  22. <div class="spirit-nav">
  23. <a accesskey="p" href="fastest_typdefs.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../cstdfloat.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="macros.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  24. </div>
  25. <div class="section">
  26. <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  27. <a name="math_toolkit.greatest_typdefs"></a><a class="link" href="greatest_typdefs.html" title="Greatest-width floating-point typedef">Greatest-width floating-point
  28. typedef</a>
  29. </h2></div></div></div>
  30. <p>
  31. The <code class="computeroutput"><span class="keyword">typedef</span> <span class="identifier">floatmax_t</span></code>
  32. designates a floating-point type capable of representing any value of any floating-point
  33. type in a given platform most precisely.
  34. </p>
  35. <p>
  36. The greatest-width <code class="computeroutput"><span class="keyword">typedef</span></code> is
  37. provided for all platforms, but, of course, the size may vary.
  38. </p>
  39. <p>
  40. To provide floating-point <span class="bold"><strong>constants</strong></span> most precisely
  41. representable for a <code class="computeroutput"><span class="identifier">floatmax_t</span></code>
  42. type, use the macro <code class="computeroutput"><span class="identifier">BOOST_FLOATMAX_C</span></code>.
  43. </p>
  44. <p>
  45. For example, replace a constant <code class="computeroutput"><span class="number">123.4567890123456789012345678901234567890</span></code>
  46. with
  47. </p>
  48. <pre class="programlisting"><span class="identifier">BOOST_FLOATMAX_C</span><span class="special">(</span><span class="number">123.4567890123456789012345678901234567890</span><span class="special">)</span>
  49. </pre>
  50. <p>
  51. If, for example, <code class="computeroutput"><span class="identifier">floatmax_t</span></code>
  52. is <code class="computeroutput"><span class="identifier">float64_t</span></code> then the result
  53. will be equivalent to a <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code> suffixed with L, but if <code class="computeroutput"><span class="identifier">floatmax_t</span></code> is <code class="computeroutput"><span class="identifier">float128_t</span></code>
  54. then the result will be equivalent to a <code class="computeroutput"><span class="identifier">quad</span>
  55. <span class="identifier">type</span></code> suffixed with Q (assuming, of
  56. course, that <code class="computeroutput"><span class="identifier">float128_t</span></code> (<code class="computeroutput"><span class="identifier">__float128</span></code> or <code class="computeroutput"><span class="identifier">Quad</span></code>)
  57. is supported).
  58. </p>
  59. <p>
  60. If we display with <code class="computeroutput"><span class="identifier">max_digits10</span></code>,
  61. the maximum possibly significant decimal digits:
  62. </p>
  63. <pre class="programlisting"><span class="preprocessor">#ifdef</span> <span class="identifier">BOOST_FLOAT32_C</span>
  64. <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">.</span><span class="identifier">precision</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">max_digits10</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">float32_t</span><span class="special">&gt;());</span> <span class="comment">// Show all significant decimal digits,</span>
  65. <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">.</span><span class="identifier">setf</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios</span><span class="special">::</span><span class="identifier">showpoint</span><span class="special">);</span> <span class="comment">// including all significant trailing zeros.</span>
  66. <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"BOOST_FLOAT32_C(123.4567890123456789012345678901234567890) = "</span>
  67. <span class="special">&lt;&lt;</span> <span class="identifier">BOOST_FLOAT32_C</span><span class="special">(</span><span class="number">123.4567890123456789012345678901234567890</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
  68. <span class="comment">// BOOST_FLOAT32_C(123.4567890123456789012345678901234567890) = 123.456787</span>
  69. <span class="preprocessor">#endif</span>
  70. </pre>
  71. <p>
  72. then on a 128-bit platform (GCC 4.8.1 or higher with quadmath):
  73. </p>
  74. <pre class="programlisting"><span class="identifier">BOOST_FLOAT32_C</span><span class="special">(</span><span class="number">123.4567890123456789012345678901234567890</span><span class="special">)</span> <span class="special">=</span> <span class="number">123.456787</span>
  75. <span class="identifier">BOOST_FLOAT64_C</span><span class="special">(</span><span class="number">123.4567890123456789012345678901234567890</span><span class="special">)</span> <span class="special">=</span> <span class="number">123.45678901234568</span>
  76. <span class="identifier">BOOST_FLOAT80_C</span><span class="special">(</span><span class="number">123.4567890123456789012345678901234567890</span><span class="special">)</span> <span class="special">=</span> <span class="number">123.456789012345678903</span>
  77. <span class="identifier">BOOST_FLOAT128_C</span><span class="special">(</span><span class="number">123.4567890123456789012345678901234567890</span><span class="special">)</span> <span class="special">=</span> <span class="number">123.456789012345678901234567890123453</span>
  78. </pre>
  79. </div>
  80. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  81. <td align="left"></td>
  82. <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2019 Nikhar
  83. Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
  84. Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
  85. R&#229;de, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
  86. Daryle Walker and Xiaogang Zhang<p>
  87. Distributed under the Boost Software License, Version 1.0. (See accompanying
  88. file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
  89. </p>
  90. </div></td>
  91. </tr></table>
  92. <hr>
  93. <div class="spirit-nav">
  94. <a accesskey="p" href="fastest_typdefs.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../cstdfloat.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="macros.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
  95. </div>
  96. </body>
  97. </html>