Previous Page
Next Page


Obtains the next representable value

#include <math.h>
double nextafter ( double x , double y  );
float nextafterf ( float x , float y  );
long double nextafterl ( long double x , long double y  );

The nextafter( ) function returns the next value to the first argument x, removed from it in the direction toward the value of y, that is representable in the function's type. If the values of the two arguments are equal, nextafter( ) returns the value of the second argument y.

If the argument x has the magnitude of the largest finite value that can be represented in the function's type, and the result is not a finite, representable value, then a range error may occur.


double x = nextafter( 0.0, 1.0 );
printf("The smallest positive number "
       "with the type double: %E\n", x);

This code produces output like the following:

The smallest positive number with the type double: 4.940656E-324

See Also

nexttoward( ), nearbyint( ), rint( ), lrint( ), llrint( ), round( ), lround( ), llround( ), ceil( ), floor( )

Previous Page
Next Page