1LROUND(3P)                 POSIX Programmer's Manual                LROUND(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       lround, lroundf, lroundl — round to nearest integer value
13

SYNOPSIS

15       #include <math.h>
16
17       long lround(double x);
18       long lroundf(float x);
19       long lroundl(long double x);
20

DESCRIPTION

22       The functionality described on this reference page is aligned with  the
23       ISO C  standard.  Any  conflict between the requirements described here
24       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2017
25       defers to the ISO C standard.
26
27       These  functions  shall  round  their  argument  to the nearest integer
28       value, rounding halfway cases away from zero, regardless of the current
29       rounding direction.
30
31       An  application  wishing to check for error situations should set errno
32       to zero and  call  feclearexcept(FE_ALL_EXCEPT)  before  calling  these
33       functions. On return, if errno is non-zero or fetestexcept(FE_INVALID |
34       FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero,  an  error  has
35       occurred.
36

RETURN VALUE

38       Upon  successful  completion,  these functions shall return the rounded
39       integer value.
40
41       If x is NaN, a domain error shall occur and  an  unspecified  value  is
42       returned.
43
44       If  x  is  +Inf, a domain error shall occur and an unspecified value is
45       returned.
46
47       If x is -Inf, a domain error shall occur and an  unspecified  value  is
48       returned.
49
50       If  the correct value is positive and too large to represent as a long,
51       an unspecified value shall be returned.  On systems  that  support  the
52       IEC  60559  Floating-Point  option,  a domain shall occur; otherwise, a
53       domain error may occur.
54
55       If the correct value is negative and too large to represent as a  long,
56       an  unspecified  value  shall be returned.  On systems that support the
57       IEC 60559 Floating-Point option, a domain  shall  occur;  otherwise,  a
58       domain error may occur.
59

ERRORS

61       These functions shall fail if:
62
63       Domain Error
64                   The  x argument is NaN or ±Inf, or the correct value is not
65                   representable as an integer.
66
67                   If the integer expression (math_errhandling  &  MATH_ERRNO)
68                   is  non-zero,  then  errno  shall be set to [EDOM].  If the
69                   integer expression (math_errhandling &  MATH_ERREXCEPT)  is
70                   non-zero,  then  the invalid floating-point exception shall
71                   be raised.
72
73       These functions may fail if:
74
75       Domain Error
76                   The correct value is not representable as an integer.
77
78                   If the integer expression (math_errhandling  &  MATH_ERRNO)
79                   is  non-zero,  then  errno  shall be set to [EDOM].  If the
80                   integer expression (math_errhandling &  MATH_ERREXCEPT)  is
81                   non-zero,  then  the invalid floating-point exception shall
82                   be raised.
83
84       The following sections are informative.
85

EXAMPLES

87       None.
88

APPLICATION USAGE

90       On  error,  the  expressions  (math_errhandling   &   MATH_ERRNO)   and
91       (math_errhandling  & MATH_ERREXCEPT) are independent of each other, but
92       at least one of them must be non-zero.
93

RATIONALE

95       These functions differ from the lrint() functions in the default round‐
96       ing  direction, with the lround() functions rounding halfway cases away
97       from zero and needing not to raise the inexact floating-point exception
98       for  non-integer arguments that round to within the range of the return
99       type.
100

FUTURE DIRECTIONS

102       None.
103

SEE ALSO

105       feclearexcept(), fetestexcept(), llround()
106
107       The Base Definitions volume of POSIX.1‐2017, Section 4.20, Treatment of
108       Error Conditions for Mathematical Functions, <math.h>
109
111       Portions  of  this text are reprinted and reproduced in electronic form
112       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
113       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
114       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
115       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
116       event of any discrepancy between this version and the original IEEE and
117       The  Open Group Standard, the original IEEE and The Open Group Standard
118       is the referee document. The original Standard can be  obtained  online
119       at http://www.opengroup.org/unix/online.html .
120
121       Any  typographical  or  formatting  errors that appear in this page are
122       most likely to have been introduced during the conversion of the source
123       files  to  man page format. To report such errors, see https://www.ker
124       nel.org/doc/man-pages/reporting_bugs.html .
125
126
127
128IEEE/The Open Group                  2017                           LROUND(3P)
Impressum