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

Internal Promotion Policies

Normally when evaluating a function at say float precision, maximal accuracy is assured by conducting the calculation at double precision internally, and then rounding the result. There are two policies that effect whether internal promotion takes place or not:

Policy

Meaning

boost::math::policies::promote_float<B>

Indicates whether float arguments should be promoted to double precision internally: defaults to boost::math::policies::promote_float<true>

boost::math::policies::promote_double<B>

Indicates whether double arguments should be promoted to long double precision internally: defaults to boost::math::policies::promote_double<true>

Examples

Suppose we want tgamma to be evaluated without internal promotion to long double, then we could use:

#include <boost/math/special_functions/gamma.hpp>

using namespace boost::math::policies;
using namespace boost::math;

// Define a policy:
typedef policy<
      promote_double<false> 
      > my_policy;
      
// Call the function:
double t1 = tgamma(some_value, my_policy());

// Alternatively we could use make_policy and define everything at the call site:
double t2 = tgamma(some_value, make_policy(promote_double<false>()));

Alternatively, suppose we want a distribution to perform calculations without promoting float to double, then we could use:

#include <boost/math/distributions/normal.hpp>

using namespace boost::math::policies;
using namespace boost::math;

// Define a policy:
typedef policy<
      promote_float<false>
      > my_policy;

// Define the distribution:
typedef normal_distribution<float, my_policy> my_norm;

// Get a quantile:
float q = quantile(my_norm(), 0.05f);


PrevUpHomeNext