2 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" and Copyright 2008, Linux Foundation, written by Michael Kerrisk
4 .\" <mtk.manpages@gmail.com>
6 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
8 .\" References consulted:
9 .\" Linux libc source code
10 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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)
16 .TH fmod 3 (date) "Linux man-pages (unreleased)"
18 fmod, fmodf, fmodl \- floating-point remainder function
21 .RI ( libm ", " \-lm )
26 .BI "double fmod(double " x ", double " y );
27 .BI "float fmodf(float " x ", float " y );
28 .BI "long double fmodl(long double " x ", long double " y );
32 Feature Test Macro Requirements for glibc (see
33 .BR feature_test_macros (7)):
39 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
40 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
41 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
44 These functions compute the floating-point remainder of dividing
60 rounded toward zero to an integer.
62 To obtain the modulus, more specifically, the Least Positive Residue,
63 you will need to adjust the result from fmod like so:
73 An alternate way to express this is with
74 .IR "fmod(fmod(x, y) + y, y)" ,
77 usually costs way more than the one branch.
80 functions return the value \fIx\fP\ \-\ \fIn\fP*\fIy\fP,
83 such that the returned value has the same sign as
85 and a magnitude less than the magnitude of
92 is a NaN, a NaN is returned.
97 a domain error occurs, and
103 a domain error occurs, and
110 is not zero, +0 (\-0) is returned.
114 for information on how to determine whether an error has occurred
115 when calling these functions.
117 The following errors can occur:
119 Domain error: \fIx\fP is an infinity
124 An invalid floating-point exception
128 Domain error: \fIy\fP is zero
132 An invalid floating-point exception
135 .\" POSIX.1 documents an optional underflow error, but AFAICT it doesn't
136 .\" (can't?) occur -- mtk, Jul 2008
138 For an explanation of the terms used in this section, see
144 Interface Attribute Value
151 T} Thread safety MT-Safe
158 The variant returning
163 Before glibc 2.10, the glibc implementation did not set
164 .\" https://www.sourceware.org/bugzilla/show_bug.cgi?id=6784
168 when a domain error occurred for an infinite