nextafter - C math.h

C examples for math.h:nextafter

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Returns the next representable value after x in the direction of y.

Prototype

long double nextafterl (long double x, long double y);
long double nextafter (long double x, long double y );
     double nextafter  (double x     , double y);
      float nextafterf (float x      , float y);
      float nextafter (float x      , float y );
     double nextafter (Type1 x      , Type2 y);        

Parameters

Parameter Description
x Base value.
y Value toward which the return value is approximated.

If both parameters compare equal, the function returns y.

Return Value

The next representable value after x in the direction of y.

Demo Code


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

int main ()//from  www .  j  a  va2s. c o  m
{
  printf ("first representable value greater than zero: %e\n", nextafter(0.0,1.0));
  printf ("first representable value less than zero: %e\n", nextafter(0.0,-1.0));
  
  printf ("%e\n", nextafter(10.0,-1.0));
  return 0;
}

Related Tutorials