]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" Copyright 2001 Andries Brouwer <aeb@cwi.nl>. |
2517f764 MK |
2 | .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk |
3 | .\" <mtk.manpages@gmail.com> | |
fea681da | 4 | .\" |
5fbde956 | 5 | .\" SPDX-License-Identifier: Linux-man-pages-copyleft |
fea681da | 6 | .\" |
45186a5d | 7 | .TH RINT 3 2021-03-22 "Linux man-pages (unreleased)" |
fea681da | 8 | .SH NAME |
2517f764 MK |
9 | nearbyint, nearbyintf, nearbyintl, rint, rintf, rintl \- round |
10 | to nearest integer | |
0db35ab5 AC |
11 | .SH LIBRARY |
12 | Math library | |
8fc3b2cf | 13 | .RI ( libm ", " \-lm ) |
fea681da MK |
14 | .SH SYNOPSIS |
15 | .nf | |
16 | .B #include <math.h> | |
68e4db0a | 17 | .PP |
fea681da | 18 | .BI "double nearbyint(double " x ); |
fea681da | 19 | .BI "float nearbyintf(float " x ); |
fea681da | 20 | .BI "long double nearbyintl(long double " x ); |
68e4db0a | 21 | .PP |
fea681da | 22 | .BI "double rint(double " x ); |
fea681da | 23 | .BI "float rintf(float " x ); |
fea681da MK |
24 | .BI "long double rintl(long double " x ); |
25 | .fi | |
68e4db0a | 26 | .PP |
d39ad78f | 27 | .RS -4 |
cc4615cc MK |
28 | Feature Test Macro Requirements for glibc (see |
29 | .BR feature_test_macros (7)): | |
d39ad78f | 30 | .RE |
68e4db0a | 31 | .PP |
cc4615cc MK |
32 | .BR nearbyint (), |
33 | .BR nearbyintf (), | |
34 | .BR nearbyintl (): | |
9d2adbae | 35 | .nf |
5c10d2c5 | 36 | _POSIX_C_SOURCE >= 200112L || _ISOC99_SOURCE |
9d2adbae | 37 | .fi |
98c9347c | 38 | .PP |
2517f764 | 39 | .BR rint (): |
9d2adbae | 40 | .nf |
5c10d2c5 MK |
41 | _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
42 | || _XOPEN_SOURCE >= 500 | |
43 | .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED | |
9d2adbae MK |
44 | || /* Since glibc 2.19: */ _DEFAULT_SOURCE |
45 | || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE | |
46 | .fi | |
98c9347c | 47 | .PP |
cc4615cc MK |
48 | .BR rintf (), |
49 | .BR rintl (): | |
9d2adbae | 50 | .nf |
5c10d2c5 | 51 | _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
9d2adbae MK |
52 | || /* Since glibc 2.19: */ _DEFAULT_SOURCE |
53 | || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE | |
54 | .fi | |
fea681da MK |
55 | .SH DESCRIPTION |
56 | The | |
39ea0230 PH |
57 | .BR nearbyint (), |
58 | .BR nearbyintf (), | |
59 | and | |
60 | .BR nearbyintl () | |
2517f764 MK |
61 | functions round their argument to an integer value in floating-point |
62 | format, using the current rounding direction (see | |
63 | .BR fesetround (3)) | |
64 | and without raising the | |
fea681da | 65 | .I inexact |
6bea3242 MK |
66 | exception. |
67 | When the current rounding direction is to nearest, these | |
526c53f0 MT |
68 | functions round halfway cases to the even integer in accordance with |
69 | IEEE-754. | |
dd3568a1 | 70 | .PP |
fea681da | 71 | The |
39ea0230 PH |
72 | .BR rint (), |
73 | .BR rintf (), | |
74 | and | |
75 | .BR rintl () | |
fea681da MK |
76 | functions do the same, but will raise the |
77 | .I inexact | |
2517f764 MK |
78 | exception |
79 | .RB ( FE_INEXACT , | |
80 | checkable via | |
81 | .BR fetestexcept (3)) | |
82 | when the result differs in value from the argument. | |
47297adb | 83 | .SH RETURN VALUE |
2517f764 | 84 | These functions return the rounded integer value. |
847e0d88 | 85 | .PP |
022671eb MK |
86 | If |
87 | .I x | |
88 | is integral, +0, \-0, NaN, or infinite, | |
89 | .I x | |
90 | itself is returned. | |
fea681da | 91 | .SH ERRORS |
2517f764 | 92 | No errors occur. |
efe294cb | 93 | POSIX.1-2001 documents a range error for overflows, but see NOTES. |
36981c13 | 94 | .SH ATTRIBUTES |
dd47b706 PH |
95 | For an explanation of the terms used in this section, see |
96 | .BR attributes (7). | |
c466875e MK |
97 | .ad l |
98 | .nh | |
dd47b706 PH |
99 | .TS |
100 | allbox; | |
c466875e | 101 | lbx lb lb |
dd47b706 PH |
102 | l l l. |
103 | Interface Attribute Value | |
104 | T{ | |
36981c13 PH |
105 | .BR nearbyint (), |
106 | .BR nearbyintf (), | |
107 | .BR nearbyintl (), | |
108 | .BR rint (), | |
109 | .BR rintf (), | |
36981c13 | 110 | .BR rintl () |
dd47b706 PH |
111 | T} Thread safety MT-Safe |
112 | .TE | |
c466875e MK |
113 | .hy |
114 | .ad | |
115 | .sp 1 | |
3113c7f3 | 116 | .SH STANDARDS |
9a74e018 | 117 | C99, POSIX.1-2001, POSIX.1-2008. |
fea681da | 118 | .SH NOTES |
68e1685c | 119 | SUSv2 and POSIX.1-2001 contain text about overflow (which might set |
fea681da | 120 | .I errno |
2f0af33b MK |
121 | to |
122 | .BR ERANGE , | |
2517f764 MK |
123 | or raise an |
124 | .B FE_OVERFLOW | |
125 | exception). | |
fea681da MK |
126 | In practice, the result cannot overflow on any current machine, |
127 | so this error-handling stuff is just nonsense. | |
128 | (More precisely, overflow can happen only when the maximum value | |
129 | of the exponent is smaller than the number of mantissa bits. | |
2517f764 | 130 | For the IEEE-754 standard 32-bit and 64-bit floating-point numbers |
24e0e193 AC |
131 | the maximum value of the exponent is 127 (respectively, 1023), |
132 | and the number of mantissa bits | |
133 | including the implicit bit | |
134 | is 24 (respectively, 53).) | |
847e0d88 | 135 | .PP |
2517f764 MK |
136 | If you want to store the rounded value in an integer type, |
137 | you probably want to use one of the functions described in | |
138 | .BR lrint (3) | |
139 | instead. | |
47297adb | 140 | .SH SEE ALSO |
fea681da MK |
141 | .BR ceil (3), |
142 | .BR floor (3), | |
143 | .BR lrint (3), | |
fea681da MK |
144 | .BR round (3), |
145 | .BR trunc (3) |