MCPcopy Create free account
hub / github.com/apache/singa / nextafter

Function nextafter

include/half.hpp:4265–4282  ·  view source on GitHub ↗

Next representable value. See also:** Documentation for [std::nextafter](https://en.cppreference.com/w/cpp/numeric/math/nextafter). \param from value to compute next representable value for \param to direction towards which to compute next value \return next representable value after \a from in direction towards \a to \exception FE_INVALID for signaling NaN \exception FE_OVERFLOW for infinite resu

Source from the content-addressed store, hash-verified

4263 /// \exception FE_OVERFLOW for infinite result from finite argument
4264 /// \exception FE_UNDERFLOW for subnormal result
4265 inline half nextafter(half from, half to)
4266 {
4267 int fabs = from.data_ & 0x7FFF, tabs = to.data_ & 0x7FFF;
4268 if(fabs > 0x7C00 || tabs > 0x7C00)
4269 return half(detail::binary, detail::signal(from.data_, to.data_));
4270 if(from.data_ == to.data_ || !(fabs|tabs))
4271 return to;
4272 if(!fabs)
4273 {
4274 detail::raise(FE_UNDERFLOW, !HALF_ERRHANDLING_UNDERFLOW_TO_INEXACT);
4275 return half(detail::binary, (to.data_&0x8000)+1);
4276 }
4277 unsigned int out = from.data_ + (((from.data_>>15)^static_cast<unsigned>(
4278 (from.data_^(0x8000|(0x8000-(from.data_>>15))))<(to.data_^(0x8000|(0x8000-(to.data_>>15))))))<<1) - 1;
4279 detail::raise(FE_OVERFLOW, fabs<0x7C00 && (out&0x7C00)==0x7C00);
4280 detail::raise(FE_UNDERFLOW, !HALF_ERRHANDLING_UNDERFLOW_TO_INEXACT && (out&0x7C00)<0x400);
4281 return half(detail::binary, out);
4282 }
4283
4284 /// Next representable value.
4285 /// **See also:** Documentation for [std::nexttoward](https://en.cppreference.com/w/cpp/numeric/math/nexttoward).

Callers

nothing calls this directly

Calls 3

halfClass · 0.85
signalFunction · 0.85
raiseFunction · 0.85

Tested by

no test coverage detected