OSDN Git Service

d6344aea2bfd713bebef9bc7fca8136fc18c2b89
[linuxjm/LDP_man-pages.git] / original / 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 .\" %%%LICENSE_START(VERBATIM)
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.
14 .\"
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.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .TH ROUND 3  2013-06-21 "" "Linux Programmer's Manual"
28 .SH NAME
29 round, roundf, roundl \- round to nearest integer, away from zero
30 .SH SYNOPSIS
31 .nf
32 .B #include <math.h>
33 .sp
34 .BI "double round(double " x );
35 .br
36 .BI "float roundf(float " x );
37 .br
38 .BI "long double roundl(long double " x );
39 .fi
40 .sp
41 Link with \fI\-lm\fP.
42 .sp
43 .in -4n
44 Feature Test Macro Requirements for glibc (see
45 .BR feature_test_macros (7)):
46 .in
47 .sp
48 .ad l
49 .BR round (),
50 .BR roundf (),
51 .BR roundl ():
52 .RS 4
53 _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE ||
54 _POSIX_C_SOURCE\ >=\ 200112L;
55 .br
56 or
57 .I cc\ -std=c99
58 .RE
59 .ad
60 .SH DESCRIPTION
61 These functions round
62 .I x
63 to the nearest integer, but
64 round halfway cases away from zero (regardless of the current rounding
65 direction, see
66 .BR fenv (3)),
67 instead of to the nearest even integer like
68 .BR rint (3).
69
70 For example,
71 .IR round(0.5)
72 is 1.0, and
73 .IR round(\-0.5)
74 is \-1.0.
75 .SH RETURN VALUE
76 These functions return the rounded integer value.
77
78 If
79 .I x
80 is integral, +0, \-0, NaN,  or infinite,
81 .I x
82 itself is returned.
83 .SH ERRORS
84 No errors occur.
85 POSIX.1-2001 documents a range error for overflows, but see NOTES.
86 .SH VERSIONS
87 These functions first appeared in glibc in version 2.1.
88 .SH ATTRIBUTES
89 .SS Multithreading (see pthreads(7))
90 The
91 .BR round (),
92 .BR roundf (),
93 and
94 .BR roundl ()
95 functions are thread-safe.
96 .SH CONFORMING TO
97 C99, POSIX.1-2001.
98 .SH NOTES
99 POSIX.1-2001 contains text about overflow (which might set
100 .I errno
101 to
102 .BR ERANGE ,
103 or raise an
104 .B FE_OVERFLOW
105 exception).
106 In practice, the result cannot overflow on any current machine,
107 so this error-handling stuff is just nonsense.
108 .\" The POSIX.1-2001 APPLICATION USAGE SECTION discusses this point.
109 (More precisely, overflow can happen only when the maximum value
110 of the exponent is smaller than the number of mantissa bits.
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).)
114
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.
119 .SH SEE ALSO
120 .BR ceil (3),
121 .BR floor (3),
122 .BR lround (3),
123 .BR nearbyint (3),
124 .BR rint (3),
125 .BR trunc (3)
126 .SH COLOPHON
127 This page is part of release 3.67 of the Linux
128 .I man-pages
129 project.
130 A description of the project,
131 information about reporting bugs,
132 and the latest version of this page,
133 can be found at
134 \%http://www.kernel.org/doc/man\-pages/.