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 to view this page for the latest version.
PrevUpHomeNext

Floating-Point Constant Macros

All macros of the type BOOST_FLOAT16_C, BOOST_FLOAT32_C, BOOST_FLOAT64_C, BOOST_FLOAT80_C, BOOST_FLOAT128_C, and BOOST_FLOATMAX_C are always defined after inclusion of <boost/cstdfloat.hpp>.

These allow floating-point constants of at least the specified width to be declared:

// Declare Archimedes' constant using float32_t with approximately 7 decimal digits of precision.
static const boost::float32_t pi = BOOST_FLOAT32_C(3.1415926536);

// Declare the Euler-gamma constant with approximately 15 decimal digits of precision.
static const boost::float64_t euler =
   BOOST_FLOAT64_C(0.57721566490153286060651209008240243104216);

// Declare the Golden Ratio constant with the maximum decimal digits of precision that the platform supports.
static const boost::floatmax_t golden_ratio =
   BOOST_FLOATMAX_C(1.61803398874989484820458683436563811772);
[Tip] Tip

Boost.Math provides many constants 'built-in', so always use Boost.Math constants if available, for example:

// Display the constant pi to the maximum available precision.
  boost::floatmax_t pi_max = boost::math::constants::pi<boost::floatmax_t>();
  std::cout.precision(std::numeric_limits<boost::floatmax_t>::digits10);
  std::cout << "Most precise pi = "  << pi_max << std::endl;
// If floatmax_t is float_128_t, then
// Most precise pi = 3.141592653589793238462643383279503

from cstdfloat_example.cpp.

See the complete list of constants.


PrevUpHomeNext