nexttowardl Function

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

Include

<math.h>

Prototype

long double nexttowardl(long double x, long double y);

Arguments

x
the original value
y
the target value as a long double

Return Value

Determines the next value after x in the direction of y that can be represented by the long double type. The value of y converted to the type of the function 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)
{
  long double x, z;
  long double y;

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

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

}

Example Output

The next representable value after 150.000000 in the direction of 300.000000 is 150.0000000000
The next representable value after 150.000000 in the direction of -300.000000 is 150.0000000000