What is lrint() in C?

The lrint() function casts the given double value to an integral number: a long int, based on the selected mode of rounding.

Library

#include<math.h>

Declaration

The following are the declarations of lrint():

long int lrint(double x);

Modes of rounding

We can specify the modes of rounding before calling lrint().
The four modes of rounding are as follows:

1. FE_TONEAREST

In this mode, the floating point value is rounded to the nearest integer.

2. FE_DOWNWARD

In this mode, lrint() returns the floor of the floating-point value.

3. FE_UPWARD

In this mode, lrint() returns the ceil of the floating-point value.

4. FE_TOWARDZERO

In this mode, lrint() returns the integer that is closer to zero.

Note: The default mode of rounding is FE_TONEAREST.

Code

#include <stdio.h>
#include <fenv.h> //header file for fesetround()
#include <math.h>
int main()
{
printf("%ld", lrint(1.5)); //rounding off the number
fesetround(FE_DOWNWARD);
printf("\n%ld", lrint(2.9)); //calculating floor of number
fesetround(FE_UPWARD);
printf("\n%ld", lrint(0.2)); //calculating ceil of number
fesetround(FE_TOWARDZERO);
printf("\n%ld", lrint(-2.8)); //return number closer to zero
return 0;
}

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved