DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

rint(S)


rint, lrint, llrint, round, lround, llround, trunc -- nearest integer value, rounding and truncation functions

Syntax

   cc [flag ...] file ...  -lm [library ...]
   

#include <math.h>

double rint(double x);

float rintf(float x);

long double rintl(long double x);

long int lrint(double x);

long int lrintf(float x);

long int lrintl(long double x);

long long int llrint(double x);

long long int llrintf(float x);

long long int double llrintl(long double x);

double round(double x);

float roundf(float x);

long double roundl(long double x);

long int lround(double x);

long int lroundf(float x);

long int lroundl(long double x);

long long int llround(double x);

long long int llroundf(float x);

long long int llroundl(long double x);

double trunc(double x);

float truncf(float x);

long double truncl(long double x);

Description

rint, rintf and rintl return the nearest integer value to its floating point argument x as a double-precision floating point number. The returned value is rounded according to the currently set machine rounding mode. If round-to-nearest (the default mode) is set and the difference between the function argument and the rounded result is exactly 0.5, then the result will be rounded to the nearest even integer. If the returned value does not equal the value specified in the argument, the rint functions raise the inexact floating-point exception.

lrint, lrintf, lrintl, llrint, llrintf and llrintl round their argument to the nearest integer value, according to the current rounding direction. If the rounded value is outside the range of the return type, the numeric result is unspecified. A range error can occur if the magnitude of x is too large.

round, roundf and roundl round their argument to the nearest integer value in floating-point format, rounding halfway cases away from zero, regardless of the current rounding direction.

lround, lroundf, lroundl llround, llroundf and llroundl round their argument to the nearest integer value in floating-point format, rounding halfway cases away from zero, regardless of the current rounding direction. If the rounded value is outside the range of the return type, the numeric result is unspecified. A range error can occur if the magnitude of x is too large.

trunc, truncf and truncl return the nearest integer value that is less than or equal to x.

Errors

If the returned value is calculated as falling outside of the range of LONG_MIN to LONG_MAX lrint, lrintf, lrintl, lround, lroundf and lroundl return LONG_MIN instead and set errno to ERANGE.

If the returned value is calculated as falling outside of the range of LLONG_MIN to LLONG_MAX llrint, llrintf, llrintl, llround, llroundf and llroundl return LLONG_MIN instead and set errno to ERANGE.

On systems that support IEEE NaN, if the argument to any of these functions is a quiet NaN, that value is returned. If the argument is a signaling NaN, a quiet NaN is returned and the invalid operation exception is raised. In either case, errno is set to EDOM.

See also

cc(CP), math(M), matherr(S)
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003