1LROUND(P) POSIX Programmer's Manual LROUND(P)
2
3
4
6 lround, lroundf, lroundl - round to nearest integer value
7
9 #include <math.h>
10
11 long lround(double x);
12 long lroundf(float x);
13 long lroundl(long double x);
14
15
17 These functions shall round their argument to the nearest integer
18 value, rounding halfway cases away from zero, regardless of the current
19 rounding direction.
20
21 An application wishing to check for error situations should set errno
22 to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
23 functions. On return, if errno is non-zero or fetestexcept(FE_INVALID
24 | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
25 occurred.
26
28 Upon successful completion, these functions shall return the rounded
29 integer value.
30
31 If x is NaN, a domain error shall occur and an unspecified value is
32 returned.
33
34 If x is +Inf, a domain error shall occur and an unspecified value is
35 returned.
36
37 If x is -Inf, a domain error shall occur and an unspecified value is
38 returned.
39
40 If the correct value is positive and too large to represent as a long,
41 a domain error shall occur and an unspecified value is returned.
42
43 If the correct value is negative and too large to represent as a long,
44 a domain error shall occur and an unspecified value is returned.
45
47 These functions shall fail if:
48
49 Domain Error
50 The x argument is NaN or ±Inf, or the correct value is not rep‐
51 resentable as an integer.
52
53 If the integer expression (math_errhandling & MATH_ERRNO) is non-zero,
54 then errno shall be set to [EDOM]. If the integer expression
55 (math_errhandling & MATH_ERREXCEPT) is non-zero, then the invalid
56 floating-point exception shall be raised.
57
58
59 The following sections are informative.
60
62 None.
63
65 On error, the expressions (math_errhandling & MATH_ERRNO) and
66 (math_errhandling & MATH_ERREXCEPT) are independent of each other, but
67 at least one of them must be non-zero.
68
70 These functions differ from the lrint() functions in the default round‐
71 ing direction, with the lround() functions rounding halfway cases away
72 from zero and needing not to raise the inexact floating-point exception
73 for non-integer arguments that round to within the range of the return
74 type.
75
77 None.
78
80 feclearexcept() , fetestexcept() , llround() , the Base Definitions
81 volume of IEEE Std 1003.1-2001, Section 4.18, Treatment of Error Condi‐
82 tions for Mathematical Functions, <math.h>
83
85 Portions of this text are reprinted and reproduced in electronic form
86 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
87 -- Portable Operating System Interface (POSIX), The Open Group Base
88 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
89 Electrical and Electronics Engineers, Inc and The Open Group. In the
90 event of any discrepancy between this version and the original IEEE and
91 The Open Group Standard, the original IEEE and The Open Group Standard
92 is the referee document. The original Standard can be obtained online
93 at http://www.opengroup.org/unix/online.html .
94
95
96
97IEEE/The Open Group 2003 LROUND(P)