Debian Codegraph @

upstream/debian-trixie/man3/rint.3

raw
1 '\" t
2 .\" Copyright 2001 Andries Brouwer <[email protected]>.
3 .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
4 .\" <[email protected]>
5 .\"
6 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .\"
8 .TH rint 3 2024-06-16 "Linux man-pages 6.9.1"
9 .SH NAME
10 nearbyint, nearbyintf, nearbyintl, rint, rintf, rintl \- round
11 to nearest integer
12 .SH LIBRARY
13 Math library
14 .RI ( libm ", " \-lm )
15 .SH SYNOPSIS
16 .nf
17 .B #include <math.h>
18 .P
19 .BI "double nearbyint(double " x );
20 .BI "float nearbyintf(float " x );
21 .BI "long double nearbyintl(long double " x );
22 .P
23 .BI "double rint(double " x );
24 .BI "float rintf(float " x );
25 .BI "long double rintl(long double " x );
26 .fi
27 .P
28 .RS -4
29 Feature Test Macro Requirements for glibc (see
30 .BR feature_test_macros (7)):
31 .RE
32 .P
33 .BR nearbyint (),
34 .BR nearbyintf (),
35 .BR nearbyintl ():
36 .nf
37 _POSIX_C_SOURCE >= 200112L || _ISOC99_SOURCE
38 .fi
39 .P
40 .BR rint ():
41 .nf
42 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
43 || _XOPEN_SOURCE >= 500
44 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
45 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
46 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
47 .fi
48 .P
49 .BR rintf (),
50 .BR rintl ():
51 .nf
52 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
53 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
54 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
55 .fi
56 .SH DESCRIPTION
57 The
58 .BR nearbyint (),
59 .BR nearbyintf (),
60 and
61 .BR nearbyintl ()
62 functions round their argument to an integer value in floating-point
63 format, using the current rounding direction (see
64 .BR fesetround (3))
65 and without raising the
66 .I inexact
67 exception.
68 When the current rounding direction is to nearest, these
69 functions round halfway cases to the even integer in accordance with
70 IEEE-754.
71 .P
72 The
73 .BR rint (),
74 .BR rintf (),
75 and
76 .BR rintl ()
77 functions do the same, but will raise the
78 .I inexact
79 exception
80 .RB ( FE_INEXACT ,
81 checkable via
82 .BR fetestexcept (3))
83 when the result differs in value from the argument.
84 .SH RETURN VALUE
85 These functions return the rounded integer value.
86 .P
87 If
88 .I x
89 is integral, +0, \-0, NaN, or infinite,
90 .I x
91 itself is returned.
92 .SH ERRORS
93 No errors occur.
94 .SH ATTRIBUTES
95 For an explanation of the terms used in this section, see
96 .BR attributes (7).
97 .TS
98 allbox;
99 lbx lb lb
100 l l l.
101 Interface Attribute Value
102 T{
103 .na
104 .nh
105 .BR nearbyint (),
106 .BR nearbyintf (),
107 .BR nearbyintl (),
108 .BR rint (),
109 .BR rintf (),
110 .BR rintl ()
111 T} Thread safety MT-Safe
112 .TE
113 .SH STANDARDS
114 C11, POSIX.1-2008.
115 .SH HISTORY
116 C99, POSIX.1-2001.
117 .P
118 SUSv2 and POSIX.1-2001 contain text about overflow (which might set
119 .I errno
120 to
121 .BR ERANGE ,
122 or raise an
123 .B FE_OVERFLOW
124 exception).
125 In practice, the result cannot overflow on any current machine,
126 so this error-handling stuff was just nonsense.
127 (More precisely, overflow can happen only when the maximum value
128 of the exponent is smaller than the number of mantissa bits.
129 For the IEEE-754 standard 32-bit and 64-bit floating-point numbers
130 the maximum value of the exponent is 127 (respectively, 1023),
131 and the number of mantissa bits
132 including the implicit bit
133 is 24 (respectively, 53).)
134 This was removed in POSIX.1-2008.
135 .P
136 If you want to store the rounded value in an integer type,
137 you probably want to use one of the functions described in
138 .BR lrint (3)
139 instead.
140 .SH SEE ALSO
141 .BR ceil (3),
142 .BR floor (3),
143 .BR lrint (3),
144 .BR round (3),
145 .BR trunc (3)