]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/remainder.3
remainder.3: SEE ALSO: add div(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 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .\" References consulted:
26 .\" Linux libc source code
27 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\" 386BSD man pages
29 .\"
30 .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
31 .\" Modified 2002-08-10 Walter Harms
32 .\" (walter.harms@informatik.uni-oldenburg.de)
33 .\" Modified 2003-11-18, 2004-10-05 aeb
34 .\"
35 .TH REMAINDER 3 2009-02-04 "" "Linux Programmer's Manual"
36 .SH NAME
37 drem, dremf, dreml, remainder, remainderf, remainderl \- \
38 floating-point remainder function
39 .SH SYNOPSIS
40 .nf
41 .B #include <math.h>
42 .sp
43 /* The C99 versions */
44 .BI "double remainder(double " x ", double " y );
45 .BI "float remainderf(float " x ", float " y );
46 .BI "long double remainderl(long double " x ", long double " y );
47 .sp
48 /* Obsolete synonyms */
49 .BI "double drem(double " x ", double " y );
50 .BI "float dremf(float " x ", float " y );
51 .BI "long double dreml(long double " x ", long double " y );
52 .sp
53 .fi
54 Link with \fI\-lm\fP.
55 .sp
56 .in -4n
57 Feature Test Macro Requirements for glibc (see
58 .BR feature_test_macros (7)):
59 .in
60 .sp
61 .ad l
62 .BR remainder ():
63 _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _ISOC99_SOURCE; or
64 .I cc\ -std=c99
65 .br
66 .BR remainderf (),
67 .BR remainderl ():
68 _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE; or
69 .I cc\ -std=c99
70 .br
71 .BR drem (),
72 .BR dremf (),
73 .BR dreml ():
74 _SVID_SOURCE || _BSD_SOURCE
75 .ad b
76 .SH DESCRIPTION
77 The
78 .BR remainder ()
79 function computes the remainder of dividing
80 .I x
81 by
82 .IR y .
83 The return value is
84 \fIx\fP\-\fIn\fP*\fIy\fP,
85 where
86 .I n
87 is the value
88 .IR "x\ /\ y" ,
89 rounded to the nearest integer.
90 If the absolute value of
91 \fIx\fP\-\fIn\fP*\fIy\fP
92 is 0.5,
93 .I n
94 is chosen to be even.
95
96 These functions are unaffected by the current rounding mode (see
97 .BR fenv (3)).
98 .LP
99 The
100 .BR drem ()
101 function does precisely the same thing.
102 .SH "RETURN VALUE"
103 On success, these
104 functions return the floating-point remainder,
105 \fIx\fP\-\fIn\fP*\fIy\fP.
106 If the return value is 0, it has the sign of
107 .IR x .
108
109 If
110 .I x
111 or
112 .I y
113 is a NaN, a NaN is returned.
114
115 If
116 .I x
117 is an infinity,
118 and
119 .I y
120 is not a NaN,
121 a domain error occurs, and
122 a NaN is returned.
123
124 If
125 .I y
126 is zero,
127 .\" FIXME . Instead, glibc gives a domain error even if x is a NaN
128 and
129 .I x
130 is not a NaN,
131 .\" Interestingly, remquo(3) does not have the same problem.
132 a domain error occurs, and
133 a NaN is returned.
134 .SH ERRORS
135 See
136 .BR math_error (7)
137 for information on how to determine whether an error has occurred
138 when calling these functions.
139 .PP
140 The following errors can occur:
141 .TP
142 Domain error: \fIx\fP is an infinity and \fIy\fP is not a NaN
143 .\" .I errno
144 .\" is set to
145 .\" .BR EDOM .
146 An invalid floating-point exception
147 .RB ( FE_INVALID )
148 is raised.
149 .IP
150 These functions do not set
151 .IR errno
152 for this case.
153 .\" FIXME . Is it intentional that these functions do not set errno?
154 .\" They do set errno for the y == 0 case, below.
155 .\" Bug raised: http://sources.redhat.com/bugzilla/show_bug.cgi?id=6783
156 .TP
157 Domain error: \fIy\fP is zero\" [XXX see bug above] and \fIx\fP is not a NaN
158 .I errno
159 is set to
160 .BR EDOM .
161 An invalid floating-point exception
162 .RB ( FE_INVALID )
163 is raised.
164 .SH "CONFORMING TO"
165 .\" IEC 60559.
166 The functions
167 .BR remainder (),
168 .BR remainderf (),
169 and
170 .BR remainderl ()
171 are specified in C99 and POSIX.1-2001.
172
173 The function
174 .BR drem ()
175 is from 4.3BSD.
176 The
177 .I float
178 and
179 .I "long double"
180 variants
181 .BR dremf ()
182 and
183 .BR dreml ()
184 exist on some systems, such as Tru64 and glibc2.
185 Avoid the use of these functions in favor of
186 .BR remainder ()
187 etc.
188 .SH BUGS
189 The call
190
191 remainder(nan(""), 0);
192
193 returns a NaN, as expected, but wrongly causes a domain error;
194 it should yield a silent NaN.
195 .\" FIXME . this bug occurs as at glibc 2.8.
196 .\" Bug raised: http://sources.redhat.com/bugzilla/show_bug.cgi?id=6779
197 .SH EXAMPLE
198 The call "remainder(29.0, 3.0)" returns \-1.
199 .SH "SEE ALSO"
200 .BR div (3),
201 .BR fmod (3),
202 .BR remquo (3)