What is nextafterf in C/C++?

We use the nextafterf function to get the next representable floating-point value after the value of the first parameter. It is a variation of nextafter()used when the arguments are of type float.

Library for C

#include<math.h>

Library for C++

#include<cmath>

Syntax

float nextafterf( float a, float b);

Parameters

a: We start from this float value.

b: We go towards this float value.

Return values

The function returns the next representable floating-point value starting from a, moving towards b.

If a and b are equal, then the function returns b.

Code

#include <math.h>
#include <stdio.h>
int main()
{
float answer;
answer = nextafterf( 1.5, 2.0 );
printf("The next representable float is : %.20g\n", answer); //%0.20g is used to represent 20 digits in the floating point number
return 0;
}

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved