C <math.h> - nextafter() Function
The C <math.h> nextafter() function returns the next representable value after x in the direction of y. The nexttoward() function is similar to this function, except it takes a long double as second argument.
Syntax
double nextafter (double x, double y); float nextafterf (float x, float y); long double nextafterl (long double x, long double y);
Parameters
x |
Specify the base value. |
y |
Specify the value toward which the return value is approximated. |
Return Value
Returns the next representable value after x in the direction of y.
Example:
The example below shows the usage of nextafter() function.
#include <stdio.h> #include <math.h> int main (){ printf("nextafter(0.0, 1.0): %e\n", nextafter(0.0, 1.0)); printf("nextafter(0.0, -1.0): %e\n", nextafter(0.0, -1.0)); return 0; }
The output of the above code will be:
nextafter(0.0, 1.0): 4.940656e-324 nextafter(0.0, -1.0): -4.940656e-324
❮ C <math.h> Library