...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
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 |
---|---|
|
Indicates whether |
|
Indicates whether |
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);