`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

*. If*

`y`

*and*

`x`

*are equal, the function returns*

`y`

*, converted to the return type, with no exception triggered. If*

`y`

*isn't equal to*

`x`

*, and the result is a denormal or zero, the*

`y`

`FE_UNDERFLOW`

and `FE_INEXACT`

floating-point exception states are set, and the correct result is returned. If either *or*

`x`

*is a NAN, then the return value is one of the input NANs. If*

`y`

*is finite and the result is infinite or not representable in the type, a correctly signed infinity or NAN is returned, the*

`x`

`FE_OVERFLOW`

and `FE_INEXACT`

floating-point exception states are set, and `errno`

is set to `ERANGE`

.## Remarks

The ** nextafter** and

**function families are equivalent, except for the parameter type of**

`nexttoward`

*. If*

`y`

*and*

`x`

*are equal, the value returned is*

`y`

*converted to the return type.*

`y`

Because C++ allows overloading, if you include `<cmath>`

you can call overloads of ** nextafter** and

**that return**

`nexttoward`

**and**

`float`

**types. In a C program, unless you're using the**

`long double`

`<tgmath.h>`

macro to call this function, **and**

`nextafter`

**always return**

`nexttoward`

**.**

`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

**functions are Microsoft-specific. The**

`_nextafterf`

**function is only available when compiling for x64.**

`_nextafterf`

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>` |

macro, `nextafter` macro`nexttoward` |
`<tgmath.h>` |

For more compatibility information, see Compatibility.

## See also

## Feedback

https://aka.ms/ContentUserFeedback.

Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for