| Home | Libraries | People | FAQ | More

### So Just What is a Policy Anyway?

A policy is a compile-time mechanism for customising the behaviour of a special function, or a statistical distribution. With Policies you can control:

- What action to take when an error occurs.
- What happens when you call a function that is mathematically undefined (for example, if you ask for the mean of a Cauchy distribution).
- What happens when you ask for a quantile of a discrete distribution.
- Whether the library is allowed to internally promote `float` to `double` and `double` to `long double` in order to improve precision.
- What precision to use when calculating the result.

Some of these policies could arguably be run-time variables, but then we couldn't use compile-time dispatch internally to select the best evaluation method for the given policies.

For this reason a Policy is a type: in fact it's an instance of the class template `boost::math::policies::policy<>`. This class is just a compile-time-container of user-selected policies (sometimes called a type-list).

Over a dozen policy defaults are provided, so most of the time you can ignore the policy framework, but you can overwrite the defaults with your own policies to give detailed control, for example:

    using namespace boost::math::policies;

    // Define a policy that sets ::errno on overflow,
    // and does not promote double to long double internally,
    // and only aims for precision of only 3 decimal digits,
    // to an error-handling policy, usually to trade precision for speed:

    typedef policy
    <
      domain_error<errno_on_error>,
      promote_double<false>,
      digits10<3>
    > my_policy;