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

Function nexttoward

include/half.hpp:4292–4309  ·  view source on GitHub ↗

Next representable value. See also:** Documentation for [std::nexttoward](https://en.cppreference.com/w/cpp/numeric/math/nexttoward). \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 re

Source from the content-addressed store, hash-verified

4290 /// \exception FE_OVERFLOW for infinite result from finite argument
4291 /// \exception FE_UNDERFLOW for subnormal result
4292 inline half nexttoward(half from, long double to)
4293 {
4294 int fabs = from.data_ & 0x7FFF;
4295 if(fabs > 0x7C00)
4296 return half(detail::binary, detail::signal(from.data_));
4297 long double lfrom = static_cast<long double>(from);
4298 if(detail::builtin_isnan(to) || lfrom == to)
4299 return half(static_cast<float>(to));
4300 if(!fabs)
4301 {
4302 detail::raise(FE_UNDERFLOW, !HALF_ERRHANDLING_UNDERFLOW_TO_INEXACT);
4303 return half(detail::binary, (static_cast<unsigned>(detail::builtin_signbit(to))<<15)+1);
4304 }
4305 unsigned int out = from.data_ + (((from.data_>>15)^static_cast<unsigned>(lfrom<to))<<1) - 1;
4306 detail::raise(FE_OVERFLOW, (out&0x7FFF)==0x7C00);
4307 detail::raise(FE_UNDERFLOW, !HALF_ERRHANDLING_UNDERFLOW_TO_INEXACT && (out&0x7FFF)<0x400);
4308 return half(detail::binary, out);
4309 }
4310
4311 /// Take sign.
4312 /// **See also:** Documentation for [std::copysign](https://en.cppreference.com/w/cpp/numeric/math/copysign).

Callers

nothing calls this directly

Calls 5

halfClass · 0.85
signalFunction · 0.85
builtin_isnanFunction · 0.85
raiseFunction · 0.85
builtin_signbitFunction · 0.85

Tested by

no test coverage detected