]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" Copyright 2001 Andries Brouwer <aeb@cwi.nl>. |
2601c2d4 MK |
2 | .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk |
3 | .\" <mtk.manpages@gmail.com> | |
fea681da | 4 | .\" |
93015253 | 5 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
6 | .\" Permission is granted to make and distribute verbatim copies of this |
7 | .\" manual provided the copyright notice and this permission notice are | |
8 | .\" preserved on all copies. | |
9 | .\" | |
10 | .\" Permission is granted to copy and distribute modified versions of this | |
11 | .\" manual under the conditions for verbatim copying, provided that the | |
12 | .\" entire resulting derived work is distributed under the terms of a | |
13 | .\" permission notice identical to this one. | |
c13182ef | 14 | .\" |
fea681da MK |
15 | .\" Since the Linux kernel and libraries are constantly changing, this |
16 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
17 | .\" responsibility for errors or omissions, or for damages resulting from | |
18 | .\" the use of the information contained herein. The author(s) may not | |
19 | .\" have taken the same level of care in the production of this manual, | |
20 | .\" which is licensed free of charge, as they might when working | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
fea681da MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 25 | .\" %%%LICENSE_END |
fea681da | 26 | .\" |
4b8c67d9 | 27 | .TH ROUND 3 2017-09-15 "" "Linux Programmer's Manual" |
fea681da MK |
28 | .SH NAME |
29 | round, roundf, roundl \- round to nearest integer, away from zero | |
30 | .SH SYNOPSIS | |
31 | .nf | |
32 | .B #include <math.h> | |
68e4db0a | 33 | .PP |
fea681da | 34 | .BI "double round(double " x ); |
fea681da | 35 | .BI "float roundf(float " x ); |
fea681da MK |
36 | .BI "long double roundl(long double " x ); |
37 | .fi | |
68e4db0a | 38 | .PP |
cc4615cc | 39 | Link with \fI\-lm\fP. |
68e4db0a | 40 | .PP |
cc4615cc MK |
41 | .in -4n |
42 | Feature Test Macro Requirements for glibc (see | |
43 | .BR feature_test_macros (7)): | |
44 | .in | |
68e4db0a | 45 | .PP |
cc4615cc MK |
46 | .ad l |
47 | .BR round (), | |
48 | .BR roundf (), | |
49 | .BR roundl (): | |
b32e95f2 | 50 | .RS 4 |
e464f054 | 51 | _ISOC99_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L |
b32e95f2 MK |
52 | .RE |
53 | .ad | |
fea681da | 54 | .SH DESCRIPTION |
022671eb MK |
55 | These functions round |
56 | .I x | |
57 | to the nearest integer, but | |
fea681da | 58 | round halfway cases away from zero (regardless of the current rounding |
5dcc3b66 MK |
59 | direction, see |
60 | .BR fenv (3)), | |
61 | instead of to the nearest even integer like | |
fb186734 | 62 | .BR rint (3). |
847e0d88 | 63 | .PP |
2601c2d4 MK |
64 | For example, |
65 | .IR round(0.5) | |
66 | is 1.0, and | |
67 | .IR round(\-0.5) | |
68 | is \-1.0. | |
47297adb | 69 | .SH RETURN VALUE |
2601c2d4 | 70 | These functions return the rounded integer value. |
847e0d88 | 71 | .PP |
022671eb MK |
72 | If |
73 | .I x | |
74 | is integral, +0, \-0, NaN, or infinite, | |
75 | .I x | |
76 | itself is returned. | |
fea681da | 77 | .SH ERRORS |
2601c2d4 | 78 | No errors occur. |
efe294cb | 79 | POSIX.1-2001 documents a range error for overflows, but see NOTES. |
f0d7ce1d MK |
80 | .SH VERSIONS |
81 | These functions first appeared in glibc in version 2.1. | |
7836c64d | 82 | .SH ATTRIBUTES |
da0228a1 PH |
83 | For an explanation of the terms used in this section, see |
84 | .BR attributes (7). | |
85 | .TS | |
86 | allbox; | |
87 | lbw27 lb lb | |
88 | l l l. | |
89 | Interface Attribute Value | |
90 | T{ | |
7836c64d | 91 | .BR round (), |
ed21d749 | 92 | .BR roundf (), |
7836c64d | 93 | .BR roundl () |
da0228a1 PH |
94 | T} Thread safety MT-Safe |
95 | .TE | |
47297adb | 96 | .SH CONFORMING TO |
9a74e018 | 97 | C99, POSIX.1-2001, POSIX.1-2008. |
fea681da | 98 | .SH NOTES |
68e1685c | 99 | POSIX.1-2001 contains text about overflow (which might set |
fea681da | 100 | .I errno |
2f0af33b MK |
101 | to |
102 | .BR ERANGE , | |
2601c2d4 MK |
103 | or raise an |
104 | .B FE_OVERFLOW | |
105 | exception). | |
fea681da MK |
106 | In practice, the result cannot overflow on any current machine, |
107 | so this error-handling stuff is just nonsense. | |
2601c2d4 | 108 | .\" The POSIX.1-2001 APPLICATION USAGE SECTION discusses this point. |
fea681da MK |
109 | (More precisely, overflow can happen only when the maximum value |
110 | of the exponent is smaller than the number of mantissa bits. | |
2601c2d4 MK |
111 | For the IEEE-754 standard 32-bit and 64-bit floating-point numbers |
112 | the maximum value of the exponent is 128 (respectively, 1024), | |
113 | and the number of mantissa bits is 24 (respectively, 53).) | |
847e0d88 | 114 | .PP |
2601c2d4 MK |
115 | If you want to store the rounded value in an integer type, |
116 | you probably want to use one of the functions described in | |
117 | .BR lround (3) | |
118 | instead. | |
47297adb | 119 | .SH SEE ALSO |
fea681da MK |
120 | .BR ceil (3), |
121 | .BR floor (3), | |
122 | .BR lround (3), | |
123 | .BR nearbyint (3), | |
124 | .BR rint (3), | |
125 | .BR trunc (3) |