1ROUND(3) Linux Programmer's Manual ROUND(3)
2
3
4
6 round, roundf, roundl - round to nearest integer, away from zero
7
9 #include <math.h>
10
11 double round(double x);
12 float roundf(float x);
13 long double roundl(long double x);
14
15 Link with -lm.
16
17 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19 round(), roundf(), roundl():
20 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
21
23 These functions round x to the nearest integer, but round halfway cases
24 away from zero (regardless of the current rounding direction, see
25 fenv(3)), instead of to the nearest even integer like rint(3).
26
27 For example, round(0.5) is 1.0, and round(-0.5) is -1.0.
28
30 These functions return the rounded integer value.
31
32 If x is integral, +0, -0, NaN, or infinite, x itself is returned.
33
35 No errors occur. POSIX.1-2001 documents a range error for overflows,
36 but see NOTES.
37
39 These functions first appeared in glibc in version 2.1.
40
42 For an explanation of the terms used in this section, see
43 attributes(7).
44
45 ┌────────────────────────────┬───────────────┬─────────┐
46 │Interface │ Attribute │ Value │
47 ├────────────────────────────┼───────────────┼─────────┤
48 │round(), roundf(), roundl() │ Thread safety │ MT-Safe │
49 └────────────────────────────┴───────────────┴─────────┘
51 C99, POSIX.1-2001, POSIX.1-2008.
52
54 POSIX.1-2001 contains text about overflow (which might set errno to
55 ERANGE, or raise an FE_OVERFLOW exception). In practice, the result
56 cannot overflow on any current machine, so this error-handling stuff is
57 just nonsense. (More precisely, overflow can happen only when the max‐
58 imum value of the exponent is smaller than the number of mantissa bits.
59 For the IEEE-754 standard 32-bit and 64-bit floating-point numbers the
60 maximum value of the exponent is 128 (respectively, 1024), and the num‐
61 ber of mantissa bits is 24 (respectively, 53).)
62
63 If you want to store the rounded value in an integer type, you probably
64 want to use one of the functions described in lround(3) instead.
65
67 ceil(3), floor(3), lround(3), nearbyint(3), rint(3), trunc(3)
68
70 This page is part of release 5.07 of the Linux man-pages project. A
71 description of the project, information about reporting bugs, and the
72 latest version of this page, can be found at
73 https://www.kernel.org/doc/man-pages/.
74
75
76
77 2017-09-15 ROUND(3)