function
<cmath> <ctgmath>
llrint
long long int llrint (double x);
long long int llrintf (float x);
long long int llrintl (long double x);
long long int llrint (double x);
long long int llrint (float x);
long long int llrint (long double x);
long long int llrint (T x); // additional overloads for integral types
Round and cast to long long integer
Rounds x to an integral value, using the rounding direction specified by fegetround, and returns it as a value of type long long int
.
See lrint for an equivalent function that returns a 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).
Parameters
- x
- Value to round.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
/* llrint example */
#include <stdio.h> /* printf */
#include <fenv.h> /* fegetround, FE_* */
#include <math.h> /* llrint */
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 ( "llrint (2.3) = %lld\n", llrint(2.3) );
printf ( "llrint (3.8) = %lld\n", llrint(3.8) );
printf ( "llrint (-2.3) = %lld\n", llrint(-2.3) );
printf ( "llrint (-3.8) = %lld\n", llrint(-3.8) );
return 0;
}
|
Possible output:
Rounding using to-nearest rounding:
llrint (2.3) = 2
llrint (3.8) = 4
llrint (-2.3) = -2
llrint (-3.8) = -4
|
See also
- nearbyint
- Round to nearby integral value (function
)
- rint
- Round to integral value (function
)
- lrint
- Round and cast to long integer (function
)
- round
- Round to nearest (function
)
- floor
- Round down value (function
)
- ceil
- Round up value (function
)
- trunc
- Truncate value (function
)