1ROUND(3)                   Linux Programmer's Manual                  ROUND(3)
2
3
4

NAME

6       round, roundf, roundl - round to nearest integer, away from zero
7

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

30       These functions return the rounded integer value.
31
32       If x is integral, +0, -0, NaN, or infinite, x itself is returned.
33

ERRORS

35       No  errors  occur.  POSIX.1-2001 documents a range error for overflows,
36       but see NOTES.
37

VERSIONS

39       These functions first appeared in glibc in version 2.1.
40

ATTRIBUTES

42       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
43       tributes(7).
44
45       ┌────────────────────────────────────────────┬───────────────┬─────────┐
46Interface                                   Attribute     Value   
47       ├────────────────────────────────────────────┼───────────────┼─────────┤
48round(), roundf(), roundl()                 │ Thread safety │ MT-Safe │
49       └────────────────────────────────────────────┴───────────────┴─────────┘
50

CONFORMING TO

52       C99, POSIX.1-2001, POSIX.1-2008.
53

NOTES

55       POSIX.1-2001  contains  text  about  overflow (which might set errno to
56       ERANGE, or raise an FE_OVERFLOW exception).  In  practice,  the  result
57       cannot overflow on any current machine, so this error-handling stuff is
58       just nonsense.  (More precisely, overflow can happen only when the max‐
59       imum value of the exponent is smaller than the number of mantissa bits.
60       For the IEEE-754 standard 32-bit and 64-bit floating-point numbers  the
61       maximum value of the exponent is 128 (respectively, 1024), and the num‐
62       ber of mantissa bits is 24 (respectively, 53).)
63
64       If you want to store the rounded value in an integer type, you probably
65       want to use one of the functions described in lround(3) instead.
66

SEE ALSO

68       ceil(3), floor(3), lround(3), nearbyint(3), rint(3), trunc(3)
69

COLOPHON

71       This  page  is  part of release 5.13 of the Linux man-pages project.  A
72       description of the project, information about reporting bugs,  and  the
73       latest     version     of     this    page,    can    be    found    at
74       https://www.kernel.org/doc/man-pages/.
75
76
77
78                                  2021-03-22                          ROUND(3)
Impressum