3 <meta http-equiv=
"Content-Type" content=
"text/html; charset=US-ASCII">
4 <title>Introduction
</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=
"../constants.html" title=
"Chapter 4. Mathematical Constants">
9 <link rel=
"prev" href=
"../constants.html" title=
"Chapter 4. Mathematical Constants">
10 <link rel=
"next" href=
"tutorial.html" title=
"Tutorial">
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=
"../constants.html"><img src=
"../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../constants.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=
"tutorial.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.constants_intro"></a><a class=
"link" href=
"constants_intro.html" title=
"Introduction">Introduction
</a>
28 </h2></div></div></div>
30 Boost.Math provides a collection of mathematical constants.
33 <a name=
"math_toolkit.constants_intro.h0"></a>
34 <span class=
"phrase"><a name=
"math_toolkit.constants_intro.why_use_boost_math_mathematical_"></a></span><a class=
"link" href=
"constants_intro.html#math_toolkit.constants_intro.why_use_boost_math_mathematical_">Why
35 use Boost.Math mathematical constants?
</a>
37 <div class=
"itemizedlist"><ul class=
"itemizedlist" style=
"list-style-type: disc; ">
40 Readable. For the very many jobs just using built-in like
<code class=
"computeroutput"><span class=
"keyword">double
</span></code>, you can just write expressions like
42 <pre class=
"programlisting"><span class=
"keyword">double
</span> <span class=
"identifier">area
</span> <span class=
"special">=
</span> <span class=
"identifier">pi
</span> <span class=
"special">*
</span> <span class=
"identifier">r
</span> <span class=
"special">*
</span> <span class=
"identifier">r
</span><span class=
"special">;
</span></pre>
44 (If that's all you want, jump direct to
<a class=
"link" href=
"tutorial/non_templ.html" title=
"Use in non-template code">use
45 in non-template code
</a>!)
49 Effortless - avoiding a search of reference sources.
52 Usable with both builtin floating point types, and user-defined, possibly
53 extended precision, types such as NTL, MPFR/GMP, mp_float: in the latter
54 case the constants are computed to the necessary precision and then cached.
57 Accurate - ensuring that the values are as accurate as possible for the
58 chosen floating-point type
59 <div class=
"itemizedlist"><ul class=
"itemizedlist" style=
"list-style-type: circle; ">
61 No loss of accuracy from repeated rounding of intermediate computations.
64 Result is computed with higher precision and only rounded once.
67 Less risk of inaccurate result from functions pow, trig and log at
68 <a href=
"http://en.wikipedia.org/wiki/Corner_case" target=
"_top">corner cases
</a>.
71 Less risk of
<a href=
"http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html" target=
"_top">cancellation
77 Portable - as possible between different systems using different floating-point
78 precisions: see
<a class=
"link" href=
"tutorial/templ.html" title=
"Use in template code">use in template
82 Tested - by comparison with other published sources, or separately computed
83 at long double precision.
86 Faster - can avoid (re-)calculation at runtime.
87 <div class=
"itemizedlist"><ul class=
"itemizedlist" style=
"list-style-type: circle; ">
89 If the value returned is a builtin type then it's returned by value
90 as a
<code class=
"computeroutput"><span class=
"keyword">constexpr
</span></code> (C++
11
91 feature, if available).
94 If the value is computed and cached (or constructed from a string
95 representation and cached), then it's returned by constant reference.
<br>
96 This can be significant if:
99 Functions pow, trig or log are used.
101 <li class=
"listitem">
102 Inside an inner loop.
104 <li class=
"listitem">
105 Using a high-precision UDT like
<a href=
"../../../../../libs/multiprecision/doc/html/index.html" target=
"_top">Boost.Multiprecision
</a>.
107 <li class=
"listitem">
108 Compiler optimizations possible with built-in types, especially
109 <code class=
"computeroutput"><span class=
"keyword">double
</span></code>, are not available.
115 <table xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width=
"100%"><tr>
116 <td align=
"left"></td>
117 <td align=
"right"><div class=
"copyright-footer">Copyright
© 2006-
2010,
2012-
2014 Nikhar Agrawal,
118 Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert
119 Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan R
åde, Gautam Sewani,
120 Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang
<p>
121 Distributed under the Boost Software License, Version
1.0. (See accompanying
122 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>)
127 <div class=
"spirit-nav">
128 <a accesskey=
"p" href=
"../constants.html"><img src=
"../../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"../constants.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=
"tutorial.html"><img src=
"../../../../../doc/src/images/next.png" alt=
"Next"></a>