]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/rint.3
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir...
[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 2010-09-20 "" "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 functions round their argument to an integer value in floating-point
90 format, using the current rounding direction (see
91 .BR fesetround (3))
92 and without raising the
93 .I inexact
94 exception.
95 .LP
96 The
97 .BR rint ()
98 functions do the same, but will raise the
99 .I inexact
100 exception
101 .RB ( FE_INEXACT ,
102 checkable via
103 .BR fetestexcept (3))
104 when the result differs in value from the argument.
105 .SH RETURN VALUE
106 These functions return the rounded integer value.
107
108 If \fIx\fP is integral, +0, \-0, NaN, or infinite,
109 \fIx\fP 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 CONFORMING TO
114 C99, POSIX.1-2001.
115 .SH NOTES
116 SUSv2 and POSIX.1-2001 contain text about overflow (which might set
117 .I errno
118 to
119 .BR ERANGE ,
120 or raise an
121 .B FE_OVERFLOW
122 exception).
123 In practice, the result cannot overflow on any current machine,
124 so this error-handling stuff is just nonsense.
125 (More precisely, overflow can happen only when the maximum value
126 of the exponent is smaller than the number of mantissa bits.
127 For the IEEE-754 standard 32-bit and 64-bit floating-point numbers
128 the maximum value of the exponent is 128 (respectively, 1024),
129 and the number of mantissa bits is 24 (respectively, 53).)
130
131 If you want to store the rounded value in an integer type,
132 you probably want to use one of the functions described in
133 .BR lrint (3)
134 instead.
135 .SH SEE ALSO
136 .BR ceil (3),
137 .BR floor (3),
138 .BR lrint (3),
139 .BR round (3),
140 .BR trunc (3)