man-pages/man3/remainder.3.html
2021-03-31 01:06:50 +01:00

339 lines
6.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of REMAINDER</TITLE>
</HEAD><BODY>
<H1>REMAINDER</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
drem, dremf, dreml, remainder, remainderf, remainderl - floating-point remainder function
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/math.h">math.h</A>&gt;</B>
/* The C99 versions */
<B>double remainder(double </B><I>x</I><B>, double </B><I>y</I><B>);</B>
<B>float remainderf(float </B><I>x</I><B>, float </B><I>y</I><B>);</B>
<B>long double remainderl(long double </B><I>x</I><B>, long double </B><I>y</I><B>);</B>
/* Obsolete synonyms */
<B>double drem(double </B><I>x</I><B>, double </B><I>y</I><B>);</B>
<B>float dremf(float </B><I>x</I><B>, float </B><I>y</I><B>);</B>
<B>long double dreml(long double </B><I>x</I><B>, long double </B><I>y</I><B>);</B>
</PRE>
Link with <I>-lm</I>.
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>remainder</B>():
<DL COMPACT><DT id="1"><DD>
_ISOC99_SOURCE || _POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200112L
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;_XOPEN_SOURCE&nbsp;&gt;=&nbsp;500
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Since&nbsp;glibc&nbsp;2.19:&nbsp;*/&nbsp;_DEFAULT_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Glibc&nbsp;versions&nbsp;&lt;=&nbsp;2.19:&nbsp;*/&nbsp;_BSD_SOURCE&nbsp;||&nbsp;_SVID_SOURCE
</DL>
<BR>
<B>remainderf</B>(),
<B>remainderl</B>():
<DL COMPACT><DT id="2"><DD>
_ISOC99_SOURCE || _POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200112L
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Since&nbsp;glibc&nbsp;2.19:&nbsp;*/&nbsp;_DEFAULT_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Glibc&nbsp;versions&nbsp;&lt;=&nbsp;2.19:&nbsp;*/&nbsp;_BSD_SOURCE&nbsp;||&nbsp;_SVID_SOURCE
</DL>
<BR>
<B>drem</B>(),
<B>dremf</B>(),
<B>dreml</B>():
<DL COMPACT><DT id="3"><DD>
/* Since glibc 2.19: */ _DEFAULT_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Glibc&nbsp;versions&nbsp;&lt;=&nbsp;2.19:&nbsp;*/&nbsp;_BSD_SOURCE&nbsp;||&nbsp;_SVID_SOURCE
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
These
functions compute the remainder of dividing
<I>x</I>
by
<I>y</I>.
The return value is
<I>x</I>-<I>n</I>*<I>y</I>,
where
<I>n</I>
is the value
<I>x&nbsp;/&nbsp;y</I>,
rounded to the nearest integer.
If the absolute value of
<I>x</I>-<I>n</I>*<I>y</I>
is 0.5,
<I>n</I>
is chosen to be even.
<P>
These functions are unaffected by the current rounding mode (see
<B><A HREF="/cgi-bin/man/man2html?3+fenv">fenv</A></B>(3)).
<P>
The
<B>drem</B>()
function does precisely the same thing.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, these
functions return the floating-point remainder,
<I>x</I>-<I>n</I>*<I>y</I>.
If the return value is 0, it has the sign of
<I>x</I>.
<P>
If
<I>x</I>
or
<I>y</I>
is a NaN, a NaN is returned.
<P>
If
<I>x</I>
is an infinity,
and
<I>y</I>
is not a NaN,
a domain error occurs, and
a NaN is returned.
<P>
If
<I>y</I>
is zero,
and
<I>x</I>
is not a NaN,
a domain error occurs, and
a NaN is returned.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
See
<B><A HREF="/cgi-bin/man/man2html?7+math_error">math_error</A></B>(7)
for information on how to determine whether an error has occurred
when calling these functions.
<P>
The following errors can occur:
<DL COMPACT>
<DT id="4">Domain error: <I>x</I> is an infinity and <I>y</I> is not a NaN<DD>
<I>errno</I>
is set to
<B>EDOM</B>
(but see BUGS).
An invalid floating-point exception
(<B>FE_INVALID</B>)
is raised.
<DT id="5"><DD>
These functions do not set
<I>errno</I>
for this case.
<DT id="6">Domain error: <I>y</I> is zero<I>errno</I>
<DD>
is set to
<B>EDOM</B>.
An invalid floating-point exception
(<B>FE_INVALID</B>)
is raised.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>drem</B>(),
<B>dremf</B>(),
<B>dreml</B>(),
<BR>
<B>remainder</B>(),
<B>remainderf</B>(),
<BR>
<B>remainderl</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
The functions
<B>remainder</B>(),
<B>remainderf</B>(),
and
<B>remainderl</B>()
are specified in C99, POSIX.1-2001, and POSIX.1-2008.
<P>
The function
<B>drem</B>()
is from 4.3BSD.
The
<I>float</I>
and
<I>long double</I>
variants
<B>dremf</B>()
and
<B>dreml</B>()
exist on some systems, such as Tru64 and glibc2.
Avoid the use of these functions in favor of
<B>remainder</B>()
etc.
<A NAME="lbAI">&nbsp;</A>
<H2>BUGS</H2>
Before glibc 2.15,
the call
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;remainder(nan(&quot;&quot;),&nbsp;0);
<P>
returned a NaN, as expected, but wrongly caused a domain error.
Since glibc 2.15, a silent NaN (i.e., no domain error) is returned.
<P>
Before glibc 2.15,
<I>errno</I>
was not set to
<B>EDOM</B>
for the domain error that occurs when
<I>x</I>
is an infinity and
<I>y</I>
is not a NaN.
<A NAME="lbAJ">&nbsp;</A>
<H2>EXAMPLE</H2>
The call &quot;remainder(29.0, 3.0)&quot; returns -1.
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+div">div</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+fmod">fmod</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+remquo">remquo</A></B>(3)
<A NAME="lbAL">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="7"><A HREF="#lbAB">NAME</A><DD>
<DT id="8"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="9"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="10"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="11"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="12"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="13"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="14"><A HREF="#lbAI">BUGS</A><DD>
<DT id="15"><A HREF="#lbAJ">EXAMPLE</A><DD>
<DT id="16"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="17"><A HREF="#lbAL">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:54 GMT, March 31, 2021
</BODY>
</HTML>