The lrintl()
function casts the given long double
argument to an integral number, a long int
, based on the chosen mode of rounding.
lrintl()
is a variation of thelrint()
function.
#include<math.h>
The following are the declarations of lrintl()
:
long int lrintl(long double x);
We can specify the mode of rounding before calling lrintl()
. The four modes of rounding are as follows:
In this mode, the long double
value is rounded
to the nearest integer.
In this mode, lrintl()
returns the floor
of the long double
value.
In this mode, lrintl()
returns the ceil
of the long double
value.
In this mode, lrintl()
returns the integer that is closer to zero
.
Note: The default mode of rounding is FE_TONEAREST.
#include <stdio.h>#include <fenv.h> //header file for fesetround()#include <math.h>int main(){long double x = 0.4;printf("%ld", lrintl(x)); //rounding off the numberfesetround(FE_DOWNWARD);x = -1.2;printf("\n%ld", lrintl(x)); //calculating floor of numberfesetround(FE_UPWARD);x = -2.8;printf("\n%ld", lrintl(x)); //calculating ceil of numberfesetround(FE_TOWARDZERO);x = 1.9;printf("\n%ld", lrintl(x)); //return number closer to zeroreturn 0;}
Free Resources