1ROUND(3P) POSIX Programmer's Manual ROUND(3P)
2
3
4
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
12 round, roundf, roundl - round to the nearest integer value in a float‐
13 ing-point format
14
16 #include <math.h>
17
18 double round(double x);
19 float roundf(float x);
20 long double roundl(long double x);
21
22
24 These functions shall round their argument to the nearest integer value
25 in floating-point format, rounding halfway cases away from zero,
26 regardless of the current rounding direction.
27
28 An application wishing to check for error situations should set errno
29 to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these
30 functions. On return, if errno is non-zero or fetestexcept(FE_INVALID
31 | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
32 occurred.
33
35 Upon successful completion, these functions shall return the rounded
36 integer value.
37
38 If x is NaN, a NaN shall be returned.
39
40 If x is ±0 or ±Inf, x shall be returned.
41
42 If the correct value would cause overflow, a range error shall occur
43 and round(), roundf(), and roundl() shall return the value of the macro
44 ±HUGE_VAL, ±HUGE_VALF, and ±HUGE_VALL (with the same sign as x),
45 respectively.
46
48 These functions may fail if:
49
50 Range Error
51 The result overflows.
52
53 If the integer expression (math_errhandling & MATH_ERRNO) is non-zero,
54 then errno shall be set to [ERANGE]. If the integer expression
55 (math_errhandling & MATH_ERREXCEPT) is non-zero, then the overflow
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 None.
71
73 None.
74
76 feclearexcept(), fetestexcept(), the Base Definitions volume of
77 IEEE Std 1003.1-2001, Section 4.18, Treatment of Error Conditions for
78 Mathematical Functions, <math.h>
79
81 Portions of this text are reprinted and reproduced in electronic form
82 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
83 -- Portable Operating System Interface (POSIX), The Open Group Base
84 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
85 Electrical and Electronics Engineers, Inc and The Open Group. In the
86 event of any discrepancy between this version and the original IEEE and
87 The Open Group Standard, the original IEEE and The Open Group Standard
88 is the referee document. The original Standard can be obtained online
89 at http://www.opengroup.org/unix/online.html .
90
91
92
93IEEE/The Open Group 2003 ROUND(3P)