Home Libraries People FAQ More

#### 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);

```

 Copyright © 2006 -2007 John Maddock, Paul A. Bristow, Hubert Holin and Xiaogang Zhang Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)