function
<cmath> <ctgmath>
lrintlong 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);long int lrint (T x); // additional overloads for integral types
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 typelong 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.
are provided in this header (
<cmath>
) for the
integral types: These overloads effectively cast
xto a
double
before calculations (defined for
Tbeing any
integral type).
long int
.
If a domain error occurs:
If an overflow range error occurs:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* lrint example */
#include <stdio.h> /* printf */
#include <fenv.h> /* fegetround, FE_* */
#include <math.h> /* 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;
}
Rounding using to-nearest rounding: lrint (2.3) = 2 lrint (3.8) = 4 lrint (-2.3) = -2 lrint (-3.8) = -4
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4