OSDN Git Service

c44576979110745620441b772ea18c81fa88aaad
[linuxjm/LDP_man-pages.git] / original / man3 / rint.3
1 .\" Copyright 2001 Andries Brouwer <aeb@cwi.nl>.
2 .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
3 .\"     <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
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.
14 .\"
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.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .TH RINT 3  2013-08-26 "" "Linux Programmer's Manual"
28 .SH NAME
29 nearbyint, nearbyintf, nearbyintl, rint, rintf, rintl \- round
30 to nearest integer
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
48 Link with \fI\-lm\fP.
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 ():
59 .RS 4
60 _XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L || _ISOC99_SOURCE;
61 .br
62 or
63 .I cc\ -std=c99
64 .RE
65 .br
66 .BR rint ():
67 .RS 4
68 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
69 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED || _ISOC99_SOURCE ||
70 _POSIX_C_SOURCE\ >=\ 200112L;
71 .br
72 or
73 .I cc\ -std=c99
74 .RE
75 .br
76 .BR rintf (),
77 .BR rintl ():
78 .RS 4
79 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE ||
80 _POSIX_C_SOURCE\ >=\ 200112L;
81 .br
82 or
83 .I cc\ -std=c99
84 .RE
85 .ad b
86 .SH DESCRIPTION
87 The
88 .BR nearbyint (),
89 .BR nearbyintf (),
90 and
91 .BR nearbyintl ()
92 functions round their argument to an integer value in floating-point
93 format, using the current rounding direction (see
94 .BR fesetround (3))
95 and without raising the
96 .I inexact
97 exception.
98 .LP
99 The
100 .BR rint (),
101 .BR rintf (),
102 and
103 .BR rintl ()
104 functions do the same, but will raise the
105 .I inexact
106 exception
107 .RB ( FE_INEXACT ,
108 checkable via
109 .BR fetestexcept (3))
110 when the result differs in value from the argument.
111 .SH RETURN VALUE
112 These functions return the rounded integer value.
113
114 If
115 .I x
116 is integral, +0, \-0, NaN, or infinite,
117 .I x
118 itself is returned.
119 .SH ERRORS
120 No errors occur.
121 POSIX.1-2001 documents a range error for overflows, but see NOTES.
122 .SH ATTRIBUTES
123 .SS Multithreading (see pthreads(7))
124 The
125 .BR nearbyint (),
126 .BR nearbyintf (),
127 .BR nearbyintl (),
128 .BR rint (),
129 .BR rintf (),
130 and
131 .BR rintl ()
132 functions are thread-safe.
133 .SH CONFORMING TO
134 C99, POSIX.1-2001.
135 .SH NOTES
136 SUSv2 and POSIX.1-2001 contain text about overflow (which might set
137 .I errno
138 to
139 .BR ERANGE ,
140 or raise an
141 .B FE_OVERFLOW
142 exception).
143 In practice, the result cannot overflow on any current machine,
144 so this error-handling stuff is just nonsense.
145 (More precisely, overflow can happen only when the maximum value
146 of the exponent is smaller than the number of mantissa bits.
147 For the IEEE-754 standard 32-bit and 64-bit floating-point numbers
148 the maximum value of the exponent is 128 (respectively, 1024),
149 and the number of mantissa bits is 24 (respectively, 53).)
150
151 If you want to store the rounded value in an integer type,
152 you probably want to use one of the functions described in
153 .BR lrint (3)
154 instead.
155 .SH SEE ALSO
156 .BR ceil (3),
157 .BR floor (3),
158 .BR lrint (3),
159 .BR round (3),
160 .BR trunc (3)
161 .SH COLOPHON
162 This page is part of release 3.67 of the Linux
163 .I man-pages
164 project.
165 A description of the project,
166 information about reporting bugs,
167 and the latest version of this page,
168 can be found at
169 \%http://www.kernel.org/doc/man\-pages/.