]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/round.3
update timestamp
[thirdparty/man-pages.git] / man3 / round.3
1 .\" Copyright 2001 Andries Brouwer <aeb@cwi.nl>.
2 .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
3 .\" <mtk.manpages@gmail.com>
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.
13 .\"
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.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .TH ROUND 3 2008-08-05 "" "Linux Programmer's Manual"
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
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 ():
50 _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE; or
51 .I cc\ -std=c99
52 .ad b
53 .SH DESCRIPTION
54 These functions round \fIx\fP to the nearest integer, but
55 round halfway cases away from zero (regardless of the current rounding
56 direction), instead of to the nearest even integer like
57 .BR rint (3).
58
59 For example,
60 .IR round(0.5)
61 is 1.0, and
62 .IR round(\-0.5)
63 is \-1.0.
64 .SH "RETURN VALUE"
65 These functions return the rounded integer value.
66
67 If \fIx\fP is integral, +0, \-0, NaN, or infinite,
68 \fIx\fP itself is returned.
69 .SH ERRORS
70 No errors occur.
71 POSIX.1-2001 documents a "range error" for overflows, but see NOTES.
72 .SH "CONFORMING TO"
73 C99, POSIX.1-2001.
74 .SH NOTES
75 POSIX.1-2001 contains text about overflow (which might set
76 .I errno
77 to
78 .BR ERANGE ,
79 or raise an
80 .B FE_OVERFLOW
81 exception).
82 In practice, the result cannot overflow on any current machine,
83 so this error-handling stuff is just nonsense.
84 .\" The POSIX.1-2001 APPLICATION USAGE SECTION discusses this point.
85 (More precisely, overflow can happen only when the maximum value
86 of the exponent is smaller than the number of mantissa bits.
87 For the IEEE-754 standard 32-bit and 64-bit floating-point numbers
88 the maximum value of the exponent is 128 (respectively, 1024),
89 and the number of mantissa bits is 24 (respectively, 53).)
90
91 If you want to store the rounded value in an integer type,
92 you probably want to use one of the functions described in
93 .BR lround (3)
94 instead.
95 .SH "SEE ALSO"
96 .BR ceil (3),
97 .BR floor (3),
98 .BR lround (3),
99 .BR nearbyint (3),
100 .BR rint (3),
101 .BR trunc (3)