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           _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE ||
21           _POSIX_C_SOURCE >= 200112L;
22           or cc -std=c99
23

DESCRIPTION

25       These functions round x to the nearest integer, but round halfway cases
26       away  from  zero  (regardless  of  the  current rounding direction, see
27       fenv(3)), instead of to the nearest even integer like rint(3).
28
29       For example, round(0.5) is 1.0, and round(-0.5) is -1.0.
30

RETURN VALUE

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

ERRORS

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

VERSIONS

41       These functions first appeared in glibc in version 2.1.
42

ATTRIBUTES

44   Multithreading (see pthreads(7))
45       The round(), roundf(), and roundl() functions are thread-safe.
46

CONFORMING TO

48       C99, POSIX.1-2001.
49

NOTES

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

SEE ALSO

64       ceil(3), floor(3), lround(3), nearbyint(3), rint(3), trunc(3)
65

COLOPHON

67       This  page  is  part of release 3.53 of the Linux man-pages project.  A
68       description of the project, and information about reporting  bugs,  can
69       be found at http://www.kernel.org/doc/man-pages/.
70
71
72
73                                  2013-06-21                          ROUND(3)
Impressum