lrint - C math.h

C examples for math.h:lrint

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Rounds x to an integral value, using the rounding direction specified by fegetround, and returns it as a value of type long int.

Prototype

long int lrint  (double x);
long int lrintf (float x);
long int lrintl (long double x);
long int lrint (float x);
long int lrint (long double x);
long int lrint (T x);           

Parameters

Parameter Description
x Value to round.

Return Value

The value of x rounded to a nearby integral, casted to a value of type long int.

Example

Demo Code


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

int main ()//from   w  ww  .j a v a2  s .co  m
{
  printf ( "%ld\n", lrint(2.1) );
  printf ( "%ld\n", lrint(3.9) );
  printf ( "%ld\n", lrint(-2.1) );
  printf ( "%ld\n", lrint(-3.9) );
  return 0;
}

Related Tutorials