]>
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 | .\" |
5fbde956 | 5 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da | 6 | .\" |
4c1c5274 | 7 | .TH round 3 (date) "Linux man-pages (unreleased)" |
fea681da MK |
8 | .SH NAME |
9 | round, roundf, roundl \- round to nearest integer, away from zero | |
f8ab1243 AC |
10 | .SH LIBRARY |
11 | Math library | |
8fc3b2cf | 12 | .RI ( libm ", " \-lm ) |
fea681da MK |
13 | .SH SYNOPSIS |
14 | .nf | |
15 | .B #include <math.h> | |
68e4db0a | 16 | .PP |
fea681da | 17 | .BI "double round(double " x ); |
fea681da | 18 | .BI "float roundf(float " x ); |
fea681da MK |
19 | .BI "long double roundl(long double " x ); |
20 | .fi | |
68e4db0a | 21 | .PP |
d39ad78f | 22 | .RS -4 |
cc4615cc MK |
23 | Feature Test Macro Requirements for glibc (see |
24 | .BR feature_test_macros (7)): | |
d39ad78f | 25 | .RE |
68e4db0a | 26 | .PP |
cc4615cc MK |
27 | .BR round (), |
28 | .BR roundf (), | |
29 | .BR roundl (): | |
9d2adbae | 30 | .nf |
5c10d2c5 | 31 | _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
9d2adbae | 32 | .fi |
fea681da | 33 | .SH DESCRIPTION |
022671eb MK |
34 | These functions round |
35 | .I x | |
36 | to the nearest integer, but | |
fea681da | 37 | round halfway cases away from zero (regardless of the current rounding |
5dcc3b66 MK |
38 | direction, see |
39 | .BR fenv (3)), | |
40 | instead of to the nearest even integer like | |
fb186734 | 41 | .BR rint (3). |
847e0d88 | 42 | .PP |
2601c2d4 | 43 | For example, |
1ae6b2c7 | 44 | .I round(0.5) |
2601c2d4 | 45 | is 1.0, and |
1ae6b2c7 | 46 | .I round(\-0.5) |
2601c2d4 | 47 | is \-1.0. |
47297adb | 48 | .SH RETURN VALUE |
2601c2d4 | 49 | These functions return the rounded integer value. |
847e0d88 | 50 | .PP |
022671eb MK |
51 | If |
52 | .I x | |
61eaa189 | 53 | is integral, +0, \-0, NaN, or infinite, |
022671eb MK |
54 | .I x |
55 | itself is returned. | |
fea681da | 56 | .SH ERRORS |
2601c2d4 | 57 | No errors occur. |
efe294cb | 58 | POSIX.1-2001 documents a range error for overflows, but see NOTES. |
f0d7ce1d MK |
59 | .SH VERSIONS |
60 | These functions first appeared in glibc in version 2.1. | |
7836c64d | 61 | .SH ATTRIBUTES |
da0228a1 PH |
62 | For an explanation of the terms used in this section, see |
63 | .BR attributes (7). | |
c466875e MK |
64 | .ad l |
65 | .nh | |
da0228a1 PH |
66 | .TS |
67 | allbox; | |
c466875e | 68 | lbx lb lb |
da0228a1 PH |
69 | l l l. |
70 | Interface Attribute Value | |
71 | T{ | |
7836c64d | 72 | .BR round (), |
ed21d749 | 73 | .BR roundf (), |
7836c64d | 74 | .BR roundl () |
da0228a1 PH |
75 | T} Thread safety MT-Safe |
76 | .TE | |
c466875e MK |
77 | .hy |
78 | .ad | |
79 | .sp 1 | |
3113c7f3 | 80 | .SH STANDARDS |
9a74e018 | 81 | C99, POSIX.1-2001, POSIX.1-2008. |
fea681da | 82 | .SH NOTES |
68e1685c | 83 | POSIX.1-2001 contains text about overflow (which might set |
fea681da | 84 | .I errno |
2f0af33b MK |
85 | to |
86 | .BR ERANGE , | |
2601c2d4 MK |
87 | or raise an |
88 | .B FE_OVERFLOW | |
89 | exception). | |
fea681da MK |
90 | In practice, the result cannot overflow on any current machine, |
91 | so this error-handling stuff is just nonsense. | |
2601c2d4 | 92 | .\" The POSIX.1-2001 APPLICATION USAGE SECTION discusses this point. |
fea681da MK |
93 | (More precisely, overflow can happen only when the maximum value |
94 | of the exponent is smaller than the number of mantissa bits. | |
2601c2d4 | 95 | For the IEEE-754 standard 32-bit and 64-bit floating-point numbers |
24e0e193 AC |
96 | the maximum value of the exponent is 127 (respectively, 1023), |
97 | and the number of mantissa bits | |
98 | including the implicit bit | |
99 | is 24 (respectively, 53).) | |
847e0d88 | 100 | .PP |
2601c2d4 MK |
101 | If you want to store the rounded value in an integer type, |
102 | you probably want to use one of the functions described in | |
103 | .BR lround (3) | |
104 | instead. | |
47297adb | 105 | .SH SEE ALSO |
fea681da MK |
106 | .BR ceil (3), |
107 | .BR floor (3), | |
108 | .BR lround (3), | |
109 | .BR nearbyint (3), | |
110 | .BR rint (3), | |
111 | .BR trunc (3) |