OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / 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 2010-09-20 "" "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 ||
69 _POSIX_C_SOURCE\ >=\ 200112L;
70 .br
71 or
72 .I cc\ -std=c99
73 .RE
74 .br
75 .BR remainderf (),
76 .BR remainderl ():
77 .RS 4
78 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE ||
79 _POSIX_C_SOURCE\ >=\ 200112L;
80 .br
81 or
82 .I cc\ -std=c99
83 .RE
84 .br
85 .BR drem (),
86 .BR dremf (),
87 .BR dreml ():
88 .RS 4
89 _SVID_SOURCE || _BSD_SOURCE
90 .RE
91 .ad b
92 .SH DESCRIPTION
93 The
94 .BR remainder ()
95 function computes the remainder of dividing
96 .I x
97 by
98 .IR y .
99 The return value is
100 \fIx\fP\-\fIn\fP*\fIy\fP,
101 where
102 .I n
103 is the value
104 .IR "x\ /\ y" ,
105 rounded to the nearest integer.
106 If the absolute value of
107 \fIx\fP\-\fIn\fP*\fIy\fP
108 is 0.5,
109 .I n
110 is chosen to be even.
111
112 These functions are unaffected by the current rounding mode (see
113 .BR fenv (3)).
114 .LP
115 The
116 .BR drem ()
117 function does precisely the same thing.
118 .SH RETURN VALUE
119 On success, these
120 functions return the floating-point remainder,
121 \fIx\fP\-\fIn\fP*\fIy\fP.
122 If the return value is 0, it has the sign of
123 .IR x .
124
125 If
126 .I x
127 or
128 .I y
129 is a NaN, a NaN is returned.
130
131 If
132 .I x
133 is an infinity,
134 and
135 .I y
136 is not a NaN,
137 a domain error occurs, and
138 a NaN is returned.
139
140 If
141 .I y
142 is zero,
143 .\" FIXME . Instead, glibc gives a domain error even if x is a NaN
144 and
145 .I x
146 is not a NaN,
147 .\" Interestingly, remquo(3) does not have the same problem.
148 a domain error occurs, and
149 a NaN is returned.
150 .SH ERRORS
151 See
152 .BR math_error (7)
153 for information on how to determine whether an error has occurred
154 when calling these functions.
155 .PP
156 The following errors can occur:
157 .TP
158 Domain error: \fIx\fP is an infinity and \fIy\fP is not a NaN
159 .\" .I errno
160 .\" is set to
161 .\" .BR EDOM .
162 An invalid floating-point exception
163 .RB ( FE_INVALID )
164 is raised.
165 .IP
166 These functions do not set
167 .IR errno
168 for this case.
169 .\" FIXME . Is it intentional that these functions do not set errno?
170 .\" They do set errno for the y == 0 case, below.
171 .\" Bug raised: http://sources.redhat.com/bugzilla/show_bug.cgi?id=6783
172 .TP
173 Domain error: \fIy\fP is zero\" [XXX see bug above] and \fIx\fP is not a NaN
174 .I errno
175 is set to
176 .BR EDOM .
177 An invalid floating-point exception
178 .RB ( FE_INVALID )
179 is raised.
180 .SH CONFORMING TO
181 .\" IEC 60559.
182 The functions
183 .BR remainder (),
184 .BR remainderf (),
185 and
186 .BR remainderl ()
187 are specified in C99 and POSIX.1-2001.
188
189 The function
190 .BR drem ()
191 is from 4.3BSD.
192 The
193 .I float
194 and
195 .I "long double"
196 variants
197 .BR dremf ()
198 and
199 .BR dreml ()
200 exist on some systems, such as Tru64 and glibc2.
201 Avoid the use of these functions in favor of
202 .BR remainder ()
203 etc.
204 .SH BUGS
205 The call
206
207     remainder(nan(""), 0);
208
209 returns a NaN, as expected, but wrongly causes a domain error;
210 it should yield a silent NaN.
211 .\" FIXME . this bug occurs as at glibc 2.8.
212 .\" Bug raised: http://sources.redhat.com/bugzilla/show_bug.cgi?id=6779
213 .SH EXAMPLE
214 The call "remainder(29.0, 3.0)" returns \-1.
215 .SH SEE ALSO
216 .BR div (3),
217 .BR fmod (3),
218 .BR remquo (3)
219 .SH COLOPHON
220 This page is part of release 3.79 of the Linux
221 .I man-pages
222 project.
223 A description of the project,
224 information about reporting bugs,
225 and the latest version of this page,
226 can be found at
227 \%http://www.kernel.org/doc/man\-pages/.