Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / math / doc / html / math_toolkit / macros.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Floating-Point Constant Macros</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="greatest_typdefs.html" title="Greatest-width floating-point typedef">
10 <link rel="next" href="examples.html" title="Examples">
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="greatest_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="examples.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.macros"></a><a class="link" href="macros.html" title="Floating-Point Constant Macros">Floating-Point Constant Macros</a>
28 </h2></div></div></div>
29 <p>
30       All macros of the type <code class="computeroutput"><span class="identifier">BOOST_FLOAT16_C</span><span class="special">,</span> <span class="identifier">BOOST_FLOAT32_C</span><span class="special">,</span> <span class="identifier">BOOST_FLOAT64_C</span><span class="special">,</span> <span class="identifier">BOOST_FLOAT80_C</span><span class="special">,</span> <span class="identifier">BOOST_FLOAT128_C</span><span class="special">,</span> </code> and <code class="computeroutput"><span class="identifier">BOOST_FLOATMAX_C</span></code>
31       are always defined after inclusion of <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">cstdfloat</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>.
32     </p>
33 <p>
34       These allow floating-point <span class="bold"><strong>constants of at least the
35       specified width</strong></span> to be declared:
36     </p>
37 <pre class="programlisting"><span class="comment">// Declare Archimedes' constant using float32_t with approximately 7 decimal digits of precision.</span>
38 <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">float32_t</span> <span class="identifier">pi</span> <span class="special">=</span> <span class="identifier">BOOST_FLOAT32_C</span><span class="special">(</span><span class="number">3.1415926536</span><span class="special">);</span>
39
40 <span class="comment">// Declare the Euler-gamma constant with approximately 15 decimal digits of precision.</span>
41 <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">float64_t</span> <span class="identifier">euler</span> <span class="special">=</span>
42    <span class="identifier">BOOST_FLOAT64_C</span><span class="special">(</span><span class="number">0.57721566490153286060651209008240243104216</span><span class="special">);</span>
43
44 <span class="comment">// Declare the Golden Ratio constant with the maximum decimal digits of precision that the platform supports.</span>
45 <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span> <span class="identifier">golden_ratio</span> <span class="special">=</span>
46    <span class="identifier">BOOST_FLOATMAX_C</span><span class="special">(</span><span class="number">1.61803398874989484820458683436563811772</span><span class="special">);</span>
47 </pre>
48 <div class="tip"><table border="0" summary="Tip">
49 <tr>
50 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../doc/src/images/tip.png"></td>
51 <th align="left">Tip</th>
52 </tr>
53 <tr><td align="left" valign="top"><p>
54         Boost.Math provides many constants 'built-in', so always use Boost.Math constants
55         if available, for example:
56       </p></td></tr>
57 </table></div>
58 <pre class="programlisting"><span class="comment">// Display the constant pi to the maximum available precision.</span>
59   <span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span> <span class="identifier">pi_max</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">constants</span><span class="special">::</span><span class="identifier">pi</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span><span class="special">&gt;();</span>
60   <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">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">floatmax_t</span><span class="special">&gt;::</span><span class="identifier">digits10</span><span class="special">);</span>
61   <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Most precise pi = "</span>  <span class="special">&lt;&lt;</span> <span class="identifier">pi_max</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>
62 <span class="comment">// If floatmax_t is float_128_t, then</span>
63 <span class="comment">// Most precise pi = 3.141592653589793238462643383279503</span>
64 </pre>
65 <p>
66       from <a href="../../../example/cstdfloat_example.cpp" target="_top">cstdfloat_example.cpp</a>.
67     </p>
68 <p>
69       See the complete list of <a class="link" href="constants.html" title="The Mathematical Constants">constants</a>.
70     </p>
71 </div>
72 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
73 <td align="left"></td>
74 <td align="right"><div class="copyright-footer">Copyright &#169; 2006-2019 Nikhar
75       Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
76       Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
77       R&#229;de, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
78       Daryle Walker and Xiaogang Zhang<p>
79         Distributed under the Boost Software License, Version 1.0. (See accompanying
80         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>)
81       </p>
82 </div></td>
83 </tr></table>
84 <hr>
85 <div class="spirit-nav">
86 <a accesskey="p" href="greatest_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="examples.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
87 </div>
88 </body>
89 </html>