std::nextafter,std::nextafterf,std::nextafterl,std::nexttoward,std::nexttowardf,std::nexttowardl (3) - Linux Manuals
std::nextafter,std::nextafterf,std::nextafterl,std::nexttoward,std::nexttowardf,std::nexttowardl: std::nextafter,std::nextafterf,std::nextafterl,std::nexttoward,std::nexttowardf,std::nexttowardl
NAME
std::nextafter,std::nextafterf,std::nextafterl,std::nexttoward,std::nexttowardf,std::nexttowardl - std::nextafter,std::nextafterf,std::nextafterl,std::nexttoward,std::nexttowardf,std::nexttowardl
Synopsis
Defined in header <cmath>
float nextafter ( float from, float to ); (1) (since C++11)
float nextafterf( float from, float to );
double nextafter ( double from, double to ); (2) (since C++11)
long double nextafter ( long double from, long double to ); (3) (since C++11)
long double nextafterl( long double from, long double to );
Promoted nextafter ( Arithmetic1 from, Arithmetic2 to ); (4) (since C++11)
float nexttoward ( float from, long double to ); (5) (since C++11)
float nexttowardf( float from, long double to );
double nexttoward ( double from, long double to ); (6) (since C++11)
long double nexttoward ( long double from, long double to ); (7) (since C++11)
long double nexttowardl( long double from, long double to );
double nexttoward ( IntegralType from, long double to ); (8) (since C++11)
Returns the next representable value of from in the direction of to.
1-3) If from equals to to, to is returned.
5-7) If from equals to to, to is returned, converted from long double to the return type of the function without loss of range or precision.
4) A set of overloads or a function template for all combinations of arguments of arithmetic type not covered by (1-3). If any argument has integral_type, it is cast to double. If any argument is long double, then the return type Promoted is also long double, otherwise the return type is always double.
8) A set of overloads or a function template accepting the from argument of any integral_type. Equivalent to (6) (the argument is cast to double).
Parameters
from, to - floating point values
Return value
If no errors occur, the next representable value of from in the direction of to. is returned. If from equals to, then to is returned.
If a range error due to overflow occurs, ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL is returned (with the same sign as from)
If a range error occurs due to underflow, the correct result is returned.
Error handling
Errors are reported as specified in math_errhandling.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
* if from is finite, but the expected result is an infinity, raises FE_INEXACT and FE_OVERFLOW
* if from does not equal to and the result is subnormal or zero, raises FE_INEXACT and FE_UNDERFLOW
* in any case, the returned value is independent of the current rounding mode
* if either from or to is NaN, NaN is returned
Notes
POSIX_specifies that the overflow and the underflow conditions are range errors (errno may be set)
IEC 60559 recommends that from is returned whenever from==to. These functions return to instead, which makes the behavior around zero consistent: std::nextafter(-0.0, +0.0) returns +0.0 and std::nextafter(+0.0, -0.0) returns –0.0.
Example
// Run this code