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

NAME

6       nearbyint,  nearbyintf, nearbyintl, rint, rintf, rintl - round to near‐
7       est integer
8

LIBRARY

10       Math library (libm, -lm)
11

SYNOPSIS

13       #include <math.h>
14
15       double nearbyint(double x);
16       float nearbyintf(float x);
17       long double nearbyintl(long double x);
18
19       double rint(double x);
20       float rintf(float x);
21       long double rintl(long double x);
22
23   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
24
25       nearbyint(), nearbyintf(), nearbyintl():
26           _POSIX_C_SOURCE >= 200112L || _ISOC99_SOURCE
27
28       rint():
29           _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
30               || _XOPEN_SOURCE >= 500
31               || /* Since glibc 2.19: */ _DEFAULT_SOURCE
32               || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
33
34       rintf(), rintl():
35           _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
36               || /* Since glibc 2.19: */ _DEFAULT_SOURCE
37               || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
38

DESCRIPTION

40       The nearbyint(), nearbyintf(), and nearbyintl() functions  round  their
41       argument  to  an integer value in floating-point format, using the cur‐
42       rent rounding direction (see fesetround(3)) and without raising the in‐
43       exact  exception.   When  the current rounding direction is to nearest,
44       these functions round halfway cases to the even integer  in  accordance
45       with IEEE-754.
46
47       The  rint(), rintf(), and rintl() functions do the same, but will raise
48       the inexact exception (FE_INEXACT, checkable via fetestexcept(3))  when
49       the result differs in value from the argument.
50

RETURN VALUE

52       These functions return the rounded integer value.
53
54       If x is integral, +0, -0, NaN, or infinite, x itself is returned.
55

ERRORS

57       No  errors  occur.  POSIX.1-2001 documents a range error for overflows,
58       but see NOTES.
59

ATTRIBUTES

61       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
62       tributes(7).
63
64       ┌────────────────────────────────────────────┬───────────────┬─────────┐
65Interface                                   Attribute     Value   
66       ├────────────────────────────────────────────┼───────────────┼─────────┤
67nearbyint(), nearbyintf(), nearbyintl(),    │ Thread safety │ MT-Safe │
68rint(), rintf(), rintl()                    │               │         │
69       └────────────────────────────────────────────┴───────────────┴─────────┘
70

STANDARDS

72       C11, POSIX.1-2008.
73

HISTORY

75       C99, POSIX.1-2001.
76

NOTES

78       SUSv2 and POSIX.1-2001 contain text about overflow (which might set er‐
79       rno  to  ERANGE,  or raise an FE_OVERFLOW exception).  In practice, the
80       result cannot overflow on any current machine, so  this  error-handling
81       stuff is just nonsense.  (More precisely, overflow can happen only when
82       the maximum value of the exponent is smaller than the number of mantis‐
83       sa  bits.   For  the IEEE-754 standard 32-bit and 64-bit floating-point
84       numbers the maximum value of the exponent is 127 (respectively,  1023),
85       and  the  number of mantissa bits including the implicit bit is 24 (re‐
86       spectively, 53).)
87
88       If you want to store the rounded value in an integer type, you probably
89       want to use one of the functions described in lrint(3) instead.
90

SEE ALSO

92       ceil(3), floor(3), lrint(3), round(3), trunc(3)
93
94
95
96Linux man-pages 6.04              2023-03-30                           rint(3)
Impressum