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(): _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; or
20       cc -std=c99
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

CONFORMING TO

42       C99, POSIX.1-2001.
43

NOTES

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

SEE ALSO

58       ceil(3), floor(3), lround(3), nearbyint(3), rint(3), trunc(3)
59

COLOPHON

61       This  page  is  part of release 3.25 of the Linux man-pages project.  A
62       description of the project, and information about reporting  bugs,  can
63       be found at http://www.kernel.org/doc/man-pages/.
64
65
66
67                                  2008-08-11                          ROUND(3)
Impressum