]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/remainder.3
_exit.2, brk.2, abs.3, acos.3, acosh.3, asin.3, asinh.3, atan.3, atan2.3, atanh.3...
[thirdparty/man-pages.git] / man3 / remainder.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
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 .\" References consulted:
28 .\" Linux libc source code
29 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
30 .\" 386BSD man pages
31 .\"
32 .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
33 .\" Modified 2002-08-10 Walter Harms
34 .\" (walter.harms@informatik.uni-oldenburg.de)
35 .\" Modified 2003-11-18, 2004-10-05 aeb
36 .\"
37 .TH REMAINDER 3 2015-04-19 "" "Linux Programmer's Manual"
38 .SH NAME
39 drem, dremf, dreml, remainder, remainderf, remainderl \- \
40 floating-point remainder function
41 .SH SYNOPSIS
42 .nf
43 .B #include <math.h>
44 .sp
45 /* The C99 versions */
46 .BI "double remainder(double " x ", double " y );
47 .BI "float remainderf(float " x ", float " y );
48 .BI "long double remainderl(long double " x ", long double " y );
49 .sp
50 /* Obsolete synonyms */
51 .BI "double drem(double " x ", double " y );
52 .BI "float dremf(float " x ", float " y );
53 .BI "long double dreml(long double " x ", long double " y );
54 .sp
55 .fi
56 Link with \fI\-lm\fP.
57 .sp
58 .in -4n
59 Feature Test Macro Requirements for glibc (see
60 .BR feature_test_macros (7)):
61 .in
62 .sp
63 .ad l
64 .BR remainder ():
65 .RS 4
66 _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
67 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED ||
68 _ISOC99_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L
69 .br
70 or
71 .I cc\ -std=c99
72 .RE
73 .br
74 .BR remainderf (),
75 .BR remainderl ():
76 .RS 4
77 _BSD_SOURCE || _SVID_SOURCE || _ISOC99_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L
78 .br
79 or
80 .I cc\ -std=c99
81 .RE
82 .br
83 .BR drem (),
84 .BR dremf (),
85 .BR dreml ():
86 .RS 4
87 _SVID_SOURCE || _BSD_SOURCE
88 .RE
89 .ad b
90 .SH DESCRIPTION
91 These
92 functions compute the remainder of dividing
93 .I x
94 by
95 .IR y .
96 The return value is
97 \fIx\fP\-\fIn\fP*\fIy\fP,
98 where
99 .I n
100 is the value
101 .IR "x\ /\ y" ,
102 rounded to the nearest integer.
103 If the absolute value of
104 \fIx\fP\-\fIn\fP*\fIy\fP
105 is 0.5,
106 .I n
107 is chosen to be even.
108
109 These functions are unaffected by the current rounding mode (see
110 .BR fenv (3)).
111 .LP
112 The
113 .BR drem ()
114 function does precisely the same thing.
115 .SH RETURN VALUE
116 On success, these
117 functions return the floating-point remainder,
118 \fIx\fP\-\fIn\fP*\fIy\fP.
119 If the return value is 0, it has the sign of
120 .IR x .
121
122 If
123 .I x
124 or
125 .I y
126 is a NaN, a NaN is returned.
127
128 If
129 .I x
130 is an infinity,
131 and
132 .I y
133 is not a NaN,
134 a domain error occurs, and
135 a NaN is returned.
136
137 If
138 .I y
139 is zero,
140 .\" FIXME . Instead, glibc gives a domain error even if x is a NaN
141 and
142 .I x
143 is not a NaN,
144 .\" Interestingly, remquo(3) does not have the same problem.
145 a domain error occurs, and
146 a NaN is returned.
147 .SH ERRORS
148 See
149 .BR math_error (7)
150 for information on how to determine whether an error has occurred
151 when calling these functions.
152 .PP
153 The following errors can occur:
154 .TP
155 Domain error: \fIx\fP is an infinity and \fIy\fP is not a NaN
156 .\" .I errno
157 .\" is set to
158 .\" .BR EDOM .
159 An invalid floating-point exception
160 .RB ( FE_INVALID )
161 is raised.
162 .IP
163 These functions do not set
164 .IR errno
165 for this case.
166 .\" FIXME . Is it intentional that these functions do not set errno?
167 .\" They do set errno for the y == 0 case, below.
168 .\" Bug raised: http://sources.redhat.com/bugzilla/show_bug.cgi?id=6783
169 .TP
170 Domain error: \fIy\fP is zero\" [XXX see bug above] and \fIx\fP is not a NaN
171 .I errno
172 is set to
173 .BR EDOM .
174 An invalid floating-point exception
175 .RB ( FE_INVALID )
176 is raised.
177 .SH ATTRIBUTES
178 For an explanation of the terms used in this section, see
179 .BR attributes (7).
180 .TS
181 allbox;
182 lbw26 lb lb
183 l l l.
184 Interface Attribute Value
185 T{
186 .BR drem (),
187 .BR dremf (),
188 .BR dreml (),
189 .br
190 .BR remainder (),
191 .BR remainderf (),
192 .br
193 .BR remainderl ()
194 T} Thread safety MT-Safe
195 .TE
196 .SH CONFORMING TO
197 .\" IEC 60559.
198 The functions
199 .BR remainder (),
200 .BR remainderf (),
201 and
202 .BR remainderl ()
203 are specified in C99, POSIX.1-2001, and POSIX.1-2008.
204
205 The function
206 .BR drem ()
207 is from 4.3BSD.
208 The
209 .I float
210 and
211 .I "long double"
212 variants
213 .BR dremf ()
214 and
215 .BR dreml ()
216 exist on some systems, such as Tru64 and glibc2.
217 Avoid the use of these functions in favor of
218 .BR remainder ()
219 etc.
220 .SH BUGS
221 The call
222
223 remainder(nan(""), 0);
224
225 returns a NaN, as expected, but wrongly causes a domain error;
226 it should yield a silent NaN.
227 .\" FIXME . this bug occurs as at glibc 2.8.
228 .\" Bug raised: http://sources.redhat.com/bugzilla/show_bug.cgi?id=6779
229 .SH EXAMPLE
230 The call "remainder(29.0, 3.0)" returns \-1.
231 .SH SEE ALSO
232 .BR div (3),
233 .BR fmod (3),
234 .BR remquo (3)