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

PrevUpHomeNext

Obtaining the Size of a Unit In the Last Place - ULP

Function ulp gives the size of a unit-in-the-last-place for a specified floating-point value.

Synopsis
#include <boost/math/special_functions/ulp.hpp>
namespace boost{ namespace math{

template <class FPT>
FPT ulp(const FPT& x);

template <class FPT, class Policy>
FPT ulp(const FPT& x, const Policy&);

}} // namespaces
Description - ulp

Returns one unit in the last place of x.

Corner cases are handled as follows:

Important: The behavior of this function is aligned to that of Java's ulp function, please note however that this function should only ever be used for rough and ready calculations as there are enough corner cases to trap even careful programmers. In particular:

In light of the issues above, we recommend that:

There is none the less, one important use case for this function:

If it is known that the true result of some function is xt and the calculated result is xc, then the error measured in ulp is simply fabs(xt - xc) / ulp(xt).


PrevUpHomeNext