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