Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world.

Calculating the Representation Distance Between Two floating-point Values (ULP) float_distance

Function float_distance finds the number of gaps/bits/ULP between any two floating-point values. If the significands of floating-point numbers are viewed as integers, then their difference is the number of ULP/gaps/bits different.

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

template <class FPT>
FPT float_distance(FPT a, FPT b);

}} // namespaces
```
Description - float_distance

Returns the distance between a and b: the result is always a signed integer value (stored in floating-point type FPT) representing the number of distinct representations between a and b.

Note that

• `float_distance(a, a)` always returns 0.
• `float_distance(float_next(a), a)` always returns -1.
• `float_distance(float_prior(a), a)` always returns 1.

The function `float_distance` is equivalent to calculating the number of ULP (Units in the Last Place) between a and b except that it returns a signed value indicating whether ```a > b``` or not.

If the distance is too great then it may not be able to be represented as an exact integer by type FPT, but in practice this is unlikely to be a issue.

 Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle Walker 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)