lrint, lrintf, lrintl, llrint, llrintf, llrintl

Rounds the specified floating-point value to the nearest integral value, by using the current rounding mode and direction.

Syntax

long int lrint(
   double x
);

long int lrint(
   float x
); //C++ only

long int lrint(
   long double x
); //C++ only

long int lrintf(
   float x
);

long int lrintl(
   long double x
);

long long int llrint(
   double x
);

long long int llrint(
   float x
); //C++ only

long long int llrint(
   long double x
); //C++ only

long long int llrintf(
   float x
);

long long int llrintl(
   long double x
);

#define lrint(X) // Requires C11 or higher

Parameters

x
The value to round.

Return Value

If successful, returns the rounded integral value of x.

Issue Return
x is outside the range of the return type

x = ±∞

x = NaN
Raises FE_INVALID and returns zero (0).

Remarks

Because C++ allows overloading, you can call overloads of lrint and llrint that take float and long double types. In a C program, unless you're using the <tgmath.h> macro to call this function, lrint and llrint always take a double.

If you use the <tgmath.h> llrint() macro, the type of the argument determines which version of the function is selected. See Type-generic math for details.

If x does not represent the floating-point equivalent of an integral value, these functions raise FE_INEXACT.

Microsoft-specific: When the result is outside the range of the return type, or when the parameter is a NaN or infinity, the return value is implementation defined. The Microsoft compiler returns a zero (0) value.

By default, this function's global state is scoped to the application. To change this, see Global state in the CRT.

Requirements

Function C header C++ header
lrint, lrintf, lrintl, llrint, llrintf, llrintl <math.h> <cmath>
lrint macro <tgmath.h>

For additional compatibility information, see Compatibility.

See also

Alphabetical Function Reference