Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

Numeric Constants

Synopsis

#include <boost/math/constants/constants.hpp>

namespace boost{ namespace math{ namespace constants{

template <class T> T pi();
template <class T> T root_pi();
template <class T> T root_half_pi();
template <class T> T root_two_pi();
template <class T> T root_ln_four();
template <class T> T e();
template <class T> T half();
template <class T> T euler();
template <class T> T root_two();
template <class T> T ln_two();
template <class T> T ln_ln_two();
template <class T> T third();
template <class T> T twothirds();
template <class T> T pi_minus_three();
template <class T> T four_minus_pi();

}}} // namespaces
Description

The header boost/math/constants/constants.hpp contains some numeric constants that we have found useful in the development of this library. New constants are added on an ad-hock basis based on need.

Usage is like this:

template <class T>
T circumference(T r)
{
   return 2 * boost::math::constants::pi<T>() * r;
}

All the constants are accurate to at least the 34 decimal digits required for 128-bit long doubles, and most are accurate to 100 digits or more when used with a suitable arbitrary precision type.

The following table summarises the constants we have at present:

Constant

Meaning

Value

pi

π

3.1415926535897932384...

root_pi

√π

1.772453850905516027...

root_half_pi

√(π/2)

1.253314137315500251...

root_two_pi

√(2*π)

2.506628274631000502...

root_ln_four

√(ln(4))

1.17741002251547469...

e

e

2.71828182845904523536...

half

0.5

0.5

euler

Euler's constant

0.577215664901532860606

root_two

√2

1.4142135623730950488...

ln_two

ln(2)

0.6931471805599453094...

ln_ln_two

ln(ln(2))

-0.3665129205816643...

third

1/3

0.333333333333333333...

twothirds

2/3

0.666666666666666666...

pi_minus_three

π-3

0.14159265358979323846...

four_minus_pi

4-π

0.85840734641020676153735...


PrevUpHomeNext