]>
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 | .\" |
93015253 | 5 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
6 | .\" Permission is granted to make and distribute verbatim copies of this |
7 | .\" manual provided the copyright notice and this permission notice are | |
8 | .\" preserved on all copies. | |
9 | .\" | |
10 | .\" Permission is granted to copy and distribute modified versions of this | |
11 | .\" manual under the conditions for verbatim copying, provided that the | |
12 | .\" entire resulting derived work is distributed under the terms of a | |
13 | .\" permission notice identical to this one. | |
c13182ef | 14 | .\" |
fea681da MK |
15 | .\" Since the Linux kernel and libraries are constantly changing, this |
16 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
17 | .\" responsibility for errors or omissions, or for damages resulting from | |
18 | .\" the use of the information contained herein. The author(s) may not | |
19 | .\" have taken the same level of care in the production of this manual, | |
20 | .\" which is licensed free of charge, as they might when working | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
fea681da MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 25 | .\" %%%LICENSE_END |
fea681da | 26 | .\" |
50831f9b | 27 | .TH RINT 3 2010-09-20 "" "Linux Programmer's Manual" |
fea681da | 28 | .SH NAME |
2517f764 MK |
29 | nearbyint, nearbyintf, nearbyintl, rint, rintf, rintl \- round |
30 | to nearest integer | |
fea681da MK |
31 | .SH SYNOPSIS |
32 | .nf | |
33 | .B #include <math.h> | |
34 | .sp | |
35 | .BI "double nearbyint(double " x ); | |
36 | .br | |
37 | .BI "float nearbyintf(float " x ); | |
38 | .br | |
39 | .BI "long double nearbyintl(long double " x ); | |
40 | .sp | |
41 | .BI "double rint(double " x ); | |
42 | .br | |
43 | .BI "float rintf(float " x ); | |
44 | .br | |
45 | .BI "long double rintl(long double " x ); | |
46 | .fi | |
47 | .sp | |
20c58d70 | 48 | Link with \fI\-lm\fP. |
cc4615cc MK |
49 | .sp |
50 | .in -4n | |
51 | Feature Test Macro Requirements for glibc (see | |
52 | .BR feature_test_macros (7)): | |
53 | .in | |
54 | .sp | |
55 | .ad l | |
56 | .BR nearbyint (), | |
57 | .BR nearbyintf (), | |
58 | .BR nearbyintl (): | |
27311437 | 59 | .RS 4 |
98dbe7af | 60 | _XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L || _ISOC99_SOURCE; |
27311437 MK |
61 | .br |
62 | or | |
cc4615cc | 63 | .I cc\ -std=c99 |
27311437 | 64 | .RE |
cc4615cc | 65 | .br |
2517f764 | 66 | .BR rint (): |
27311437 MK |
67 | .RS 4 |
68 | _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 || | |
69 | _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED || _ISOC99_SOURCE || | |
98dbe7af | 70 | _POSIX_C_SOURCE\ >=\ 200112L; |
27311437 MK |
71 | .br |
72 | or | |
2517f764 | 73 | .I cc\ -std=c99 |
27311437 | 74 | .RE |
2517f764 | 75 | .br |
cc4615cc MK |
76 | .BR rintf (), |
77 | .BR rintl (): | |
27311437 MK |
78 | .RS 4 |
79 | _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE || | |
98dbe7af | 80 | _POSIX_C_SOURCE\ >=\ 200112L; |
27311437 MK |
81 | .br |
82 | or | |
cc4615cc | 83 | .I cc\ -std=c99 |
27311437 | 84 | .RE |
cc4615cc | 85 | .ad b |
fea681da MK |
86 | .SH DESCRIPTION |
87 | The | |
e511ffb6 | 88 | .BR nearbyint () |
2517f764 MK |
89 | functions round their argument to an integer value in floating-point |
90 | format, using the current rounding direction (see | |
91 | .BR fesetround (3)) | |
92 | and without raising the | |
fea681da MK |
93 | .I inexact |
94 | exception. | |
95 | .LP | |
96 | The | |
e511ffb6 | 97 | .BR rint () |
fea681da MK |
98 | functions do the same, but will raise the |
99 | .I inexact | |
2517f764 MK |
100 | exception |
101 | .RB ( FE_INEXACT , | |
102 | checkable via | |
103 | .BR fetestexcept (3)) | |
104 | when the result differs in value from the argument. | |
47297adb | 105 | .SH RETURN VALUE |
2517f764 MK |
106 | These functions return the rounded integer value. |
107 | ||
108 | If \fIx\fP is integral, +0, \-0, NaN, or infinite, | |
fea681da MK |
109 | \fIx\fP itself is returned. |
110 | .SH ERRORS | |
2517f764 | 111 | No errors occur. |
efe294cb | 112 | POSIX.1-2001 documents a range error for overflows, but see NOTES. |
47297adb | 113 | .SH CONFORMING TO |
2517f764 | 114 | C99, POSIX.1-2001. |
fea681da | 115 | .SH NOTES |
68e1685c | 116 | SUSv2 and POSIX.1-2001 contain text about overflow (which might set |
fea681da | 117 | .I errno |
2f0af33b MK |
118 | to |
119 | .BR ERANGE , | |
2517f764 MK |
120 | or raise an |
121 | .B FE_OVERFLOW | |
122 | exception). | |
fea681da MK |
123 | In practice, the result cannot overflow on any current machine, |
124 | so this error-handling stuff is just nonsense. | |
125 | (More precisely, overflow can happen only when the maximum value | |
126 | of the exponent is smaller than the number of mantissa bits. | |
2517f764 MK |
127 | For the IEEE-754 standard 32-bit and 64-bit floating-point numbers |
128 | the maximum value of the exponent is 128 (respectively, 1024), | |
129 | and the number of mantissa bits is 24 (respectively, 53).) | |
130 | ||
131 | If you want to store the rounded value in an integer type, | |
132 | you probably want to use one of the functions described in | |
133 | .BR lrint (3) | |
134 | instead. | |
47297adb | 135 | .SH SEE ALSO |
fea681da MK |
136 | .BR ceil (3), |
137 | .BR floor (3), | |
138 | .BR lrint (3), | |
fea681da MK |
139 | .BR round (3), |
140 | .BR trunc (3) |