In C++, the nextafter() function is defined in the <cmath> or <math.h> header file and is used to return the next representable floating-point value of a number in the direction of another number. It is useful for working with floating-point precision and low-level numerical computations.
If the values of from and to are equal, the function simply returns the value of from. Otherwise, it returns the next representable floating-point value of from moving toward to.
It has the following syntax.
( from, to): These are the floating point values.
Here, we are going to discuss several examples to demonstrate the List nextafter() Function Function.
This example demonstrates how the nextafter() function behaves when the values of from and to are equal.
Output:
Values of from and to are:6.7, 6.7 6.7
Explanation:
In the above example, values of 'from' and 'to' are equal. Therefore, the function returns the value of 'from'.
This example demonstrates how the nextafter() function returns the next representable floating-point value when from and to are different.
Output:
Values of from and to are:0, 6 4.94066e-324
Explanation:
In the above example, 'from' and 'to' are of same type but are unequal. The nextafter() function returns the value i.e 4.94066e-324
This example demonstrates how the nextafter() function finds the next representable value when moving from one negative number toward another negative number.
Output:
Values of from and to are : -2, -5 -2
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India