rint - C math.h

C examples for math.h:rint

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

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

Prototype

long double rintl (long double x);
long double rint (long double x);
     double rint  (double x);
      float rintf (float x);
      float rint (float x);
     double rint (T x);           

Parameters

Parameter Description
x Value to round.

Return Value

The value of x rounded to a nearby integral as a floating-point value.

Demo Code


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

int main ()//from  w w  w . j  ava  2 s .  co  m
{
  printf ( "rint (2.3) = %.1f\n", rint(2.1) );
  printf ( "rint (3.8) = %.1f\n", rint(3.9) );
  printf ( "rint (-2.3) = %.1f\n", rint(-2.1) );
  printf ( "rint (-3.8) = %.1f\n", rint(-3.9) );
  return 0;
}

Related Tutorials