function
<cmath> <ctgmath>

# lrint

```long int lrint  (double x);
long int lrintf (float x);
long int lrintl (long double x);
```
```long int lrint (double x);
long int lrint (float x);
long int lrint (long double x);
Round and cast to long integer
Rounds x to an integral value, using the rounding direction specified by fegetround, and returns it as a value of type `long int`.

See llrint for an equivalent function that returns a `long long int`.

Header <tgmath.h> provides a type-generic macro version of this function.
Additional overloads are provided in this header (`<cmath>`) for the integral types: These overloads effectively cast x to a `double` before calculations (defined for T being any integral type).

x
Value to round.

### Return Value

The value of x rounded to a nearby integral, casted to a value of type `long int`.
If the rounded value is outside the range of the return type, the value returned is unspecified, and a domain error or an overflow range error may occur (or none, depending on implementation).

If a domain error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to EDOM.
- And math_errhandling has MATH_ERREXCEPT set: FE_INVALID is raised.

If an overflow range error occurs:
- And math_errhandling has MATH_ERRNO set: the global variable errno is set to ERANGE.
- And math_errhandling has MATH_ERREXCEPT set: FE_OVERFLOW is raised.

### Example

 ``1234567891011121314151617181920212223`` ``````/* lrint example */ #include /* printf */ #include /* fegetround, FE_* */ #include /* lrint */ int main () { printf ("rounding using "); switch (fegetround()) { case FE_DOWNWARD: printf ("downward"); break; case FE_TONEAREST: printf ("to-nearest"); break; case FE_TOWARDZERO: printf ("toward-zero"); break; case FE_UPWARD: printf ("upward"); break; default: printf ("unknown"); } printf (" rounding:\n"); printf ( "lrint (2.3) = %ld\n", lrint(2.3) ); printf ( "lrint (3.8) = %ld\n", lrint(3.8) ); printf ( "lrint (-2.3) = %ld\n", lrint(-2.3) ); printf ( "lrint (-3.8) = %ld\n", lrint(-3.8) ); return 0; }``````

Possible output:
 ``` Rounding using to-nearest rounding: lrint (2.3) = 2 lrint (3.8) = 4 lrint (-2.3) = -2 lrint (-3.8) = -4 ```