nextafter Function

Determines the next value after x in the direction of y that can be represented by a double precision floating-point value.

Include

<math.h>

Prototype

double nextafter(double x, double y);

Arguments

x
the original value
y
the target value

Return Value

Determines the next value after x in the direction of y that can be represented by the type of the function. The value of y is returned if x equals y.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <math.h>
#include <stdio.h>

int main(void)
{
  double x,y,z;

  x = 150.0;
  y = 300.0;
  z = nextafter(x, y);
  printf("The next representable value after %f in the direction of %f is %.10f\n", x, y, z);

  x = 150.0;
  y = -300.0;
  z = nextafter(x, y);
  printf("The next representable value after %f in the direction of %f is %.10f\n", x, y, z);

}

Example Output

The next representable value after 150.00000 in the direction of 300.00000 is 150.0000152588
The next representable value after 150.00000 in the direction of -300.00000 is 149.9999847412