Debian Codegraph @

upstream/debian-trixie/man3/round.3

raw
1 '\" t
2 .\" Copyright 2001 Andries Brouwer <[email protected]>.
3 .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
4 .\" <[email protected]>
5 .\"
6 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .\"
8 .TH round 3 2024-06-16 "Linux man-pages 6.9.1"
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 .P
18 .BI "double round(double " x );
19 .BI "float roundf(float " x );
20 .BI "long double roundl(long double " x );
21 .fi
22 .P
23 .RS -4
24 Feature Test Macro Requirements for glibc (see
25 .BR feature_test_macros (7)):
26 .RE
27 .P
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 .P
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 .P
52 If
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 .SH ATTRIBUTES
60 For an explanation of the terms used in this section, see
61 .BR attributes (7).
62 .TS
63 allbox;
64 lbx lb lb
65 l l l.
66 Interface Attribute Value
67 T{
68 .na
69 .nh
70 .BR round (),
71 .BR roundf (),
72 .BR roundl ()
73 T} Thread safety MT-Safe
74 .TE
75 .SH STANDARDS
76 C11, POSIX.1-2008.
77 .SH HISTORY
78 glibc 2.1.
79 C99, POSIX.1-2001.
80 .P
81 POSIX.1-2001 contains text about overflow (which might set
82 .I errno
83 to
84 .BR ERANGE ,
85 or raise an
86 .B FE_OVERFLOW
87 exception).
88 In practice, the result cannot overflow on any current machine,
89 so this error-handling stuff was just nonsense.
90 .\" The POSIX.1-2001 APPLICATION USAGE SECTION discusses this point.
91 (More precisely, overflow can happen only when the maximum value
92 of the exponent is smaller than the number of mantissa bits.
93 For the IEEE-754 standard 32-bit and 64-bit floating-point numbers
94 the maximum value of the exponent is 127 (respectively, 1023),
95 and the number of mantissa bits
96 including the implicit bit
97 is 24 (respectively, 53).)
98 This was removed in POSIX.1-2008.
99 .P
100 If you want to store the rounded value in an integer type,
101 you probably want to use one of the functions described in
102 .BR lround (3)
103 instead.
104 .SH SEE ALSO
105 .BR ceil (3),
106 .BR floor (3),
107 .BR lround (3),
108 .BR nearbyint (3),
109 .BR rint (3),
110 .BR trunc (3)