I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
ComputingCMath.h

lroundf

Round to integral value, regardless of rounding direction
+ View other versions (4)

Interface

#include <math.h>
double round (double x)
long roundl (long double x)
float roundf (float x)
long lround (double x)
long lroundl (long double x)
long lroundf (float x)
long llround (double x)
long llroundl (long double x)
long llroundf (float x)

Description

The round functions return the integral value nearest to x rounding half-way cases away from zero, regardless of the current rounding direction.

The lround and llround functions return the integral value nearest to x (rounding half-way cases away from zero, regardless of the current rounding direction) in the return formats specified. If the rounded value is outside the range of the return type, the numeric result is unspecified and the invalid floating-point exception is raised. A range error may occur if the magnitude of x is too large.

Example:
Example -
Workings
#include <stdio.h>
#include <math.h>
int main(void)
{
  for(double a=120;a<=130;a+=1.0) /* note: increments by fraction are not exact! */
    printf("round of  %.1lf is  %.1lf\n", a/10.0, round(a/10.0));
  return 0;
}
Solution
round of  12.0 is  12.0
round of  12.1 is  12.0
round of  12.2 is  12.0
round of  12.3 is  12.0
round of  12.4 is  12.0
round of  12.5 is  13.0
round of  12.6 is  13.0
round of  12.7 is  13.0
round of  12.8 is  13.0
round of  12.9 is  13.0
round of  13.0 is  13.0

Special Values

round ( ±0 ) returns ±0.

round ( ±∞ ) returns ±∞.

The round functions may, but are not required to, raise the inexact floating-point exception for non-integer numeric arguments.

The lround and llround functions need not raise the inexact floating-point exception for non-integer arguments that round to within the range of the return type.

Standards

The round, lround and llround functions conform to ISO/IEC 9899:1999(E).