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