]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/rint.3
_exit.2, bpf.2, cacheflush.2, capget.2, chdir.2, chmod.2, chroot.2, clock_getres...
[thirdparty/man-pages.git] / 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 2016-03-15 "" "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 .PP
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 .PP
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 .PP
48 Link with \fI\-lm\fP.
49 .PP
50 .in -4n
51 Feature Test Macro Requirements for glibc (see
52 .BR feature_test_macros (7)):
53 .in
54 .PP
55 .ad l
56 .BR nearbyint (),
57 .BR nearbyintf (),
58 .BR nearbyintl ():
59 .RS 4
60 _POSIX_C_SOURCE\ >=\ 200112L || _ISOC99_SOURCE
61 .RE
62 .br
63 .BR rint ():
64 .RS 4
65 _ISOC99_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L
66 || _XOPEN_SOURCE\ >=\ 500
67 .\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
68 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
69 || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
70 .RE
71 .br
72 .BR rintf (),
73 .BR rintl ():
74 .RS 4
75 _ISOC99_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L
76 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
77 || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
78 .RE
79 .ad b
80 .SH DESCRIPTION
81 The
82 .BR nearbyint (),
83 .BR nearbyintf (),
84 and
85 .BR nearbyintl ()
86 functions round their argument to an integer value in floating-point
87 format, using the current rounding direction (see
88 .BR fesetround (3))
89 and without raising the
90 .I inexact
91 exception.
92 When the current rounding direction is to nearest, these
93 functions round halfway cases to the even integer in accordance with
94 IEEE-754.
95 .LP
96 The
97 .BR rint (),
98 .BR rintf (),
99 and
100 .BR rintl ()
101 functions do the same, but will raise the
102 .I inexact
103 exception
104 .RB ( FE_INEXACT ,
105 checkable via
106 .BR fetestexcept (3))
107 when the result differs in value from the argument.
108 .SH RETURN VALUE
109 These functions return the rounded integer value.
110
111 If
112 .I x
113 is integral, +0, \-0, NaN, or infinite,
114 .I x
115 itself is returned.
116 .SH ERRORS
117 No errors occur.
118 POSIX.1-2001 documents a range error for overflows, but see NOTES.
119 .SH ATTRIBUTES
120 For an explanation of the terms used in this section, see
121 .BR attributes (7).
122 .TS
123 allbox;
124 lbw26 lb lb
125 l l l.
126 Interface Attribute Value
127 T{
128 .BR nearbyint (),
129 .BR nearbyintf (),
130 .br
131 .BR nearbyintl (),
132 .BR rint (),
133 .br
134 .BR rintf (),
135 .BR rintl ()
136 T} Thread safety MT-Safe
137 .TE
138 .SH CONFORMING TO
139 C99, POSIX.1-2001, POSIX.1-2008.
140 .SH NOTES
141 SUSv2 and POSIX.1-2001 contain text about overflow (which might set
142 .I errno
143 to
144 .BR ERANGE ,
145 or raise an
146 .B FE_OVERFLOW
147 exception).
148 In practice, the result cannot overflow on any current machine,
149 so this error-handling stuff is just nonsense.
150 (More precisely, overflow can happen only when the maximum value
151 of the exponent is smaller than the number of mantissa bits.
152 For the IEEE-754 standard 32-bit and 64-bit floating-point numbers
153 the maximum value of the exponent is 128 (respectively, 1024),
154 and the number of mantissa bits is 24 (respectively, 53).)
155
156 If you want to store the rounded value in an integer type,
157 you probably want to use one of the functions described in
158 .BR lrint (3)
159 instead.
160 .SH SEE ALSO
161 .BR ceil (3),
162 .BR floor (3),
163 .BR lrint (3),
164 .BR round (3),
165 .BR trunc (3)