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