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.77.1">
7 <link rel=
"home" href=
"../index.html" title=
"Math Toolkit 2.5.1">
8 <link rel=
"up" href=
"../cstdfloat.html" title=
"Chapter 3. 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">
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>
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>
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>
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"><</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">></span></code>.
34 These allow floating-point
<span class=
"bold"><strong>constants of at least the
35 specified width
</strong></span> to be declared:
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>
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>
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>
48 <div class=
"tip"><table border=
"0" summary=
"Tip">
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>
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:
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"><</span><span class=
"identifier">boost
</span><span class=
"special">::
</span><span class=
"identifier">floatmax_t
</span><span class=
"special">>();
</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"><</span><span class=
"identifier">boost
</span><span class=
"special">::
</span><span class=
"identifier">floatmax_t
</span><span class=
"special">>::
</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"><<</span> <span class=
"string">"Most precise pi = "</span> <span class=
"special"><<</span> <span class=
"identifier">pi_max
</span> <span class=
"special"><<</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>
66 from
<a href=
"../../../example/cstdfloat_example.cpp" target=
"_top">cstdfloat_example.cpp
</a>.
69 See the complete list of
<a class=
"link" href=
"constants.html" title=
"The Mathematical Constants">constants
</a>.
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
© 2006-
2010,
2012-
2014 Nikhar Agrawal,
75 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
76 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R
åde, Gautam Sewani,
77 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang
<p>
78 Distributed under the Boost Software License, Version
1.0. (See accompanying
79 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>)
84 <div class=
"spirit-nav">
85 <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>