blob: e0fe2192fd5c572918f43c4f9bf19993962e8a3b [file]
<html lang="en">
<head>
<title>ldiv - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Stdlib.html#Stdlib" title="Stdlib">
<link rel="prev" href="labs.html#labs" title="labs">
<link rel="next" href="llabs.html#llabs" title="llabs">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="ldiv"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="llabs.html#llabs">llabs</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="labs.html#labs">labs</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Stdlib.html#Stdlib">Stdlib</a>
<hr>
</div>
<h3 class="section">2.20 <code>ldiv</code>&mdash;divide two long integers</h3>
<p><a name="index-ldiv-34"></a><strong>Synopsis</strong>
<pre class="example"> #include &lt;stdlib.h&gt;
ldiv_t ldiv(long <var>n</var>, long <var>d</var>);
</pre>
<p><strong>Description</strong><br>
Divide
<var>n</var>/<var>d</var>,
returning quotient and remainder as two long integers in a structure <code>ldiv_t</code>.
<p><br>
<strong>Returns</strong><br>
The result is represented with the structure
<pre class="smallexample"> typedef struct
{
long quot;
long rem;
} ldiv_t;
</pre>
<p>where the <code>quot</code> field represents the quotient, and <code>rem</code> the
remainder. For nonzero <var>d</var>, if `<var>r</var><code> = ldiv(</code><var>n</var><code>,</code><var>d</var><code>);</code>' then
<var>n</var> equals `<var>r</var><code>.rem + </code><var>d</var><code>*</code><var>r</var><code>.quot</code>'.
<p>To divide <code>int</code> rather than <code>long</code> values, use the similar
function <code>div</code>.
<p><br>
<strong>Portability</strong><br>
<code>ldiv</code> is ANSI.
<p>No supporting OS subroutines are required.
<p><br>
</body></html>