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