]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/round.3
share/mk/: distcheck: Run 'check' after 'build'
[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 .\" %%%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 2017-09-15 "" "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 .PP
34 .BI "double round(double " x );
35 .BI "float roundf(float " x );
36 .BI "long double roundl(long double " x );
37 .fi
38 .PP
39 Link with \fI\-lm\fP.
40 .PP
41 .in -4n
42 Feature Test Macro Requirements for glibc (see
43 .BR feature_test_macros (7)):
44 .in
45 .PP
46 .ad l
47 .BR round (),
48 .BR roundf (),
49 .BR roundl ():
50 .RS 4
51 _ISOC99_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L
52 .RE
53 .ad
54 .SH DESCRIPTION
55 These functions round
56 .I x
57 to the nearest integer, but
58 round halfway cases away from zero (regardless of the current rounding
59 direction, see
60 .BR fenv (3)),
61 instead of to the nearest even integer like
62 .BR rint (3).
63 .PP
64 For example,
65 .IR round(0.5)
66 is 1.0, and
67 .IR round(\-0.5)
68 is \-1.0.
69 .SH RETURN VALUE
70 These functions return the rounded integer value.
71 .PP
72 If
73 .I x
74 is integral, +0, \-0, NaN, or infinite,
75 .I x
76 itself is returned.
77 .SH ERRORS
78 No errors occur.
79 POSIX.1-2001 documents a range error for overflows, but see NOTES.
80 .SH VERSIONS
81 These functions first appeared in glibc in version 2.1.
82 .SH ATTRIBUTES
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{
91 .BR round (),
92 .BR roundf (),
93 .BR roundl ()
94 T} Thread safety MT-Safe
95 .TE
96 .SH CONFORMING TO
97 C99, POSIX.1-2001, POSIX.1-2008.
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 .PP
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)