Debian Codegraph @

upstream/debian-unstable/man3/round.3

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