1round(3)                   Library Functions Manual                   round(3)
2
3
4

NAME

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

LIBRARY

9       Math library (libm, -lm)
10

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

ATTRIBUTES

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

STANDARDS

50       C11, POSIX.1-2008.
51

HISTORY

53       glibc 2.1.  C99, POSIX.1-2001.
54

NOTES

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
60       maximum  value  of  the exponent is smaller than the number of mantissa
61       bits.  For the  IEEE-754  standard  32-bit  and  64-bit  floating-point
62       numbers  the maximum value of the exponent is 127 (respectively, 1023),
63       and the number of mantissa  bits  including  the  implicit  bit  is  24
64       (respectively, 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

SEE ALSO

70       ceil(3), floor(3), lround(3), nearbyint(3), rint(3), trunc(3)
71
72
73
74Linux man-pages 6.05              2023-07-20                          round(3)
Impressum