1round(3) Library Functions Manual round(3)
2
3
4
6 round, roundf, roundl - round to nearest integer, away from zero
7
9 Math library (libm, -lm)
10
12 #include <math.h>
13
14 double round(double x);
15 float roundf(float x);
16 long double roundl(long double x);
17
18 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20 round(), roundf(), roundl():
21 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
22
24 These functions round x to the nearest integer, but round halfway cases
25 away from zero (regardless of the current rounding direction, see
26 fenv(3)), instead of to the nearest even integer like rint(3).
27
28 For example, round(0.5) is 1.0, and round(-0.5) is -1.0.
29
31 These functions return the rounded integer value.
32
33 If x is integral, +0, -0, NaN, or infinite, x itself is returned.
34
36 No errors occur. POSIX.1-2001 documents a range error for overflows,
37 but see NOTES.
38
40 For an explanation of the terms used in this section, see at‐
41 tributes(7).
42
43 ┌────────────────────────────────────────────┬───────────────┬─────────┐
44 │Interface │ Attribute │ Value │
45 ├────────────────────────────────────────────┼───────────────┼─────────┤
46 │round(), roundf(), roundl() │ Thread safety │ MT-Safe │
47 └────────────────────────────────────────────┴───────────────┴─────────┘
48
50 C11, POSIX.1-2008.
51
53 glibc 2.1. C99, POSIX.1-2001.
54
56 POSIX.1-2001 contains text about overflow (which might set errno to
57 ERANGE, or raise an FE_OVERFLOW exception). In practice, the result
58 cannot overflow on any current machine, so this error-handling stuff is
59 just nonsense. (More precisely, overflow can happen only when the max‐
60 imum value of the exponent is smaller than the number of mantissa bits.
61 For the IEEE-754 standard 32-bit and 64-bit floating-point numbers the
62 maximum value of the exponent is 127 (respectively, 1023), and the num‐
63 ber of mantissa bits including the implicit bit is 24 (respectively,
64 53).)
65
66 If you want to store the rounded value in an integer type, you probably
67 want to use one of the functions described in lround(3) instead.
68
70 ceil(3), floor(3), lround(3), nearbyint(3), rint(3), trunc(3)
71
72
73
74Linux man-pages 6.04 2023-03-30 round(3)