nextafter
, nextafterf
, nextafterl
, _nextafter
, _nextafterf
, nexttoward
, nexttowardf
, nexttowardl
Returns the next representable floating-point value.
Syntax
double nextafter( double x, double y );
float nextafterf( float x, float y );
long double nextafterl( long double x, long double y );
double _nextafter( double x, double y );
float _nextafterf( float x, float y ); /* x64 only */
#define nextafter(X, Y) // Requires C11 or higher
double nexttoward( double x, long double y );
float nexttowardf( float x, long double y );
long double nexttowardl( long double x, long double y );
#define nexttoward(X, Y) // Requires C11 or higher
float nextafter( float x, float y ); /* C++ only, requires <cmath> */
long double nextafter( long double x, long double y ); /* C++ only, requires <cmath> */
float nexttoward( float x, long double y ); /* C++ only, requires <cmath> */
long double nexttoward( long double x, long double y ); /* C++ only, requires <cmath> */
Parameters
x
The floating-point value to start from.
y
The floating-point value to go towards.
Return value
Returns the next representable floating-point value of the return type after x
in the direction of y
. If x
and y
are equal, the function returns y
, converted to the return type, with no exception triggered. If x
isn't equal to y
, and the result is a denormal or zero, the FE_UNDERFLOW
and FE_INEXACT
floating-point exception states are set, and the correct result is returned. If either x
or y
is a NAN, then the return value is one of the input NANs. If x
is finite and the result is infinite or not representable in the type, a correctly signed infinity or NAN is returned, the FE_OVERFLOW
and FE_INEXACT
floating-point exception states are set, and errno
is set to ERANGE
.
Remarks
The nextafter
and nexttoward
function families are equivalent, except for the parameter type of y
. If x
and y
are equal, the value returned is y
converted to the return type.
Because C++ allows overloading, if you include <cmath>
you can call overloads of nextafter
and nexttoward
that return float
and long double
types. In a C program, unless you're using the <tgmath.h>
macro to call this function, nextafter
and nexttoward
always return double
.
If you use the nextafter
or nexttoward
macro from <tgmath.h>
, the type of the argument determines which version of the function is selected. See Type-generic math for details.
The _nextafter
and _nextafterf
functions are Microsoft-specific. The _nextafterf
function is only available when compiling for x64.
By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.
Requirements
Routine | Required header (C) | Required header (C++) |
---|---|---|
nextafter , nextafterf , nextafterl , _nextafterf , nexttoward , nexttowardf , nexttowardl |
<math.h> |
<math.h> or <cmath> |
_nextafter |
<float.h> |
<float.h> or <cfloat> |
nextafter macro, nexttoward macro |
<tgmath.h> |
For more compatibility information, see Compatibility.