nearbyint - C math.h

C examples for math.h:nearbyint

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Rounds x to an integral value, using the rounding direction specified by fegetround.

Prototype

long double nearbyintl (long double x);
long double nearbyint (long double x);
     double nearbyint  (double x);
      float nearbyintf (float x);
      float nearbyint (float x);
     double nearbyint (T x);           

Parameters

Parameter Description
x Value to round.

Return Value

The value of x rounded to a nearby integral.

Demo Code


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

int main ()/*from   w  ww.  j  av  a  2  s.c om*/
{
  printf ( "%.1f\n", nearbyint(2.1) );
  printf ( "%.1f\n", nearbyint(3.9) );
  printf ( "%.1f\n", nearbyint(-2.1) );
  printf ( "%.1f\n", nearbyint(-3.9) );
  return 0;
}

Related Tutorials