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 an old version of boost. Click here for the latest version's documentation home page.
PrevUpHomeNext

Use in non-template code

When using the math constants at your chosen fixed precision in non-template code, you can simply add a using declaration, for example, using boost::math::double_constants, to make the constants of the correct precision for your code visible in the current scope, and then use each constant as a simple variable:

#include <boost/math/constants.hpp>

double area(double r)
{
   using boost::math::double_constants;
   return pi * r * r;
}

Had our function been written as taking a float rather than a double, we could have written instead:

#include <boost/math/constants.hpp>

float area(float r)
{
   using boost::math::float_constants;
   return pi * r * r;
}

Likewise, constants that are suitable for use at long double precision are available in the namespace boost::math::long_double_constants.

You can see the full list of available constants at math_toolkit.constants.constants.


PrevUpHomeNext