◆ nextafter()

Value boost::simd::nextafter ( Value const &  x,
Value const &  y 
)

Returns the next representable value of x in the direction of y.

Header <boost/simd/function/nextafter.hpp>
Semantic:
auto r = nextafter(x, y);

is similar to:

if (y > x) r = next(x);
else if (y == x) r = x;
else if (y < x) r = prev(x);
See also
next, prev, successor, predecessor
Note
C++11 standard library also defines nexttoward, but as (for SIMD considerations) x and y must be here of same type, the two function would coincide. So nexttoward is not defined in boost.simd.
Decorators
  • std_ calls std::nextafter
Example:
#include <boost/simd/ieee.hpp>
#include <boost/simd/pack.hpp>
#include <iostream>
#include <iomanip>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
int main()
{
pack_ft pf = {1.0f, 2.0f, -1.0f, 0.5f};
pack_ft qf = {2.0f, -1.0f, 0.5f, 1.0f};
std::cout
<< "---- simd" << std::setprecision(10) << '\n'
<< "<- pf = " << pf << '\n'
<< "<- qf = " << qf << '\n'
<< "-> bs::nextafter(pf, qf) = " << bs::nextafter(pf, qf) << '\n';
float xf = 2.0f, yf = -1.0f;
std::cout
<< "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "<- yf = " << yf << '\n'
<< "-> bs::nextafter(xf, yf) = " << bs::nextafter(xf, yf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (1, 2, -1, 0.5)
<- qf = (2, -1, 0.5, 1)
-> bs::nextafter(pf, qf) = (1.000000119, 1.999999881, -0.9999999404, 0.5000000596)
---- scalar
<- xf = 2
<- yf = -1
-> bs::nextafter(xf, yf) = 1.999999881