Debian Codegraph @

upstream/debian-unstable/man3/remainder.3

raw
1 '\" t
2 .\" Copyright 1993, David Metcalfe <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH remainder 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 drem, dremf, dreml, remainder, remainderf, remainderl \- \
10 floating-point remainder function
11 .SH LIBRARY
12 Math library
13 .RI ( libm ,\~ \-lm )
14 .SH SYNOPSIS
15 .nf
16 .B #include <math.h>
17 .P
18 .BI "double remainder(double " x ", double " y );
19 .BI "float remainderf(float " x ", float " y );
20 .BI "long double remainderl(long double " x ", long double " y );
21 .P
22 /* Obsolete synonyms */
23 .BI "[[deprecated]] double drem(double " x ", double " y );
24 .BI "[[deprecated]] float dremf(float " x ", float " y );
25 .BI "[[deprecated]] long double dreml(long double " x ", long double " y );
26 .fi
27 .P
28 .RS -4
29 Feature Test Macro Requirements for glibc (see
30 .BR feature_test_macros (7)):
31 .RE
32 .P
33 .BR remainder ():
34 .nf
35 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
36 || _XOPEN_SOURCE >= 500
37 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
38 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
39 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
40 .fi
41 .P
42 .BR remainderf (),
43 .BR remainderl ():
44 .nf
45 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
46 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
47 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
48 .fi
49 .P
50 .BR drem (),
51 .BR dremf (),
52 .BR dreml ():
53 .nf
54 /* Since glibc 2.19: */ _DEFAULT_SOURCE
55 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
56 .fi
57 .SH DESCRIPTION
58 These
59 functions compute the remainder of dividing
60 .I x
61 by
62 .IR y .
63 The return value is
64 .IR x\-n*y ,
65 where
66 .I n
67 is the value
68 .IR "x\ /\ y" ,
69 rounded to the nearest integer.
70 If the absolute value of
71 .I x\-n*y
72 is 0.5,
73 .I n
74 is chosen to be even.
75 .P
76 These functions are unaffected by the current rounding mode (see
77 .BR fenv (3)).
78 .P
79 The
80 .BR drem ()
81 function does precisely the same thing.
82 .SH RETURN VALUE
83 On success, these
84 functions return the floating-point remainder,
85 .IR x\-n*y .
86 If the return value is 0, it has the sign of
87 .IR x .
88 .P
89 If
90 .I x
91 or
92 .I y
93 is a NaN, a NaN is returned.
94 .P
95 If
96 .I x
97 is an infinity,
98 and
99 .I y
100 is not a NaN,
101 a domain error occurs, and
102 a NaN is returned.
103 .P
104 If
105 .I y
106 is zero,
107 .\" FIXME . Instead, glibc gives a domain error even if x is a NaN
108 and
109 .I x
110 is not a NaN,
111 .\" Interestingly, remquo(3) does not have the same problem.
112 a domain error occurs, and
113 a NaN is returned.
114 .SH ERRORS
115 See
116 .BR math_error (7)
117 for information on how to determine whether an error has occurred
118 when calling these functions.
119 .P
120 The following errors can occur:
121 .TP
122 Domain error: \f[I]x\f[] is an infinity and \f[I]y\f[] is not a NaN
123 .I errno
124 is set to
125 .B EDOM
126 (but see BUGS).
127 An invalid floating-point exception
128 .RB ( FE_INVALID )
129 is raised.
130 .IP
131 These functions do not set
132 .I errno
133 for this case.
134 .TP
135 Domain error: \f[I]y\f[] is zero
136 .\" [XXX see bug above] and \f[I]x\f[] is not a NaN
137 .I errno
138 is set to
139 .BR EDOM .
140 An invalid floating-point exception
141 .RB ( FE_INVALID )
142 is raised.
143 .SH ATTRIBUTES
144 For an explanation of the terms used in this section, see
145 .BR attributes (7).
146 .TS
147 allbox;
148 lbx lb lb
149 l l l.
150 Interface Attribute Value
151 T{
152 .na
153 .nh
154 .BR drem (),
155 .BR dremf (),
156 .BR dreml (),
157 .BR remainder (),
158 .BR remainderf (),
159 .BR remainderl ()
160 T} Thread safety MT-Safe
161 .TE
162 .SH STANDARDS
163 .\" IEC 60559.
164 .TP
165 .BR remainder ()
166 .TQ
167 .BR remainderf ()
168 .TQ
169 .BR remainderl ()
170 C11, POSIX.1-2008.
171 .TP
172 .BR drem ()
173 .TQ
174 .BR dremf ()
175 .TQ
176 .BR dreml ()
177 None.
178 .SH HISTORY
179 .\" IEC 60559.
180 .TP
181 .BR remainder ()
182 .TQ
183 .BR remainderf ()
184 .TQ
185 .BR remainderl ()
186 C99, POSIX.1-2001.
187 .TP
188 .BR drem ()
189 4.3BSD.
190 .TP
191 .BR dremf ()
192 .TQ
193 .BR dreml ()
194 Tru64, glibc2.
195 .SH BUGS
196 Before glibc 2.15,
197 .\" https://www.sourceware.org/bugzilla/show_bug.cgi?id=6779
198 the call
199 .P
200 .in +4n
201 .EX
202 remainder(nan(""), 0);
203 .EE
204 .in
205 .P
206 returned a NaN, as expected, but wrongly caused a domain error.
207 Since glibc 2.15, a silent NaN (i.e., no domain error) is returned.
208 .P
209 Before glibc 2.15,
210 .\" https://www.sourceware.org/bugzilla/show_bug.cgi?id=6783
211 .I errno
212 was not set to
213 .B EDOM
214 for the domain error that occurs when
215 .I x
216 is an infinity and
217 .I y
218 is not a NaN.
219 .SH EXAMPLES
220 The call "remainder(29.0, 3.0)" returns \-1.
221 .SH SEE ALSO
222 .BR div (3),
223 .BR fmod (3),
224 .BR remquo (3)