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