diff options
Diffstat (limited to 'libs/math/doc/sf_and_dist/html/math_toolkit/constants')
8 files changed, 2965 insertions, 0 deletions
diff --git a/libs/math/doc/sf_and_dist/html/math_toolkit/constants/FAQ.html b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/FAQ.html new file mode 100644 index 0000000000..0c5b058306 --- /dev/null +++ b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/FAQ.html @@ -0,0 +1,480 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> +<title>FAQs</title> +<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.76.1"> +<link rel="home" href="../../index.html" title="Math Toolkit"> +<link rel="up" href="../constants.html" title="Mathematical Constants"> +<link rel="prev" href="new_const.html" title="Defining New Constants"> +<link rel="next" href="../toolkit.html" title="Tools and Internal Details"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"><tr> +<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> +<td align="center"><a href="../../../../../../../index.html">Home</a></td> +<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> +<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> +<td align="center"><a href="../../../../../../../more/index.htm">More</a></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="new_const.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="../toolkit.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +<div class="section math_toolkit_constants_FAQ"> +<div class="titlepage"><div><div><h3 class="title"> +<a name="math_toolkit.constants.FAQ"></a><a class="link" href="FAQ.html" title="FAQs">FAQs</a> +</h3></div></div></div> +<h5> +<a name="math_toolkit.constants.FAQ.h0"></a> + <span><a name="math_toolkit.constants.FAQ.why_are__emphasis_these__emphasis__constants_chosen_"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.why_are__emphasis_these__emphasis__constants_chosen_">Why + are <span class="emphasis"><em>these</em></span> Constants Chosen?</a> + </h5> +<p> + It is, of course, impossible to please everyone with a list like this. + </p> +<p> + Some of the criteria we have used are: + </p> +<div class="itemizedlist"><ul class="itemizedlist" type="disc"> +<li class="listitem"> + Used in Boost.Math. + </li> +<li class="listitem"> + Commonly used. + </li> +<li class="listitem"> + Expensive to compute. + </li> +<li class="listitem"> + Requested by users. + </li> +<li class="listitem"> + <a href="http://en.wikipedia.org/wiki/Mathematical_constant" target="_top">Used + in science and mathematics.</a> + </li> +<li class="listitem"> + No integer values (because so cheap to construct).<br> (You can easily + define your own if found convenient, for example: <code class="computeroutput"><span class="identifier">FPT</span> + <span class="identifier">one</span> <span class="special">=</span><span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">FPT</span><span class="special">>(</span><span class="number">42</span><span class="special">);</span></code>). + </li> +</ul></div> +<h5> +<a name="math_toolkit.constants.FAQ.h1"></a> + <span><a name="math_toolkit.constants.FAQ.how_are_constants_named_"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.how_are_constants_named_">How + are constants named?</a> + </h5> +<div class="itemizedlist"><ul class="itemizedlist" type="disc"> +<li class="listitem"> + Not macros, so no upper case. + </li> +<li class="listitem"> + All lower case (following C++ standard names). + </li> +<li class="listitem"> + No CamelCase. + </li> +<li class="listitem"> + Underscore as _ delimiter between words. + </li> +<li class="listitem"> + Numbers spelt as words rather than decimal digits (except following pow). + </li> +<li class="listitem"> + Abbreviation conventions: + <div class="itemizedlist"><ul class="itemizedlist" type="circle"> +<li class="listitem"> + root for square root. + </li> +<li class="listitem"> + cbrt for cube root. + </li> +<li class="listitem"> + pow for pow function using decimal digits like pow23 for n<sup>2/3</sup>. + </li> +<li class="listitem"> + div for divided by or operator /. + </li> +<li class="listitem"> + minus for operator -, plus for operator +. + </li> +<li class="listitem"> + sqr for squared. + </li> +<li class="listitem"> + cubed for cubed n<sup>3</sup>. + </li> +<li class="listitem"> + words for greek, like π, ζ and Γ. + </li> +<li class="listitem"> + words like half, third, three_quarters, sixth for fractions. (Digit(s) + can get muddled). + </li> +<li class="listitem"> + log10 for log<sub>10</sub> + </li> +<li class="listitem"> + ln for log<sub>e</sub> + </li> +</ul></div> + </li> +</ul></div> +<h5> +<a name="math_toolkit.constants.FAQ.h2"></a> + <span><a name="math_toolkit.constants.FAQ.how_are_the_constants_derived_"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.how_are_the_constants_derived_">How are + the constants derived?</a> + </h5> +<p> + The constants have all been calculated using high-precision software working + with up to 300-bit precision giving about 100 decimal digits. (The precision + can be arbitrarily chosen and is limited only by compute time). + </p> +<h5> +<a name="math_toolkit.constants.FAQ.h3"></a> + <span><a name="math_toolkit.constants.FAQ.how_accurate_are_the_constants_"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.how_accurate_are_the_constants_">How + Accurate are the constants?</a> + </h5> +<p> + The minimum accuracy chosen (100 decimal digits) exceeds the accuracy of + reasonably-foreseeable floating-point hardware (256-bit) and should meet + most high-precision computations. + </p> +<h5> +<a name="math_toolkit.constants.FAQ.h4"></a> + <span><a name="math_toolkit.constants.FAQ.how_are_the_constants_tested_"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.how_are_the_constants_tested_">How are + the constants tested?</a> + </h5> +<div class="orderedlist"><ol class="orderedlist" type="1"> +<li class="listitem"> + Comparison using Boost.Test BOOST_CHECK_CLOSE_FRACTION using long double + literals, with at least 35 decimal digits, enough to be accurate for + all long double implementations. The tolerance is usually twice <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span> + <span class="identifier">epsilon</span></code>. + </li> +<li class="listitem"> + Comparison with calculation at long double precision. This often requires + a slightly higher tolerance than two epsilon because of computational + noise from round-off etc, especially when trig and other functions are + called. + </li> +<li class="listitem"> + Comparison with independent published values, for example, using <a href="http://oeis.org/" target="_top">The On-Line Encyclopedia of Integer Sequences + (OEIS)</a> again using at least 35 decimal digits strings. + </li> +<li class="listitem"> + Comparison with independely calculated values using arbitrary precision + tools like <a href="http://www.wolfram.com/mathematica/" target="_top">Mathematica</a>, + again using at least 35 decimal digits literal strings. + </li> +</ol></div> +<div class="warning"><table border="0" summary="Warning"> +<tr> +<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td> +<th align="left">Warning</th> +</tr> +<tr><td align="left" valign="top"><p> + We have not yet been able to <span class="bold"><strong>check</strong></span> that + <span class="bold"><strong>all</strong></span> constants are accurate at the full + arbitrary precision, at present 100 decimal digits. But certain key values + like <code class="computeroutput"><span class="identifier">e</span></code> and <code class="computeroutput"><span class="identifier">pi</span></code> appear to be accurate and internal + consistencies suggest that others are this accurate too. + </p></td></tr> +</table></div> +<h5> +<a name="math_toolkit.constants.FAQ.h5"></a> + <span><a name="math_toolkit.constants.FAQ.why_is_portability_important_"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.why_is_portability_important_">Why is + Portability important?</a> + </h5> +<p> + Code written using math constants is easily portable even when using different + floating-point types with differing precision. + </p> +<p> + It is a mistake to expect that results of computations will be <span class="bold"><strong>identical</strong></span>, but you can achieve the <span class="bold"><strong>best + accuracy possible for the floating-point type in use</strong></span>. + </p> +<p> + This has no extra cost to the user, but reduces irritating, and often confusing + and very hard-to-trace effects, caused by the intrinsically limited precision + of floating-point calculations. + </p> +<p> + A harmless symptom of this limit is a spurious least-significant digit; at + worst, slightly inaccurate constants sometimes cause iterating algorithms + to diverge wildly because internal comparisons just fail. + </p> +<h5> +<a name="math_toolkit.constants.FAQ.h6"></a> + <span><a name="math_toolkit.constants.FAQ.what_is_the_internal_format_of_the_constants__and_why_"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.what_is_the_internal_format_of_the_constants__and_why_">What + is the Internal Format of the constants, and why?</a> + </h5> +<p> + See <a class="link" href="tutorial.html" title="Tutorial">tutorial</a> above + for normal use, but this FAQ explains the internal details used for the constants. + </p> +<p> + Constants are stored as 100 decimal digit values. However, some compilers + do not accept decimal digits strings as long as this. So the constant is + split into two parts, with the first containing at least 128-bit long double + precision (35 decimal digits), and for consistency should be in scientific + format with a signed exponent. + </p> +<p> + The second part is the value of the constant expressed as a string literal, + accurate to at least 100 decimal digits (in practice that means at least + 102 digits). Again for consistency use scientific format with a signed exponent. + </p> +<p> + For types with precision greater than a long double, then if T is constructible + <code class="computeroutput"><span class="identifier">T</span> </code>is constructible from a + <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span></code> then it's directly constructed from the + string, otherwise we fall back on lexical_cast to convert to type <code class="computeroutput"><span class="identifier">T</span></code>. (Using a string is necessary because + you can't use a numeric constant since even a <code class="computeroutput"><span class="keyword">long</span> + <span class="keyword">double</span></code> might not have enough digits). + </p> +<p> + So, for example, a constant like pi is internally defined as + </p> +<pre class="programlisting"><span class="identifier">BOOST_DEFINE_MATH_CONSTANT</span><span class="special">(</span><span class="identifier">pi</span><span class="special">,</span> <span class="number">3.141592653589793238462643383279502884e+00</span><span class="special">,</span> <span class="string">"3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651e+00"</span><span class="special">);</span> +</pre> +<p> + In this case the significand is 109 decimal digits, ensuring 100 decimal + digits are exact, and exponent is zero. + </p> +<p> + See <a class="link" href="new_const.html" title="Defining New Constants">defining new constants</a> + to calculate new constants. + </p> +<p> + A macro definition like this can be pasted into user code where convenient, + or into <code class="computeroutput"><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">hpp</span></code> if + it is to be added to the Boost.Math library. + </p> +<h5> +<a name="math_toolkit.constants.FAQ.h7"></a> + <span><a name="math_toolkit.constants.FAQ.what_floating_point_types_could_i_use_"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.what_floating_point_types_could_i_use_">What + Floating-point Types could I use?</a> + </h5> +<p> + Apart from the built-in floating-point types <code class="computeroutput"><span class="keyword">float</span></code>, + <code class="computeroutput"><span class="keyword">double</span></code>, <code class="computeroutput"><span class="keyword">long</span> + <span class="keyword">double</span></code>, there are several arbitrary + precision floating-point classes available, but most are not licensed for + commercial use. + </p> +<h6> +<a name="math_toolkit.constants.FAQ.h8"></a> + <span><a name="math_toolkit.constants.FAQ.boost_multiprecision_by_christopher_kormanyos"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.boost_multiprecision_by_christopher_kormanyos">Boost.Multiprecision + by Christopher Kormanyos</a> + </h6> +<p> + This work is based on an earlier work called e-float: Algorithm 910: A Portable + C++ Multiple-Precision System for Special-Function Calculations, in ACM TOMS, + {VOL 37, ISSUE 4, (February 2011)} (C) ACM, 2011. <a href="http://doi.acm.org/10.1145/1916461.1916469" target="_top">http://doi.acm.org/10.1145/1916461.1916469</a> + <a href="https://svn.boost.org/svn/boost/sandbox/e_float/" target="_top">e_float</a> + but is now re-factored and available under the Boost license in the Boost-sandbox + at <a href="https://svn.boost.org/svn/boost/sandbox/multiprecision/" target="_top">multiprecision</a> + where it is being refined and prepared for review. + </p> +<h6> +<a name="math_toolkit.constants.FAQ.h9"></a> + <span><a name="math_toolkit.constants.FAQ.boost_cpp_float_by_john_maddock_using_expression_templates"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.boost_cpp_float_by_john_maddock_using_expression_templates">Boost.cpp_float + by John Maddock using Expression Templates</a> + </h6> +<p> + <a href="https://svn.boost.org/svn/boost/sandbox/big_number/" target="_top">Big Number</a> + which is a reworking of <a href="https://svn.boost.org/svn/boost/sandbox/e_float/" target="_top">e_float</a> + by Christopher Kormanyos to use expression templates for faster execution. + </p> +<h6> +<a name="math_toolkit.constants.FAQ.h10"></a> + <span><a name="math_toolkit.constants.FAQ.ntl_class_quad_float"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.ntl_class_quad_float">NTL + class quad_float</a> + </h6> +<p> + <a href="http://shoup.net/ntl/" target="_top">NTL</a> by Victor Shoup has fixed + and arbitrary high precision fixed and floating-point types. However none + of these are licenced for commercial use. + </p> +<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">NTL</span><span class="special">/</span><span class="identifier">quad_float</span><span class="special">.</span><span class="identifier">h</span><span class="special">></span> <span class="comment">// quad precision 106-bit, about 32 decimal digits.</span> +<span class="keyword">using</span> <span class="identifier">NTL</span><span class="special">::</span><span class="identifier">to_quad_float</span><span class="special">;</span> <span class="comment">// Less precise than arbitrary precision NTL::RR.</span> +</pre> +<p> + NTL class <code class="computeroutput"><span class="identifier">quad_float</span></code>, which + gives a form of quadruple precision, 106-bit significand (but without an + extended exponent range.) With an IEC559/IEEE 754 compatible processor, for + example Intel X86 family, with 64-bit double, and 53-bit significand, using + the significands of <span class="bold"><strong>two</strong></span> 64-bit doubles, + if <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="keyword">double</span><span class="special">>::</span><span class="identifier">digits10</span></code> is 16, then we get about twice + the precision, so <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">quad_float</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">()</span></code> + should be 32. (the default <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">RR</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">()</span></code> should be about 40). (which seems to agree + with experiments). We output constants (including some noisy bits, an approximation + to <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">RR</span><span class="special">>::</span><span class="identifier">max_digits10</span><span class="special">()</span></code>) + by adding 2 extra decimal digits, so using <code class="computeroutput"><span class="identifier">quad_float</span><span class="special">::</span><span class="identifier">SetOutputPrecision</span><span class="special">(</span><span class="number">32</span> <span class="special">+</span> + <span class="number">2</span><span class="special">);</span></code> + </p> +<p> + Apple Mac/Darwin uses a similar <span class="emphasis"><em>doubledouble</em></span> 106-bit + for its built-in <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code> + type. + </p> +<div class="note"><table border="0" summary="Note"> +<tr> +<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td> +<th align="left">Note</th> +</tr> +<tr><td align="left" valign="top"><p> + The precision of all <code class="computeroutput"><span class="identifier">doubledouble</span></code> + floating-point types is rather odd and values given are only approximate. + </p></td></tr> +</table></div> +<h6> +<a name="math_toolkit.constants.FAQ.h11"></a> + <span><a name="math_toolkit.constants.FAQ.ntl_class_rr"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.ntl_class_rr">NTL + class RR</a> + </h6> +<p> + Arbitrary precision floating point with NTL class RR, default is 150 bit + (about 50 decimal digits) used here with 300 bit to output 100 decimal digits, + enough for many practical non-'number-theoretic' C++ applications. + </p> +<p> + NTL is <span class="bold"><strong>not licenced for commercial use</strong></span>. + </p> +<p> + This class is used in Boost.Math and an option when using big_number projects + to calculate new math constants. + </p> +<h6> +<a name="math_toolkit.constants.FAQ.h12"></a> + <span><a name="math_toolkit.constants.FAQ.gmp_and_mpfr"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.gmp_and_mpfr">GMP + and MPFR</a> + </h6> +<p> + <a href="../../gmplib.org" target="_top">GMP</a> and <a href="http://www.mpfr.org/" target="_top">MPFR</a> + have also been used to compute constants, but are licensed under the <a href="http://www.gnu.org/copyleft/lesser.html" target="_top">Lesser GPL license</a> + and are <span class="bold"><strong>not licensed for commercial use</strong></span>. + </p> +<h5> +<a name="math_toolkit.constants.FAQ.h13"></a> + <span><a name="math_toolkit.constants.FAQ.what_happened_to_a_previous_collection_of_constants_proposed_for_boost_"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.what_happened_to_a_previous_collection_of_constants_proposed_for_boost_">What + happened to a previous collection of constants proposed for Boost?</a> + </h5> +<p> + A review concluded that the way in which the constants were presented did + not meet many peoples needs. None of the methods proposed met many users' + essential requirement to allow writing simply <code class="computeroutput"><span class="identifier">pi</span></code> + rather than <code class="computeroutput"><span class="identifier">pi</span><span class="special">()</span></code>. + Many science and engineering equations look difficult to read when because + function call brackets can be confused with the many other brackets often + needed. All the methods then proposed of avoiding the brackets failed to + meet all needs, often on grounds of complexity and lack of applicability + to various realistic scenarios. + </p> +<p> + So the simple namespace method, proposed on its own, but rejected at the + first review, has been added to allow users to have convenient access to + float, double and long double values, but combined with template struct and + functions to allow simultaneous use with other non-built-in floating-point + types. + </p> +<h5> +<a name="math_toolkit.constants.FAQ.h14"></a> + <span><a name="math_toolkit.constants.FAQ.why_do_the_constants__internally__have_a_struct_rather_than_a_simple_function_"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.why_do_the_constants__internally__have_a_struct_rather_than_a_simple_function_">Why + do the constants (internally) have a struct rather than a simple function?</a> + </h5> +<p> + A function mechanism was provided by in previous versions of Boost.Math. + </p> +<p> + The new mechanism is to permit partial specialization. See Custom Specializing + a constant above. It should also allow use with other packages like <a href="http://www.ttmath.org/" target="_top">ttmath Bignum C++ library.</a> + </p> +<h5> +<a name="math_toolkit.constants.FAQ.h15"></a> + <span><a name="math_toolkit.constants.FAQ.where_can_i_find_other_high_precision_constants_"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.where_can_i_find_other_high_precision_constants_">Where + can I find other high precision constants?</a> + </h5> +<div class="orderedlist"><ol class="orderedlist" type="1"> +<li class="listitem"> + Constants with very high precision and good accuracy (>40 decimal + digits) from Simon Plouffe's web based collection <a href="http://pi.lacim.uqam.ca/eng/" target="_top">http://pi.lacim.uqam.ca/eng/</a>. + </li> +<li class="listitem"> + <a href="https://oeis.org/" target="_top">The On-Line Encyclopedia of Integer Sequences + (OEIS)</a> + </li> +<li class="listitem"> + Checks using printed text optically scanned values and converted from: + D. E. Knuth, Art of Computer Programming, Appendix A, Table 1, Vol 1, + ISBN 0 201 89683 4 (1997) + </li> +<li class="listitem"> + M. Abrahamovitz & I. E. Stegun, National Bureau of Standards, Handbook + of Mathematical Functions, a reference source for formulae now superceded + by + </li> +<li class="listitem"> + Frank W. Olver, Daniel W. Lozier, Ronald F. Boisvert, Charles W. Clark, + NIST Handbook of Mathemetical Functions, Cambridge University Press, + ISBN 978-0-521-14063-8, 2010. + </li> +<li class="listitem"> + John F Hart, Computer Approximations, Kreiger (1978) ISBN 0 88275 642 + 7. + </li> +<li class="listitem"> + Some values from Cephes Mathematical Library, Stephen L. Moshier and + CALC100 100 decimal digit Complex Variable Calculator Program, a DOS + utility. + </li> +<li class="listitem"> + Xavier Gourdon, Pascal Sebah, 50 decimal digits constants at <a href="http://numbers.computation.free.fr/Constants/constants.html" target="_top">Number, + constants and computation</a>. + </li> +</ol></div> +<h5> +<a name="math_toolkit.constants.FAQ.h16"></a> + <span><a name="math_toolkit.constants.FAQ.where_are_physical_constants_"></a></span><a class="link" href="FAQ.html#math_toolkit.constants.FAQ.where_are_physical_constants_">Where + are Physical Constants?</a> + </h5> +<p> + Not here in this Boost.Math collection, because physical constants: + </p> +<div class="itemizedlist"><ul class="itemizedlist" type="disc"> +<li class="listitem"> + Are measurements. + </li> +<li class="listitem"> + Are not truly constant and keeping changing as mensuration technology + improves. + </li> +<li class="listitem"> + Have a instrinsic uncertainty. + </li> +<li class="listitem"> + Mathematical constants are stored and represented at varying precision, + but should never be inaccurate. + </li> +</ul></div> +<p> + Some physical constants may be available in Boost.Units. + </p> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><div class="copyright-footer">Copyright © 2006-2010 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno + Lalande, Johan Råde, Gautam Sewani, Thijs van den Berg and Benjamin Sobotta<p> + Distributed under the Boost Software License, Version 1.0. (See accompanying + 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>) + </p> +</div></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="new_const.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="../toolkit.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +</body> +</html> diff --git a/libs/math/doc/sf_and_dist/html/math_toolkit/constants/constants.html b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/constants.html new file mode 100644 index 0000000000..e232c66181 --- /dev/null +++ b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/constants.html @@ -0,0 +1,1489 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> +<title>The Mathematical Constants</title> +<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.76.1"> +<link rel="home" href="../../index.html" title="Math Toolkit"> +<link rel="up" href="../constants.html" title="Mathematical Constants"> +<link rel="prev" href="tutorial/user_def.html" title="Use With User Defined Types"> +<link rel="next" href="new_const.html" title="Defining New Constants"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"><tr> +<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> +<td align="center"><a href="../../../../../../../index.html">Home</a></td> +<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> +<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> +<td align="center"><a href="../../../../../../../more/index.htm">More</a></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="tutorial/user_def.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="new_const.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +<div class="section math_toolkit_constants_constants"> +<div class="titlepage"><div><div><h3 class="title"> +<a name="math_toolkit.constants.constants"></a><a class="link" href="constants.html" title="The Mathematical Constants">The Mathematical Constants</a> +</h3></div></div></div> +<p> + This section lists the mathematical constants, their use(s) (and sometimes + rationale for their inclusion). + </p> +<div class="table"> +<a name="math_toolkit.constants.constants.mathematical_constants"></a><p class="title"><b>Table 51. Mathematical Constants</b></p> +<div class="table-contents"><table class="table" summary="Mathematical Constants"> +<colgroup> +<col> +<col> +<col> +<col> +</colgroup> +<thead><tr> +<th> + <p> + name + </p> + </th> +<th> + <p> + formula + </p> + </th> +<th> + <p> + Value (6 decimals) + </p> + </th> +<th> + <p> + Uses and Rationale + </p> + </th> +</tr></thead> +<tbody> +<tr> +<td> + <p> + <span class="bold"><strong>Rational fractions</strong></span> + </p> + </td> +<td> + </td> +<td> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + half + </p> + </td> +<td> + <p> + 1/2 + </p> + </td> +<td> + <p> + 0.5 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + third + </p> + </td> +<td> + <p> + 1/3 + </p> + </td> +<td> + <p> + 0.333333 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + two_thirds + </p> + </td> +<td> + <p> + 2/3 + </p> + </td> +<td> + <p> + 0.66667 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + three_quarters + </p> + </td> +<td> + <p> + 3/4 + </p> + </td> +<td> + <p> + 0.75 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + <span class="bold"><strong>two and related</strong></span> + </p> + </td> +<td> + </td> +<td> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + root_two + </p> + </td> +<td> + <p> + √2 + </p> + </td> +<td> + <p> + 1.41421 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + root_three + </p> + </td> +<td> + <p> + √3 + </p> + </td> +<td> + <p> + 1.73205 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + half_root_two + </p> + </td> +<td> + <p> + √2 /2 + </p> + </td> +<td> + <p> + 0.707106 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + ln_two + </p> + </td> +<td> + <p> + ln(2) + </p> + </td> +<td> + <p> + 0.693147 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + ln_ten + </p> + </td> +<td> + <p> + ln(10) + </p> + </td> +<td> + <p> + 2.30258 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + ln_ln_two + </p> + </td> +<td> + <p> + ln(ln(2)) + </p> + </td> +<td> + <p> + -0.366512 + </p> + </td> +<td> + <p> + Gumbel distribution median + </p> + </td> +</tr> +<tr> +<td> + <p> + root_ln_four + </p> + </td> +<td> + <p> + √ln(4) + </p> + </td> +<td> + <p> + 1.177410 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + one_div_root_two + </p> + </td> +<td> + <p> + 1/√2 + </p> + </td> +<td> + <p> + 0.707106 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + <span class="bold"><strong>π and related</strong></span> + </p> + </td> +<td> + </td> +<td> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + pi + </p> + </td> +<td> + <p> + pi + </p> + </td> +<td> + <p> + 3.14159 + </p> + </td> +<td> + <p> + Ubiquitous. Archimedes constant <a href="http://en.wikipedia.org/wiki/Pi" target="_top">π</a> + </p> + </td> +</tr> +<tr> +<td> + <p> + half_pi + </p> + </td> +<td> + <p> + π/2 + </p> + </td> +<td> + <p> + 1.570796 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + third_pi + </p> + </td> +<td> + <p> + π/3 + </p> + </td> +<td> + <p> + 1.04719 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + sixth_pi + </p> + </td> +<td> + <p> + π/6 + </p> + </td> +<td> + <p> + 0.523598 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + two_pi + </p> + </td> +<td> + <p> + 2π + </p> + </td> +<td> + <p> + 6.28318 + </p> + </td> +<td> + <p> + Many uses, most simply, circumference of a circle + </p> + </td> +</tr> +<tr> +<td> + <p> + two_thirds_pi + </p> + </td> +<td> + <p> + 2/3 π + </p> + </td> +<td> + <p> + 2.09439 + </p> + </td> +<td> + <p> + <a href="http://en.wikipedia.org/wiki/Sphere#Volume_of_a_sphere" target="_top">volume + of a hemi-sphere</a> = 4/3 π r³ + </p> + </td> +</tr> +<tr> +<td> + <p> + three_quarters_pi + </p> + </td> +<td> + <p> + 3/4 π + </p> + </td> +<td> + <p> + 2.35619 + </p> + </td> +<td> + <p> + <a href="http://en.wikipedia.org/wiki/Sphere#Volume_of_a_sphere" target="_top">volume + of a hemi-sphere</a> = 4/3 π r³ + </p> + </td> +</tr> +<tr> +<td> + <p> + four_thirds_pi + </p> + </td> +<td> + <p> + 4/3 π + </p> + </td> +<td> + <p> + 4.18879 + </p> + </td> +<td> + <p> + <a href="http://en.wikipedia.org/wiki/Sphere#Volume_of_a_sphere" target="_top">volume + of a sphere</a> = 4/3 π r³ + </p> + </td> +</tr> +<tr> +<td> + <p> + one_div_two_pi + </p> + </td> +<td> + <p> + 1/(2π) + </p> + </td> +<td> + <p> + 1.59155 + </p> + </td> +<td> + <p> + Widely used + </p> + </td> +</tr> +<tr> +<td> + <p> + root_pi + </p> + </td> +<td> + <p> + √π + </p> + </td> +<td> + <p> + 1.77245 + </p> + </td> +<td> + <p> + Widely used + </p> + </td> +</tr> +<tr> +<td> + <p> + root_half_pi + </p> + </td> +<td> + <p> + √ π/2 + </p> + </td> +<td> + <p> + 1.25331 + </p> + </td> +<td> + <p> + Widely used + </p> + </td> +</tr> +<tr> +<td> + <p> + root_two_pi + </p> + </td> +<td> + <p> + √ π*2 + </p> + </td> +<td> + <p> + 2.50662 + </p> + </td> +<td> + <p> + Widely used + </p> + </td> +</tr> +<tr> +<td> + <p> + one_div_root_pi + </p> + </td> +<td> + <p> + 1/√π + </p> + </td> +<td> + <p> + 0.564189 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + one_div_root_two_pi + </p> + </td> +<td> + <p> + 1/√(2π) + </p> + </td> +<td> + <p> + 0.398942 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + root_one_div_pi + </p> + </td> +<td> + <p> + √(1/π + </p> + </td> +<td> + <p> + 0.564189 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + pi_minus_three + </p> + </td> +<td> + <p> + π-3 + </p> + </td> +<td> + <p> + 1.41593 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + four_minus_pi + </p> + </td> +<td> + <p> + 4 -π + </p> + </td> +<td> + <p> + 0.858407 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + pow23_four_minus_pi + </p> + </td> +<td> + <p> + 4<sup>2/3</sup> - π + </p> + </td> +<td> + <p> + 0.795316 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + pi_pow_e + </p> + </td> +<td> + <p> + π<sup>e</sup> + </p> + </td> +<td> + <p> + 22.4591 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + pi_sqr + </p> + </td> +<td> + <p> + π<sup>2</sup> + </p> + </td> +<td> + <p> + 9.86960 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + pi_sqr_div_six + </p> + </td> +<td> + <p> + π<sup>2</sup>/6 + </p> + </td> +<td> + <p> + 1.64493 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + pi_cubed + </p> + </td> +<td> + <p> + π<sup>3</sup> + </p> + </td> +<td> + <p> + 31.00627 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + cbrt_pi + </p> + </td> +<td> + <p> + √<sup>3</sup> π + </p> + </td> +<td> + <p> + 1.46459 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + one_div_cbrt_pi + </p> + </td> +<td> + <p> + 1/√<sup>3</sup> π + </p> + </td> +<td> + <p> + 0.682784 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + <span class="bold"><strong>Euler's e and related</strong></span> + </p> + </td> +<td> + </td> +<td> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + e + </p> + </td> +<td> + <p> + e + </p> + </td> +<td> + <p> + 2.71828 + </p> + </td> +<td> + <p> + <a href="http://en.wikipedia.org/wiki/E_(mathematical_constant)" target="_top">Euler's + constant e</a> + </p> + </td> +</tr> +<tr> +<td> + <p> + exp_minus_half + </p> + </td> +<td> + <p> + e <sup>-1/2</sup> + </p> + </td> +<td> + <p> + 0.606530 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + e_pow_pi + </p> + </td> +<td> + <p> + e <sup>π</sup> + </p> + </td> +<td> + <p> + 23.14069 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + root_e + </p> + </td> +<td> + <p> + √ e + </p> + </td> +<td> + <p> + 1.64872 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + log10_e + </p> + </td> +<td> + <p> + log10(e) + </p> + </td> +<td> + <p> + 0.434294 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + one_div_log10_e + </p> + </td> +<td> + <p> + 1/log10(e) + </p> + </td> +<td> + <p> + 2.30258 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + <span class="bold"><strong>Trigonometric</strong></span> + </p> + </td> +<td> + </td> +<td> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + degree + </p> + </td> +<td> + <p> + radians = π / 180 + </p> + </td> +<td> + <p> + 0.017453 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + radian + </p> + </td> +<td> + <p> + degrees = 180 / π + </p> + </td> +<td> + <p> + 57.2957 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + sin_one + </p> + </td> +<td> + <p> + sin(1) + </p> + </td> +<td> + <p> + 0.841470 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + cos_one + </p> + </td> +<td> + <p> + cos(1) + </p> + </td> +<td> + <p> + 0.54030 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + sinh_one + </p> + </td> +<td> + <p> + sinh(1) + </p> + </td> +<td> + <p> + 1.17520 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + cosh_one + </p> + </td> +<td> + <p> + cosh(1) + </p> + </td> +<td> + <p> + 1.54308 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + <span class="bold"><strong>Phi</strong></span> + </p> + </td> +<td> + <p> + Phidias golden ratio + </p> + </td> +<td> + <p> + <a href="http://en.wikipedia.org/wiki/Golden_ratio" target="_top">Phidias + golden ratio</a> + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + phi + </p> + </td> +<td> + <p> + (1 + √5) /2 + </p> + </td> +<td> + <p> + 1.61803 + </p> + </td> +<td> + <p> + finance + </p> + </td> +</tr> +<tr> +<td> + <p> + ln_phi + </p> + </td> +<td> + <p> + ln(φ) + </p> + </td> +<td> + <p> + 0.48121 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + one_div_ln_phi + </p> + </td> +<td> + <p> + 1/ln(φ) + </p> + </td> +<td> + <p> + 2.07808 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + <span class="bold"><strong>Euler's Gamma</strong></span> + </p> + </td> +<td> + </td> +<td> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + euler + </p> + </td> +<td> + <p> + euler + </p> + </td> +<td> + <p> + 0.577215 + </p> + </td> +<td> + <p> + <a href="http://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant" target="_top">Euler-Mascheroni + gamma constant</a> + </p> + </td> +</tr> +<tr> +<td> + <p> + one_div_euler + </p> + </td> +<td> + <p> + 1/euler + </p> + </td> +<td> + <p> + 1.73245 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + euler_sqr + </p> + </td> +<td> + <p> + euler<sup>2</sup> + </p> + </td> +<td> + <p> + 0.333177 + </p> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + <span class="bold"><strong>Misc</strong></span> + </p> + </td> +<td> + </td> +<td> + </td> +<td> + </td> +</tr> +<tr> +<td> + <p> + zeta_two + </p> + </td> +<td> + <p> + ζ(2) + </p> + </td> +<td> + <p> + 1.64493 + </p> + </td> +<td> + <p> + <a href="http://en.wikipedia.org/wiki/Riemann_zeta_function" target="_top">Riemann + zeta function</a> + </p> + </td> +</tr> +<tr> +<td> + <p> + zeta_three + </p> + </td> +<td> + <p> + ζ(3) + </p> + </td> +<td> + <p> + 1.20205 + </p> + </td> +<td> + <p> + <a href="http://en.wikipedia.org/wiki/Riemann_zeta_function" target="_top">Riemann + zeta function</a> + </p> + </td> +</tr> +<tr> +<td> + <p> + catalan + </p> + </td> +<td> + <p> + <span class="emphasis"><em>K</em></span> + </p> + </td> +<td> + <p> + 0.915965 + </p> + </td> +<td> + <p> + <a href="http://mathworld.wolfram.com/CatalansConstant.html" target="_top">Catalan + (or Glaisher) combinatorial constant</a> + </p> + </td> +</tr> +<tr> +<td> + <p> + glaisher + </p> + </td> +<td> + <p> + <span class="emphasis"><em>A</em></span> + </p> + </td> +<td> + <p> + 1.28242 + </p> + </td> +<td> + <p> + <a href="https://oeis.org/A074962/constant" target="_top">Decimal expansion + of Glaisher-Kinkelin constant</a> + </p> + </td> +</tr> +<tr> +<td> + <p> + khinchin + </p> + </td> +<td> + <p> + <span class="emphasis"><em>k</em></span> + </p> + </td> +<td> + <p> + 2.685452 + </p> + </td> +<td> + <p> + <a href="https://oeis.org/A002210/constant" target="_top">Decimal expansion + of Khinchin constant</a> + </p> + </td> +</tr> +<tr> +<td> + <p> + extreme_value_skewness + </p> + </td> +<td> + <p> + 12√6 ζ(3)/ π<sup>3</sup> + </p> + </td> +<td> + <p> + 1.139547 + </p> + </td> +<td> + <p> + Extreme value distribution + </p> + </td> +</tr> +<tr> +<td> + <p> + rayleigh_skewness + </p> + </td> +<td> + <p> + 2√π(π-3)/(4 - π)<sup>3/2</sup> + </p> + </td> +<td> + <p> + 0.631110 + </p> + </td> +<td> + <p> + Rayleigh distribution skewness + </p> + </td> +</tr> +<tr> +<td> + <p> + rayleigh_kurtosis_excess + </p> + </td> +<td> + <p> + -(6π<sup>2</sup>-24π+16)/(4-π)<sup>2</sup> + </p> + </td> +<td> + <p> + 0.245089 + </p> + </td> +<td> + <p> + <a href="http://en.wikipedia.org/wiki/Rayleigh_distribution" target="_top">Rayleigh + distribution kurtosis excess</a> + </p> + </td> +</tr> +<tr> +<td> + <p> + rayleigh_kurtosis + </p> + </td> +<td> + <p> + 3+(6π<sup>2</sup>-24π+16)/(4-π)<sup>2</sup> + </p> + </td> +<td> + <p> + 3.245089 + </p> + </td> +<td> + <p> + Rayleigh distribution kurtosis + </p> + </td> +</tr> +</tbody> +</table></div> +</div> +<br class="table-break"><div class="note"><table border="0" summary="Note"> +<tr> +<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td> +<th align="left">Note</th> +</tr> +<tr><td align="left" valign="top"><p> + Integer values are <span class="bold"><strong>not included</strong></span> in this + list of math constants, however interesting, because they can be so easily + and exactly constructed, even for UDT, for example: <code class="computeroutput"><span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">cpp_float</span><span class="special">>(</span><span class="number">42</span><span class="special">)</span></code>. + </p></td></tr> +</table></div> +<div class="tip"><table border="0" summary="Tip"> +<tr> +<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../../doc/src/images/tip.png"></td> +<th align="left">Tip</th> +</tr> +<tr><td align="left" valign="top"><p> + If you know the approximate value of the constant, you can search for the + value to find Boost.Math chosen name in this table. + </p></td></tr> +</table></div> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><div class="copyright-footer">Copyright © 2006-2010 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno + Lalande, Johan Råde, Gautam Sewani, Thijs van den Berg and Benjamin Sobotta<p> + Distributed under the Boost Software License, Version 1.0. (See accompanying + 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>) + </p> +</div></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="tutorial/user_def.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="new_const.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +</body> +</html> diff --git a/libs/math/doc/sf_and_dist/html/math_toolkit/constants/intro.html b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/intro.html new file mode 100644 index 0000000000..e0cfc65866 --- /dev/null +++ b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/intro.html @@ -0,0 +1,118 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> +<title>Introduction</title> +<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.76.1"> +<link rel="home" href="../../index.html" title="Math Toolkit"> +<link rel="up" href="../constants.html" title="Mathematical Constants"> +<link rel="prev" href="../constants.html" title="Mathematical Constants"> +<link rel="next" href="tutorial.html" title="Tutorial"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"><tr> +<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> +<td align="center"><a href="../../../../../../../index.html">Home</a></td> +<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> +<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> +<td align="center"><a href="../../../../../../../more/index.htm">More</a></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<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> +</div> +<div class="section math_toolkit_constants_intro"> +<div class="titlepage"><div><div><h3 class="title"> +<a name="math_toolkit.constants.intro"></a><a class="link" href="intro.html" title="Introduction">Introduction</a> +</h3></div></div></div> +<p> + Boost.Math provides a collection of mathematical constants. + </p> +<h5> +<a name="math_toolkit.constants.intro.h0"></a> + <span><a name="math_toolkit.constants.intro.why_use_boost_math_mathematical_constants_"></a></span><a class="link" href="intro.html#math_toolkit.constants.intro.why_use_boost_math_mathematical_constants_">Why + use Boost.Math mathematical constants?</a> + </h5> +<div class="itemizedlist"><ul class="itemizedlist" type="disc"> +<li class="listitem"> + 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 +<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> + (If that's all you want, jump direct to <a class="link" href="tutorial/non_templ.html" title="Use in non-template code">use + in non-template code</a>!) + </li> +<li class="listitem"> + Effortless - avoiding a search of reference sources. + </li> +<li class="listitem"> + Usable with both builtin floating point types, and user-defined, possibly + extended precision, types such as NTL, MPFR/GMP, mp_float: in the latter + case the constants are computed to the necessary precision and then cached. + </li> +<li class="listitem"> + Accurate - ensuring that the values are as accurate as possible for the + chosen floating-point type + <div class="itemizedlist"><ul class="itemizedlist" type="circle"> +<li class="listitem"> + No loss of accuracy from repeated rounding of intermediate computations. + </li> +<li class="listitem"> + Result is computed with higher precision and only rounded once. + </li> +<li class="listitem"> + Less risk of inaccurate result from functions pow, trig and log + at <a href="http://en.wikipedia.org/wiki/Corner_case" target="_top">corner + cases</a>. + </li> +<li class="listitem"> + Less risk of <a href="http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html" target="_top">cancellation + error</a>. + </li> +</ul></div> + </li> +<li class="listitem"> + Faster - can avoid (re-)calculation at runtime. This can be significant + if: + <div class="itemizedlist"><ul class="itemizedlist" type="circle"> +<li class="listitem"> + Functions pow, trig or log are used. + </li> +<li class="listitem"> + Inside an inner loop. + </li> +<li class="listitem"> + Using a high-precision UDT. + </li> +<li class="listitem"> + Compiler optimizations possible with built-in types, especially + <code class="computeroutput"><span class="keyword">double</span></code>, are not available. + </li> +</ul></div> + </li> +<li class="listitem"> + Portable - as possible between different systems using different floating-point + precisions: see <a class="link" href="tutorial/templ.html" title="Use in template code">use + in template code</a>. + </li> +<li class="listitem"> + Tested - by comparison with other published sources, or separately computed + at long double precision. + </li> +</ul></div> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><div class="copyright-footer">Copyright © 2006-2010 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno + Lalande, Johan Råde, Gautam Sewani, Thijs van den Berg and Benjamin Sobotta<p> + Distributed under the Boost Software License, Version 1.0. (See accompanying + 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>) + </p> +</div></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<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> +</div> +</body> +</html> diff --git a/libs/math/doc/sf_and_dist/html/math_toolkit/constants/new_const.html b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/new_const.html new file mode 100644 index 0000000000..75e90fa9e0 --- /dev/null +++ b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/new_const.html @@ -0,0 +1,267 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> +<title>Defining New Constants</title> +<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.76.1"> +<link rel="home" href="../../index.html" title="Math Toolkit"> +<link rel="up" href="../constants.html" title="Mathematical Constants"> +<link rel="prev" href="constants.html" title="The Mathematical Constants"> +<link rel="next" href="FAQ.html" title="FAQs"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"><tr> +<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> +<td align="center"><a href="../../../../../../../index.html">Home</a></td> +<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> +<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> +<td align="center"><a href="../../../../../../../more/index.htm">More</a></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<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="FAQ.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +<div class="section math_toolkit_constants_new_const"> +<div class="titlepage"><div><div><h3 class="title"> +<a name="math_toolkit.constants.new_const"></a><a class="link" href="new_const.html" title="Defining New Constants">Defining New Constants</a> +</h3></div></div></div> +<p> + The library provides some helper code to assist in defining new constants; + the process for defining a constant called <code class="computeroutput"><span class="identifier">my_constant</span></code> + goes like this: + </p> +<p> + 1. <span class="bold"><strong>Define a function that calculates the value of the + constant</strong></span>. This should be a template function, and be placed in + <code class="computeroutput"><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">calculate_constants</span><span class="special">.</span><span class="identifier">hpp</span></code> if + the constant is to be added to this library, or else defined at the top of + your source file if not. + </p> +<p> + The function should look like this: + </p> +<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">constants</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">detail</span><span class="special">{</span> + +<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Real</span><span class="special">></span> +<span class="keyword">template</span> <span class="special"><</span><span class="keyword">int</span> <span class="identifier">N</span><span class="special">></span> +<span class="identifier">Real</span> <span class="identifier">constant_my_constant</span><span class="special"><</span><span class="identifier">Real</span><span class="special">>::</span><span class="identifier">compute</span><span class="special">(</span><span class="identifier">BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC</span><span class="special">(</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">N</span><span class="special">>))</span> +<span class="special">{</span> + <span class="keyword">int</span> <span class="identifier">required_precision</span> <span class="special">=</span> <span class="identifier">N</span> <span class="special">?</span> <span class="identifier">N</span> <span class="special">:</span> <span class="identifier">tools</span><span class="special">::</span><span class="identifier">digits</span><span class="special"><</span><span class="identifier">Real</span><span class="special">>();</span> + <span class="identifier">Real</span> <span class="identifier">result</span> <span class="special">=</span> <span class="comment">/* value computed to required_precision bits */</span> <span class="special">;</span> + <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span> +<span class="special">}</span> + +<span class="special">}}}}</span> <span class="comment">// namespaces</span> +</pre> +<p> + Then define a placeholder for the constant itself: + </p> +<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">constants</span><span class="special">{</span> + +<span class="identifier">BOOST_DEFINE_MATH_CONSTANT</span><span class="special">(</span><span class="identifier">my_constant</span><span class="special">,</span> <span class="number">0.0</span><span class="special">,</span> <span class="string">"0"</span><span class="special">);</span> + +<span class="special">}}}</span> +</pre> +<p> + For example, to calculate π/2, add to <code class="computeroutput"><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">calculate_constants</span><span class="special">.</span><span class="identifier">hpp</span></code> + </p> +<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> +<span class="keyword">template</span><span class="special"><</span><span class="keyword">int</span> <span class="identifier">N</span><span class="special">></span> +<span class="keyword">inline</span> <span class="identifier">T</span> <span class="identifier">constant_half_pi</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">compute</span><span class="special">(</span><span class="identifier">BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC</span><span class="special">(</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">N</span><span class="special">>))</span> +<span class="special">{</span> + <span class="identifier">BOOST_MATH_STD_USING</span> + <span class="keyword">return</span> <span class="identifier">pi</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">policies</span><span class="special">::</span><span class="identifier">policy</span><span class="special"><</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">digits2</span><span class="special"><</span><span class="identifier">N</span><span class="special">></span> <span class="special">></span> <span class="special">>()</span> <span class="special">/</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="number">2</span><span class="special">);</span> +<span class="special">}</span> +</pre> +<p> + Then to <code class="computeroutput"><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">constants</span><span class="special">.</span><span class="identifier">hpp</span></code> add: + </p> +<pre class="programlisting"><span class="identifier">BOOST_DEFINE_MATH_CONSTANT</span><span class="special">(</span><span class="identifier">half_pi</span><span class="special">,</span> <span class="number">0.0</span><span class="special">,</span> <span class="string">"0"</span><span class="special">);</span> <span class="comment">// Actual values are temporary, we'll replace them later.</span> +</pre> +<div class="note"><table border="0" summary="Note"> +<tr> +<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td> +<th align="left">Note</th> +</tr> +<tr><td align="left" valign="top"><p> + Previously defined constants like pi and e can be used, but by <span class="bold"><strong>not simply calling</strong></span> <code class="computeroutput"><span class="identifier">pi</span><span class="special"><</span><span class="identifier">T</span><span class="special">>()</span></code>; specifying the precision via the + policy <code class="computeroutput"><span class="identifier">pi</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">policies</span><span class="special">::</span><span class="identifier">policy</span><span class="special"><</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">digits2</span><span class="special"><</span><span class="identifier">N</span><span class="special">></span> <span class="special">></span> <span class="special">>()</span></code> is essential to ensure full accuracy. + </p></td></tr> +</table></div> +<div class="warning"><table border="0" summary="Warning"> +<tr> +<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td> +<th align="left">Warning</th> +</tr> +<tr><td align="left" valign="top"> +<p> + Newly defined constants can only be used once they are included in <code class="computeroutput"><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">constants</span><span class="special">.</span><span class="identifier">hpp</span></code>. So if you add <code class="computeroutput"><span class="keyword">template</span> + <span class="special"><</span><span class="keyword">class</span> + <span class="identifier">T</span><span class="special">,</span> + <span class="keyword">class</span> <span class="identifier">N</span><span class="special">></span> <span class="identifier">T</span> <span class="identifier">constant_my_constant</span><span class="special">{...}</span></code>, + then you cannot define <code class="computeroutput"><span class="identifier">constant_my_constant</span></code> + until you add the temporary <code class="computeroutput"><span class="identifier">BOOST_DEFINE_MATH_CONSTANT</span><span class="special">(</span><span class="identifier">my_constant</span><span class="special">,</span> <span class="number">0.0</span><span class="special">,</span> + <span class="string">"0"</span><span class="special">)</span></code>. + Failing to do this will result in surprising compile errors: +</p> +<pre class="programlisting"><span class="identifier">error</span> <span class="identifier">C2143</span><span class="special">:</span> <span class="identifier">syntax</span> <span class="identifier">error</span> <span class="special">:</span> <span class="identifier">missing</span> <span class="char">';'</span> <span class="identifier">before</span> <span class="char">'<'</span> +<span class="identifier">error</span> <span class="identifier">C2433</span><span class="special">:</span> <span class="char">'constant_root_two_div_pi'</span> <span class="special">:</span> <span class="char">'inline'</span> <span class="keyword">not</span> <span class="identifier">permitted</span> <span class="identifier">on</span> <span class="identifier">data</span> <span class="identifier">declarations</span> +<span class="identifier">error</span> <span class="identifier">C2888</span><span class="special">:</span> <span class="char">'T constant_root_two_div_pi'</span> <span class="special">:</span> <span class="identifier">symbol</span> <span class="identifier">cannot</span> <span class="identifier">be</span> <span class="identifier">defined</span> <span class="identifier">within</span> <span class="keyword">namespace</span> <span class="char">'detail'</span> +<span class="identifier">error</span> <span class="identifier">C2988</span><span class="special">:</span> <span class="identifier">unrecognizable</span> <span class="keyword">template</span> <span class="identifier">declaration</span><span class="special">/</span><span class="identifier">definition</span> +</pre> +<p> + </p> +</td></tr> +</table></div> +<p> + 2. <span class="bold"><strong>You will need an arbitrary precision type to use + to calculate the value</strong></span>. This library currently supports either + <code class="computeroutput"><span class="identifier">cpp_float</span></code>, <code class="computeroutput"><span class="identifier">NTL</span><span class="special">::</span><span class="identifier">RR</span></code> + or <code class="computeroutput"><span class="identifier">mpfr_class</span></code> used via the + bindings in <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">bindings</span></code>. + The default is to use <code class="computeroutput"><span class="identifier">NTL</span><span class="special">::</span><span class="identifier">RR</span></code> unless + you define an alternate macro, for example, <code class="computeroutput"><span class="identifier">USE_MPFR</span></code> + or <code class="computeroutput"><span class="identifier">USE_CPP_FLOAT</span></code> at the start + of your program. + </p> +<p> + 3. It is necessary to link to the Boost.Regex library, and probably to your + chosen arbitrary precision type library. + </p> +<p> + 4. The complete program to generate the constant <code class="computeroutput"><span class="identifier">half_pi</span></code> + using function <code class="computeroutput"><span class="identifier">calculate_half_pi</span></code> + is then: + </p> +<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">USE_CPP_FLOAT</span> <span class="comment">// If required.</span> +<span class="preprocessor">#include</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">generate</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> + +<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> +<span class="special">{</span> + <span class="identifier">BOOST_CONSTANTS_GENERATE</span><span class="special">(</span><span class="identifier">half_pi</span><span class="special">);</span> +<span class="special">}</span> +</pre> +<p> + The output from the program is a snippet of C++ code (actually a macro call) + that can be cut and pasted into <code class="computeroutput"><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">constants</span><span class="special">.</span><span class="identifier">hpp</span></code> or else into your own code, for example: + </p> +<pre class="programlisting">BOOST_DEFINE_MATH_CONSTANT(half_pi, 1.570796326794896619231321691639751442e+00, "1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404326e+00"); +</pre> +<p> + This macro BOOST_DEFINE_MATH_CONSTANT inserts a C++ struct code snippet that + declares the <code class="computeroutput"><span class="keyword">float</span></code>, <code class="computeroutput"><span class="keyword">double</span></code> and <code class="computeroutput"><span class="keyword">long</span> + <span class="keyword">double</span></code> versions of the constant, plus + a decimal digit string representation correct to 100 decimal digits, and + all the meta-programming machinery needed to select between them. + </p> +<p> + The result of an expanded macro for Pi is shown below. + </p> +<p> +</p> +<pre class="programlisting"><span class="comment">// Preprocessed pi constant, annotated.</span> + +<span class="keyword">namespace</span> <span class="identifier">boost</span> +<span class="special">{</span> + <span class="keyword">namespace</span> <span class="identifier">math</span> + <span class="special">{</span> + <span class="keyword">namespace</span> <span class="identifier">constants</span> + <span class="special">{</span> + <span class="keyword">namespace</span> <span class="identifier">detail</span> + <span class="special">{</span> + <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <span class="keyword">struct</span> <span class="identifier">constant_pi</span> + <span class="special">{</span> + <span class="keyword">private</span><span class="special">:</span> + <span class="comment">// Default implementations from string of decimal digits:</span> + <span class="keyword">static</span> <span class="keyword">inline</span> <span class="identifier">T</span> <span class="identifier">get_from_string</span><span class="special">()</span> + <span class="special">{</span> + <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">T</span> <span class="identifier">result</span> + <span class="special">=</span> <span class="identifier">detail</span><span class="special">::</span><span class="identifier">convert_from_string</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="string">"3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651e+00"</span><span class="special">,</span> + <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_convertible</span><span class="special"><</span><span class="keyword">const</span> <span class="keyword">char</span><span class="special">*,</span> <span class="identifier">T</span><span class="special">>());</span> + <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span> + <span class="special">}</span> + <span class="keyword">template</span> <span class="special"><</span><span class="keyword">int</span> <span class="identifier">N</span><span class="special">></span> <span class="keyword">static</span> <span class="identifier">T</span> <span class="identifier">compute</span><span class="special">();</span> + + <span class="keyword">public</span><span class="special">:</span> + <span class="comment">// Default implementations from string of decimal digits:</span> + <span class="keyword">static</span> <span class="keyword">inline</span> <span class="identifier">T</span> <span class="identifier">get</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">construct_from_string</span><span class="special">>&)</span> + <span class="special">{</span> + <span class="identifier">constant_initializer</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span> <span class="special">&</span> <span class="identifier">constant_pi</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">get_from_string</span> <span class="special">>::</span><span class="identifier">do_nothing</span><span class="special">();</span> + <span class="keyword">return</span> <span class="identifier">get_from_string</span><span class="special">();</span> + <span class="special">}</span> + <span class="comment">// Float, double and long double versions:</span> + <span class="keyword">static</span> <span class="keyword">inline</span> <span class="identifier">T</span> <span class="identifier">get</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">construct_from_float</span><span class="special">>)</span> + <span class="special">{</span> + <span class="keyword">return</span> <span class="number">3.141592653589793238462643383279502884e+00F</span><span class="special">;</span> + <span class="special">}</span> + <span class="keyword">static</span> <span class="keyword">inline</span> <span class="identifier">T</span> <span class="identifier">get</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">construct_from_double</span><span class="special">>&)</span> + <span class="special">{</span> + <span class="keyword">return</span> <span class="number">3.141592653589793238462643383279502884e+00</span><span class="special">;</span> + <span class="special">}</span> + <span class="keyword">static</span> <span class="keyword">inline</span> <span class="identifier">T</span> <span class="identifier">get</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">construct_from_long_double</span><span class="special">>&)</span> + <span class="special">{</span> + <span class="keyword">return</span> <span class="number">3.141592653589793238462643383279502884e+00L</span><span class="special">;</span> + <span class="special">}</span> + <span class="comment">// For very high precision that is nonetheless can be calculated at compile time:</span> + <span class="keyword">template</span> <span class="special"><</span><span class="keyword">int</span> <span class="identifier">N</span><span class="special">></span> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="identifier">T</span> <span class="identifier">get</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">N</span><span class="special">>&</span> <span class="identifier">n</span><span class="special">)</span> + <span class="special">{</span> + <span class="identifier">constant_initializer2</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">N</span><span class="special">,</span> <span class="special">&</span> <span class="identifier">constant_pi</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="keyword">template</span> <span class="identifier">compute</span><span class="special"><</span><span class="identifier">N</span><span class="special">></span> <span class="special">>::</span><span class="identifier">do_nothing</span><span class="special">();</span> + <span class="keyword">return</span> <span class="identifier">compute</span><span class="special"><</span><span class="identifier">N</span><span class="special">>();</span> + <span class="special">}</span> + <span class="comment">//For true arbitrary precision, which may well vary at runtime.</span> + <span class="keyword">static</span> <span class="keyword">inline</span> <span class="identifier">T</span> <span class="identifier">get</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="number">0</span><span class="special">>&)</span> + <span class="special">{</span> + <span class="keyword">return</span> <span class="identifier">tools</span><span class="special">::</span><span class="identifier">digits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>()</span> <span class="special">></span> <span class="identifier">max_string_digits</span> <span class="special">?</span> <span class="identifier">compute</span><span class="special"><</span><span class="number">0</span><span class="special">>()</span> <span class="special">:</span> <span class="identifier">get</span><span class="special">(</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">construct_from_string</span><span class="special">>());</span> + <span class="special">}</span> + <span class="special">};</span> <span class="comment">// template <class T> struct constant_pi</span> + <span class="special">}</span> <span class="comment">// namespace detail</span> + + <span class="comment">// The actual forwarding function (including policy to control precision).</span> + <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policy</span><span class="special">></span> <span class="keyword">inline</span> <span class="identifier">T</span> <span class="identifier">pi</span><span class="special">(</span> <span class="special">)</span> + <span class="special">{</span> + <span class="keyword">return</span> <span class="identifier">detail</span><span class="special">::</span> <span class="identifier">constant_pi</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">get</span><span class="special">(</span><span class="keyword">typename</span> <span class="identifier">construction_traits</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Policy</span><span class="special">>::</span><span class="identifier">type</span><span class="special">());</span> + <span class="special">}</span> + <span class="comment">// The actual forwarding function (using default policy to control precision).</span> + <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> <span class="keyword">inline</span> <span class="identifier">T</span> <span class="identifier">pi</span><span class="special">()</span> + <span class="special">{</span> + <span class="keyword">return</span> <span class="identifier">pi</span><span class="special"><</span><span class="identifier">T</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">policies</span><span class="special">::</span><span class="identifier">policy</span><span class="special"><></span> <span class="special">>()</span> + <span class="special">}</span> + <span class="special">}</span> <span class="comment">// namespace constants</span> + + <span class="comment">// Namespace specific versions, for the three built-in floats:</span> + <span class="keyword">namespace</span> <span class="identifier">float_constants</span> + <span class="special">{</span> + <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">float</span> <span class="identifier">pi</span> <span class="special">=</span> <span class="number">3.141592653589793238462643383279502884e+00F</span><span class="special">;</span> + <span class="special">}</span> + <span class="keyword">namespace</span> <span class="identifier">double_constants</span> + <span class="special">{</span> + <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">double</span> <span class="identifier">pi</span> <span class="special">=</span> <span class="number">3.141592653589793238462643383279502884e+00</span><span class="special">;</span> + <span class="special">}</span> + <span class="keyword">namespace</span> <span class="identifier">long_double_constants</span> + <span class="special">{</span> + <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">long</span> <span class="keyword">double</span> <span class="identifier">pi</span> <span class="special">=</span> <span class="number">3.141592653589793238462643383279502884e+00L</span><span class="special">;</span> + <span class="special">}</span> + <span class="keyword">namespace</span> <span class="identifier">constants</span><span class="special">{;</span> + <span class="special">}</span> <span class="comment">// namespace constants</span> + <span class="special">}</span> <span class="comment">// namespace math</span> +<span class="special">}</span> <span class="comment">// namespace boost</span> +</pre> +<p> + </p> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><div class="copyright-footer">Copyright © 2006-2010 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno + Lalande, Johan Råde, Gautam Sewani, Thijs van den Berg and Benjamin Sobotta<p> + Distributed under the Boost Software License, Version 1.0. (See accompanying + 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>) + </p> +</div></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<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="FAQ.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +</body> +</html> diff --git a/libs/math/doc/sf_and_dist/html/math_toolkit/constants/tutorial.html b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/tutorial.html new file mode 100644 index 0000000000..cfecd87834 --- /dev/null +++ b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/tutorial.html @@ -0,0 +1,52 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> +<title>Tutorial</title> +<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.76.1"> +<link rel="home" href="../../index.html" title="Math Toolkit"> +<link rel="up" href="../constants.html" title="Mathematical Constants"> +<link rel="prev" href="intro.html" title="Introduction"> +<link rel="next" href="tutorial/non_templ.html" title="Use in non-template code"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"><tr> +<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> +<td align="center"><a href="../../../../../../../index.html">Home</a></td> +<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> +<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> +<td align="center"><a href="../../../../../../../more/index.htm">More</a></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="intro.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/non_templ.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +<div class="section math_toolkit_constants_tutorial"> +<div class="titlepage"><div><div><h3 class="title"> +<a name="math_toolkit.constants.tutorial"></a><a class="link" href="tutorial.html" title="Tutorial">Tutorial</a> +</h3></div></div></div> +<div class="toc"><dl> +<dt><span class="section"><a href="tutorial/non_templ.html">Use in non-template + code</a></span></dt> +<dt><span class="section"><a href="tutorial/templ.html">Use in template + code</a></span></dt> +<dt><span class="section"><a href="tutorial/user_def.html">Use With + User Defined Types</a></span></dt> +</dl></div> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><div class="copyright-footer">Copyright © 2006-2010 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno + Lalande, Johan Råde, Gautam Sewani, Thijs van den Berg and Benjamin Sobotta<p> + Distributed under the Boost Software License, Version 1.0. (See accompanying + 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>) + </p> +</div></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="intro.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/non_templ.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +</body> +</html> diff --git a/libs/math/doc/sf_and_dist/html/math_toolkit/constants/tutorial/non_templ.html b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/tutorial/non_templ.html new file mode 100644 index 0000000000..a9c7339bbe --- /dev/null +++ b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/tutorial/non_templ.html @@ -0,0 +1,82 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> +<title>Use in non-template code</title> +<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.76.1"> +<link rel="home" href="../../../index.html" title="Math Toolkit"> +<link rel="up" href="../tutorial.html" title="Tutorial"> +<link rel="prev" href="../tutorial.html" title="Tutorial"> +<link rel="next" href="templ.html" title="Use in template code"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"><tr> +<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> +<td align="center"><a href="../../../../../../../../index.html">Home</a></td> +<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> +<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> +<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="../tutorial.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorial.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="templ.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +<div class="section math_toolkit_constants_tutorial_non_templ"> +<div class="titlepage"><div><div><h4 class="title"> +<a name="math_toolkit.constants.tutorial.non_templ"></a><a class="link" href="non_templ.html" title="Use in non-template code">Use in non-template + code</a> +</h4></div></div></div> +<p> + When using the math constants at your chosen fixed precision in non-template + code, you can simply add a <code class="computeroutput"><span class="keyword">using</span></code> + declaration, for example, <code class="computeroutput"><span class="keyword">using</span> + <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">double_constants</span></code>, to make the constants + of the correct precision for your code visible in the current scope, and + then use each constant <span class="emphasis"><em>as a simple variable</em></span>: + </p> +<pre class="programlisting"><span class="preprocessor">#include</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">hpp</span><span class="special">></span> + +<span class="keyword">double</span> <span class="identifier">area</span><span class="special">(</span><span class="keyword">double</span> <span class="identifier">r</span><span class="special">)</span> +<span class="special">{</span> + <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">double_constants</span><span class="special">;</span> + <span class="keyword">return</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> +<span class="special">}</span> +</pre> +<p> + Had our function been written as taking a <code class="computeroutput"><span class="keyword">float</span></code> + rather than a <code class="computeroutput"><span class="keyword">double</span></code>, we could + have written instead: + </p> +<pre class="programlisting"><span class="preprocessor">#include</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">hpp</span><span class="special">></span> + +<span class="keyword">float</span> <span class="identifier">area</span><span class="special">(</span><span class="keyword">float</span> <span class="identifier">r</span><span class="special">)</span> +<span class="special">{</span> + <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">float_constants</span><span class="special">;</span> + <span class="keyword">return</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> +<span class="special">}</span> +</pre> +<p> + Likewise, constants that are suitable for use at <code class="computeroutput"><span class="keyword">long</span> + <span class="keyword">double</span></code> precision are available in + the namespace <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">long_double_constants</span></code>. + </p> +<p> + You can see the full list of available constants at <a class="link" href="../constants.html" title="The Mathematical Constants">math_toolkit.constants.constants</a>. + </p> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><div class="copyright-footer">Copyright © 2006-2010 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno + Lalande, Johan Råde, Gautam Sewani, Thijs van den Berg and Benjamin Sobotta<p> + Distributed under the Boost Software License, Version 1.0. (See accompanying + 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>) + </p> +</div></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="../tutorial.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorial.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="templ.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +</body> +</html> diff --git a/libs/math/doc/sf_and_dist/html/math_toolkit/constants/tutorial/templ.html b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/tutorial/templ.html new file mode 100644 index 0000000000..7df04bb57a --- /dev/null +++ b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/tutorial/templ.html @@ -0,0 +1,164 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> +<title>Use in template code</title> +<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.76.1"> +<link rel="home" href="../../../index.html" title="Math Toolkit"> +<link rel="up" href="../tutorial.html" title="Tutorial"> +<link rel="prev" href="non_templ.html" title="Use in non-template code"> +<link rel="next" href="user_def.html" title="Use With User Defined Types"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"><tr> +<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> +<td align="center"><a href="../../../../../../../../index.html">Home</a></td> +<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> +<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> +<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="non_templ.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorial.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="user_def.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +<div class="section math_toolkit_constants_tutorial_templ"> +<div class="titlepage"><div><div><h4 class="title"> +<a name="math_toolkit.constants.tutorial.templ"></a><a class="link" href="templ.html" title="Use in template code">Use in template + code</a> +</h4></div></div></div> +<p> + When using the constants inside a function template, we need to ensure + that we use a constant of the correct precision for our template parameters. + We can do this by calling the function-template versions, <code class="computeroutput"><span class="identifier">pi</span><span class="special"><</span><span class="identifier">FPType</span><span class="special">>()</span></code>, + of the constants like this: + </p> +<pre class="programlisting"><span class="preprocessor">#include</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">hpp</span><span class="special">></span> + +<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Real</span><span class="special">></span> +<span class="identifier">Real</span> <span class="identifier">area</span><span class="special">(</span><span class="identifier">Real</span> <span class="identifier">r</span><span class="special">)</span> +<span class="special">{</span> + <span class="keyword">using</span> <span class="keyword">namespace</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="keyword">return</span> <span class="identifier">pi</span><span class="special"><</span><span class="identifier">Real</span><span class="special">>()</span> <span class="special">*</span> <span class="identifier">r</span> <span class="special">*</span> <span class="identifier">r</span><span class="special">;</span> +<span class="special">}</span> +</pre> +<p> + Although this syntax is a little less "cute" than the non-template + version, the code is no less efficient (at least for the built-in types + <code class="computeroutput"><span class="keyword">float</span></code>, <code class="computeroutput"><span class="keyword">double</span></code> + and <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code>) + : the function template versions of the constants are simple inline functions + that return a constant of the correct precision for the type used. In addition, + these functions are declared <code class="computeroutput"><span class="identifier">constexp</span></code> + for those compilers that support this, allowing the result to be used in + constant-expressions provided the template argument is a literal type. + </p> +<div class="tip"><table border="0" summary="Tip"> +<tr> +<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../../../doc/src/images/tip.png"></td> +<th align="left">Tip</th> +</tr> +<tr><td align="left" valign="top"><p> + Keep in mind the difference between the variable version, just <code class="computeroutput"><span class="identifier">pi</span></code>, and the template-function version: + the template-function requires both a <<em class="replaceable"><code>floating-point-type</code></em>> + and function call <code class="computeroutput"><span class="special">()</span></code> brackets, + for example: <code class="computeroutput"><span class="identifier">pi</span><span class="special"><</span><span class="keyword">double</span><span class="special">>()</span></code>. + You cannot write <code class="computeroutput"><span class="keyword">double</span> <span class="identifier">p</span> <span class="special">=</span> <span class="identifier">pi</span><span class="special"><>()</span></code>, + nor <code class="computeroutput"><span class="keyword">double</span> <span class="identifier">p</span> + <span class="special">=</span> <span class="identifier">pi</span><span class="special">()</span></code>. + </p></td></tr> +</table></div> +<div class="note"><table border="0" summary="Note"> +<tr> +<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../../doc/src/images/note.png"></td> +<th align="left">Note</th> +</tr> +<tr><td align="left" valign="top"> +<p> + You can always use <span class="bold"><strong>both</strong></span> variable and + template-function versions <span class="bold"><strong>provided calls are fully + qualified</strong></span>, for example: +</p> +<pre class="programlisting"><span class="keyword">double</span> <span class="identifier">my_pi1</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="keyword">double</span><span class="special">>();</span> +<span class="keyword">double</span> <span class="identifier">my_pi2</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">double_constants</span><span class="special">::</span><span class="identifier">pi</span><span class="special">;</span> +</pre> +<p> + </p> +</td></tr> +</table></div> +<div class="warning"><table border="0" summary="Warning"> +<tr> +<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../../doc/src/images/warning.png"></td> +<th align="left">Warning</th> +</tr> +<tr><td align="left" valign="top"> +<p> + It may be tempting to simply define +</p> +<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">double_constants</span><span class="special">;</span> +<span class="keyword">using</span> <span class="keyword">namespace</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> +</pre> +<p> + but if you do define two namespaces, this will, of course, create ambiguity! +</p> +<pre class="programlisting"><span class="keyword">double</span> <span class="identifier">my_pi</span> <span class="special">=</span> <span class="identifier">pi</span><span class="special">();</span> <span class="comment">// error C2872: 'pi' : ambiguous symbol</span> +<span class="keyword">double</span> <span class="identifier">my_pi2</span> <span class="special">=</span> <span class="identifier">pi</span><span class="special">;</span> <span class="comment">// Context does not allow for disambiguation of overloaded function</span> +</pre> +<p> + Although the mistake above is fairly obvious, it is also not too difficult + to do this accidentally, or worse, create it in someone elses code. + </p> +<p> + Therefore is it prudent to avoid this risk by <span class="bold"><strong>localising + the scope of such definitions</strong></span>, as shown above. + </p> +</td></tr> +</table></div> +<div class="tip"><table border="0" summary="Tip"> +<tr> +<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../../../doc/src/images/tip.png"></td> +<th align="left">Tip</th> +</tr> +<tr><td align="left" valign="top"> +<p> + Be very careful with the type provided as parameter. For example, providing + an <span class="bold"><strong>integer</strong></span> instead of a floating-point + type can be disastrous (a C++ feature). + </p> +<p> +</p> +<pre class="programlisting"><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Area = "</span> <span class="special"><<</span> <span class="identifier">area</span><span class="special">(</span><span class="number">2</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">endl</span><span class="special">;</span> <span class="comment">// Area = 12!!!</span></pre> +<p> + </p> +<p> + You should get a compiler warning + </p> +<pre class="programlisting">warning : 'return' : conversion from 'double' to 'int', possible loss of data +</pre> +<p> + Failure to heed this warning can lead to very wrong answers! + </p> +<p> + You can also avoid this by being explicit about the type of <code class="computeroutput"><span class="identifier">Area</span></code>. +</p> +<pre class="programlisting"><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Area = "</span> <span class="special"><<</span> <span class="identifier">area</span><span class="special"><</span><span class="keyword">double</span><span class="special">>(</span><span class="number">2</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">endl</span><span class="special">;</span> <span class="comment">// Area = 12.566371</span></pre> +<p> + </p> +</td></tr> +</table></div> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><div class="copyright-footer">Copyright © 2006-2010 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno + Lalande, Johan Råde, Gautam Sewani, Thijs van den Berg and Benjamin Sobotta<p> + Distributed under the Boost Software License, Version 1.0. (See accompanying + 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>) + </p> +</div></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="non_templ.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorial.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="user_def.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +</body> +</html> diff --git a/libs/math/doc/sf_and_dist/html/math_toolkit/constants/tutorial/user_def.html b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/tutorial/user_def.html new file mode 100644 index 0000000000..b4a3f60a8e --- /dev/null +++ b/libs/math/doc/sf_and_dist/html/math_toolkit/constants/tutorial/user_def.html @@ -0,0 +1,313 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> +<title>Use With User Defined Types</title> +<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> +<meta name="generator" content="DocBook XSL Stylesheets V1.76.1"> +<link rel="home" href="../../../index.html" title="Math Toolkit"> +<link rel="up" href="../tutorial.html" title="Tutorial"> +<link rel="prev" href="templ.html" title="Use in template code"> +<link rel="next" href="../constants.html" title="The Mathematical Constants"> +</head> +<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> +<table cellpadding="2" width="100%"><tr> +<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> +<td align="center"><a href="../../../../../../../../index.html">Home</a></td> +<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> +<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> +<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> +<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="templ.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorial.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="../constants.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +<div class="section math_toolkit_constants_tutorial_user_def"> +<div class="titlepage"><div><div><h4 class="title"> +<a name="math_toolkit.constants.tutorial.user_def"></a><a class="link" href="user_def.html" title="Use With User Defined Types">Use With + User Defined Types</a> +</h4></div></div></div> +<p> + The syntax for using the function-call constants with user-defined types + is the same as it is in the template class, which is to say we use: + </p> +<pre class="programlisting"><span class="preprocessor">#include</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">hpp</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">UserDefinedType</span><span class="special">>();</span> +</pre> +<p> + However, since the precision of the user-defined type may be much greater + than that of the built-in floating pointer types, how the value returned + is created is as follows: + </p> +<div class="itemizedlist"><ul class="itemizedlist" type="disc"> +<li class="listitem"> + If the precision of the type is known at compile time: + <div class="itemizedlist"><ul class="itemizedlist" type="circle"> +<li class="listitem"> + If the precision is less than or equal to that of a <code class="computeroutput"><span class="keyword">float</span></code> and the type is constructable + from a <code class="computeroutput"><span class="keyword">float</span></code> then + our code returns a <code class="computeroutput"><span class="keyword">float</span></code> + literal. If the user-defined type is a literal type then the + function call that returns the constant will be a <code class="computeroutput"><span class="identifier">constexp</span></code>. + </li> +<li class="listitem"> + If the precision is less than or equal to that of a <code class="computeroutput"><span class="keyword">double</span></code> and the type is constructable + from a <code class="computeroutput"><span class="keyword">double</span></code> then + our code returns a <code class="computeroutput"><span class="keyword">double</span></code> + literal. If the user-defined type is a literal type then the + function call that returns the constant will be a <code class="computeroutput"><span class="identifier">constexp</span></code>. + </li> +<li class="listitem"> + If the precision is less than or equal to that of a <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code> + and the type is constructable from a <code class="computeroutput"><span class="keyword">long</span> + <span class="keyword">double</span></code> then our code returns + a <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code> + literal. If the user-defined type is a literal type then the + function call that returns the constant will be a <code class="computeroutput"><span class="identifier">constexp</span></code>. + </li> +<li class="listitem"> + If the precision is less than 100 decimal digits, then the constant + will be constructed (just the once, then cached in a thread-safe + manner) from a string representation of the constant. + </li> +<li class="listitem"> + Otherwise the value is computed (just once, then cached in a + thread-safe manner). + </li> +</ul></div> + </li> +<li class="listitem"> + If the precision is unknown at compile time then: + <div class="itemizedlist"><ul class="itemizedlist" type="circle"> +<li class="listitem"> + If the runtime precision (obtained from a call to <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tools</span><span class="special">::</span><span class="identifier">digits</span><span class="special"><</span><span class="identifier">T</span><span class="special">>()</span></code>) + is less than 100 decimal digits, then the constant is constructed + "on the fly" from the string representation of the + constant. + </li> +<li class="listitem"> + Otherwise the value is constructed "on the fly" by + calculating then value of the constant using the current default + precision of the type. Note that this can make use of the constants + rather expensive. + </li> +</ul></div> + </li> +</ul></div> +<p> + In addition, it is possible to pass a <code class="computeroutput"><span class="identifier">Policy</span></code> + type as a second template argument, and use this to control the precision: + </p> +<pre class="programlisting"><span class="preprocessor">#include</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">constants</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> + +<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">policies</span><span class="special">::</span><span class="identifier">policy</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">policies</span><span class="special">::</span><span class="identifier">digits2</span><span class="special"><</span><span class="number">80</span><span class="special">></span> <span class="special">></span> <span class="identifier">my_policy_type</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">MyType</span><span class="special">,</span> <span class="identifier">my_policy_type</span><span class="special">>();</span> +</pre> +<div class="note"><table border="0" summary="Note"> +<tr> +<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../../doc/src/images/note.png"></td> +<th align="left">Note</th> +</tr> +<tr><td align="left" valign="top"><p> + Boost.Math doesn't know how to control the internal precision of <code class="computeroutput"><span class="identifier">MyType</span></code>, the policy just controls how + the selection process above is carried out, and the calculation precision + if the result is computed. + </p></td></tr> +</table></div> +<p> + It is also possible to control which method is used to construct the constant + by specialising the traits class <code class="computeroutput"><span class="identifier">construction_traits</span></code>: + </p> +<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">constant</span><span class="special">{</span> + +<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policy</span><span class="special">></span> +<span class="keyword">struct</span> <span class="identifier">construction_traits</span> +<span class="special">{</span> + <span class="keyword">typedef</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">N</span><span class="special">></span> <span class="identifier">type</span><span class="special">;</span> +<span class="special">};</span> + +<span class="special">}}}</span> <span class="comment">// namespaces</span> +</pre> +<p> + Where <span class="emphasis"><em>N</em></span> takes one of the following values: + </p> +<div class="informaltable"><table class="table"> +<colgroup> +<col> +<col> +</colgroup> +<thead><tr> +<th> + <p> + <span class="emphasis"><em>N</em></span> + </p> + </th> +<th> + <p> + Meaning + </p> + </th> +</tr></thead> +<tbody> +<tr> +<td> + <p> + 0 + </p> + </td> +<td> + <p> + The precision is unavailable at compile time; either construct + from a decimal digit string or calculate on the fly depending + upon the runtime precision. + </p> + </td> +</tr> +<tr> +<td> + <p> + 1 + </p> + </td> +<td> + <p> + Return a float precision constant. + </p> + </td> +</tr> +<tr> +<td> + <p> + 2 + </p> + </td> +<td> + <p> + Return a double precision constant. + </p> + </td> +</tr> +<tr> +<td> + <p> + 3 + </p> + </td> +<td> + <p> + Return a long double precision constant. + </p> + </td> +</tr> +<tr> +<td> + <p> + 4 + </p> + </td> +<td> + <p> + Construct the result from the string representation, and cache + the result. + </p> + </td> +</tr> +<tr> +<td> + <p> + Any other value <span class="emphasis"><em>N</em></span> + </p> + </td> +<td> + <p> + Sets the compile time precision to <span class="emphasis"><em>N</em></span> bits. + </p> + </td> +</tr> +</tbody> +</table></div> +<h6> +<a name="math_toolkit.constants.tutorial.user_def.h0"></a> + <span><a name="math_toolkit.constants.tutorial.user_def.custom_specializing_a_constant"></a></span><a class="link" href="user_def.html#math_toolkit.constants.tutorial.user_def.custom_specializing_a_constant">Custom + Specializing a constant</a> + </h6> +<p> + In addition, for user-defined types that need special handling, it's possible + to [partially-] specialize the internal structure used by each constant. + For example, suppose we're using the C++ wrapper around MPFR <code class="computeroutput"><span class="identifier">mpfr_class</span></code>: this has its own representation + of Pi which we may well wish to use in place of the above mechanism. We + can achieve this by specialising the class template <code class="computeroutput"><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">detail</span><span class="special">::</span><span class="identifier">constant_pi</span></code>: + </p> +<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">constants</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">detail</span><span class="special">{</span> + +<span class="keyword">template</span><span class="special"><></span> +<span class="keyword">struct</span> <span class="identifier">constant_pi</span><span class="special"><</span><span class="identifier">mpfr_class</span><span class="special">></span> +<span class="special">{</span> + <span class="keyword">template</span><span class="special"><</span><span class="keyword">int</span> <span class="identifier">N</span><span class="special">></span> + <span class="keyword">inline</span> <span class="identifier">T</span> <span class="identifier">get</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">N</span><span class="special">>&)</span> + <span class="special">{</span> + <span class="comment">// The template param N is one of the values in the table above,</span> + <span class="comment">// we can either handle all cases in one as is the case here,</span> + <span class="comment">// or overload "get" for the different options.</span> + <span class="identifier">mpfr_class</span> <span class="identifier">result</span><span class="special">;</span> + <span class="identifier">mpfr_const_pi</span><span class="special">(</span><span class="identifier">result</span><span class="special">.</span><span class="identifier">get_mpfr_t</span><span class="special">(),</span> <span class="identifier">GMP_RNDN</span><span class="special">);</span> + <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span> + <span class="special">}</span> +<span class="special">};</span> + +<span class="special">}}}}</span> <span class="comment">// namespaces</span> +</pre> +<h6> +<a name="math_toolkit.constants.tutorial.user_def.h1"></a> + <span><a name="math_toolkit.constants.tutorial.user_def.diagnosing_what_meta_programmed_code_is_doing"></a></span><a class="link" href="user_def.html#math_toolkit.constants.tutorial.user_def.diagnosing_what_meta_programmed_code_is_doing">Diagnosing + what meta-programmed code is doing</a> + </h6> +<p> + Finally, since it can be tricky to diagnose what meta-programmed code is + doing, there is a diagnostic routine that prints information about how + this library will handle a specific type, it can be used like this: + </p> +<pre class="programlisting"><span class="preprocessor">#include</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">info</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> + +<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</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">print_info_on_type</span><span class="special"><</span><span class="identifier">MyType</span><span class="special">>();</span> +<span class="special">}</span> +</pre> +<p> + If you wish, you can also pass an optional std::ostream argument to the + <code class="computeroutput"><span class="identifier">print_info_on_type</span></code> function. + Typical output for a user-defined type looks like this: + </p> +<pre class="programlisting">Information on the Implementation and Handling of +Mathematical Constants for Type class boost::math::concepts::real_concept + +Checking for std::numeric_limits<class boost::math::concepts::real_concept> specialisation: no +boost::math::policies::precision<class boost::math::concepts::real_concept, Policy> +reports that there is no compile type precision available. +boost::math::tools::digits<class boost::math::concepts::real_concept>() +reports that the current runtime precision is +53 binary digits. +No compile time precision is available, the construction method +will be decided at runtime and results will not be cached +- this may lead to poor runtime performance. +Current runtime precision indicates that +the constant will be constructed from a string on each call. +</pre> +</div> +<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> +<td align="left"></td> +<td align="right"><div class="copyright-footer">Copyright © 2006-2010 John Maddock, Paul A. Bristow, Hubert Holin, Xiaogang Zhang, Bruno + Lalande, Johan Råde, Gautam Sewani, Thijs van den Berg and Benjamin Sobotta<p> + Distributed under the Boost Software License, Version 1.0. (See accompanying + 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>) + </p> +</div></td> +</tr></table> +<hr> +<div class="spirit-nav"> +<a accesskey="p" href="templ.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tutorial.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="../constants.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> +</div> +</body> +</html> |