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

NAME

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

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

ATTRIBUTES

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

CONFORMING TO

71       C99, POSIX.1-2001, POSIX.1-2008.
72

NOTES

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

SEE ALSO

87       ceil(3), floor(3), lrint(3), round(3), trunc(3)
88

COLOPHON

90       This page is part of release 5.13 of the Linux  man-pages  project.   A
91       description  of  the project, information about reporting bugs, and the
92       latest    version    of    this    page,    can     be     found     at
93       https://www.kernel.org/doc/man-pages/.
94
95
96
97                                  2021-03-22                           RINT(3)
Impressum