]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/fmod.3
man*/: srcfix (Use .P instead of .PP or .LP)
[thirdparty/man-pages.git] / man3 / fmod.3
CommitLineData
a1eaacb1 1'\" t
fea681da 2.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
1cc72c09
MK
3.\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
4.\" <mtk.manpages@gmail.com>
fea681da 5.\"
5fbde956 6.\" SPDX-License-Identifier: Linux-man-pages-copyleft
fea681da
MK
7.\"
8.\" References consulted:
9.\" Linux libc source code
10.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
11.\" 386BSD man pages
12.\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
13.\" Modified 2002-07-27 by Walter Harms
14.\" (walter.harms@informatik.uni-oldenburg.de)
15.\"
4c1c5274 16.TH fmod 3 (date) "Linux man-pages (unreleased)"
fea681da
MK
17.SH NAME
18fmod, fmodf, fmodl \- floating-point remainder function
2af19291
AC
19.SH LIBRARY
20Math library
8fc3b2cf 21.RI ( libm ", " \-lm )
fea681da
MK
22.SH SYNOPSIS
23.nf
24.B #include <math.h>
c6d039a3 25.P
fea681da 26.BI "double fmod(double " x ", double " y );
fea681da 27.BI "float fmodf(float " x ", float " y );
fea681da
MK
28.BI "long double fmodl(long double " x ", long double " y );
29.fi
c6d039a3 30.P
d39ad78f 31.RS -4
1cc72c09
MK
32Feature Test Macro Requirements for glibc (see
33.BR feature_test_macros (7)):
d39ad78f 34.RE
c6d039a3 35.P
1cc72c09
MK
36.BR fmodf (),
37.BR fmodl ():
9d2adbae 38.nf
5c10d2c5 39 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
9d2adbae 40 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
75c018a1 41 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
9d2adbae 42.fi
fea681da 43.SH DESCRIPTION
5600f73a 44These functions compute the floating-point remainder of dividing
022671eb
MK
45.I x
46by
47.IR y .
48The return value is
1ae6b2c7 49.I x
022671eb
MK
50\-
51.I n
52*
53.IR y ,
54where
55.I n
56is the quotient of
57.I x
58/
59.IR y ,
60rounded toward zero to an integer.
c6d039a3 61.P
d2f632fc
JE
62To obtain the modulus, more specifically, the Least Positive Residue,
63you will need to adjust the result from fmod like so:
c6d039a3 64.P
d2f632fc
JE
65.in +4n
66.nf
67z = fmod(x, y);
68if (z < 0)
69 z += y;
70.fi
71.in
c6d039a3 72.P
d2f632fc
JE
73An alternate way to express this is with
74.IR "fmod(fmod(x, y) + y, y)" ,
75but the second
76.BR fmod ()
77usually costs way more than the one branch.
47297adb 78.SH RETURN VALUE
1cc72c09
MK
79On success, these
80functions return the value \fIx\fP\ \-\ \fIn\fP*\fIy\fP,
022671eb
MK
81for some integer
82.IR n ,
1cc72c09
MK
83such that the returned value has the same sign as
84.I x
85and a magnitude less than the magnitude of
86.IR y .
c6d039a3 87.P
1cc72c09
MK
88If
89.I x
90or
91.I y
92is a NaN, a NaN is returned.
c6d039a3 93.P
1cc72c09
MK
94If
95.I x
385cf745 96is an infinity,
efe294cb 97a domain error occurs, and
1cc72c09 98a NaN is returned.
c6d039a3 99.P
1cc72c09
MK
100If
101.I y
102is zero,
efe294cb 103a domain error occurs, and
1cc72c09 104a NaN is returned.
c6d039a3 105.P
1cc72c09
MK
106If
107.I x
108is +0 (\-0), and
109.I y
110is not zero, +0 (\-0) is returned.
fea681da 111.SH ERRORS
1cc72c09
MK
112See
113.BR math_error (7)
114for information on how to determine whether an error has occurred
115when calling these functions.
c6d039a3 116.P
1cc72c09
MK
117The following errors can occur:
118.TP
119Domain error: \fIx\fP is an infinity
9343357b
MK
120.I errno
121is set to
1ae6b2c7 122.B EDOM
9343357b 123(but see BUGS).
1cc72c09
MK
124An invalid floating-point exception
125.RB ( FE_INVALID )
126is raised.
fea681da 127.TP
1cc72c09
MK
128Domain error: \fIy\fP is zero
129.I errno
130is set to
131.BR EDOM .
132An invalid floating-point exception
133.RB ( FE_INVALID )
134is raised.
135.\" POSIX.1 documents an optional underflow error, but AFAICT it doesn't
136.\" (can't?) occur -- mtk, Jul 2008
86576222
MS
137.SH ATTRIBUTES
138For an explanation of the terms used in this section, see
139.BR attributes (7).
140.TS
141allbox;
c466875e 142lbx lb lb
86576222
MS
143l l l.
144Interface Attribute Value
145T{
9e54434e
BR
146.na
147.nh
86576222
MS
148.BR fmod (),
149.BR fmodf (),
150.BR fmodl ()
151T} Thread safety MT-Safe
152.TE
3113c7f3 153.SH STANDARDS
4131356c
AC
154C11, POSIX.1-2008.
155.SH HISTORY
156C99, POSIX.1-2001.
c6d039a3 157.P
22cb459d
MK
158The variant returning
159.I double
160also conforms to
e0089d55 161SVr4, 4.3BSD, C89.
9343357b 162.SH BUGS
b324e17d 163Before glibc 2.10, the glibc implementation did not set
fd00f831 164.\" https://www.sourceware.org/bugzilla/show_bug.cgi?id=6784
9343357b
MK
165.I errno
166to
167.B EDOM
168when a domain error occurred for an infinite
169.IR x .
ce23e818
JE
170.SH EXAMPLES
171The call
172.I fmod(372, 360)
173returns 348.
c6d039a3 174.P
ce23e818
JE
175The call
176.I fmod(-372, 360)
177returns -12.
c6d039a3 178.P
ce23e818
JE
179The call
180.I fmod(-372, -360)
181also returns -12.
47297adb 182.SH SEE ALSO
fea681da 183.BR remainder (3)