]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/remainder.3
e9af1cb8c871bc8fbaaf9955c0a93ff9fd3fdcd8
[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 2008-07-29 "" "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.
97 .LP
98 The
99 .BR drem ()
100 function does precisely the same thing.
101 .SH "RETURN VALUE"
102 On success, these
103 functions return the floating-point remainder,
104 \fIx\fP\-\fIn\fP*\fIy\fP.
105 If the return value is 0, it has the sign of
106 .IR x .
107
108 If
109 .I x
110 or
111 .I y
112 is a NaN, a NaN is returned.
113
114 If
115 .I x
116 is an infinity,
117 and
118 .I y
119 is not a NaN,
120 a "domain error" occurs, and
121 a NaN is returned.
122
123 If
124 .I y
125 is zero,
126 .\" FIXME . Instead, glibc gives a domain error even if x is a NaN
127 and
128 .I x
129 is not a NaN,
130 .\" Interestingly, remquo(3) does not have the same problem.
131 a "domain error" occurs, and
132 a NaN is returned.
133 .SH ERRORS
134 See
135 .BR math_error (7)
136 for information on how to determine whether an error has occurred
137 when calling these functions.
138 .PP
139 The following errors can occur:
140 .TP
141 Domain error: \fIx\fP is an infinity and \fIy\fP is not a NaN
142 .\" .I errno
143 .\" is set to
144 .\" .BR EDOM .
145 An invalid floating-point exception
146 .RB ( FE_INVALID )
147 is raised.
148 .IP
149 These functions do not set
150 .IR errno
151 for this case.
152 .\" FIXME . Is it intentional that these functions do not set errno?
153 .\" They do set errno for the y == 0 case, below.
154 .\" Bug raised: http://sources.redhat.com/bugzilla/show_bug.cgi?id=6783
155 .TP
156 Domain error: \fIy\fP is zero\" [XXX see bug above] and \fIx\fP is not a NaN
157 .I errno
158 is set to
159 .BR EDOM .
160 An invalid floating-point exception
161 .RB ( FE_INVALID )
162 is raised.
163 .SH "CONFORMING TO"
164 .\" IEC 60559.
165 The functions
166 .BR remainder (),
167 .BR remainderf (),
168 and
169 .BR remainderl ()
170 are specified in C99 and POSIX.1-2001.
171
172 The function
173 .BR drem ()
174 is from 4.3BSD.
175 The
176 .I float
177 and
178 .I "long double"
179 variants
180 .BR dremf ()
181 and
182 .BR dreml ()
183 exist on some systems, such as Tru64 and glibc2.
184 Avoid the use of these functions in favor of
185 .BR remainder ()
186 etc.
187 .SH EXAMPLE
188 The call "remainder(29.0, 3.0)" returns \-1.
189 .SH BUGS
190 The call
191
192 remainder(nan(""), 0);
193
194 returns a NaN, as expected, but wrongly causes a domain error;
195 it should yield a silent NaN.
196 .\" FIXME . this bug occurs as at glibc 2.8.
197 .\" Bug raised: http://sources.redhat.com/bugzilla/show_bug.cgi?id=6779
198 .SH "SEE ALSO"
199 .BR fmod (3),
200 .BR remquo (3)