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