div/ldiv
Syntax
#include
<stdlib.h>
div_t
div(numer,
denom)
int
numer,
denom;
ldiv_t
ldiv(numer,
denom)
long
int
numer,
denom;
Division
Defined
in
div.
c in
rts.
src
Description
Two
functions support integer division by returning
numer
divided by
de-
nom. You can use these functions
to
get both the quotient and the re-
mainder in a single operation.
6-34
• The
div
function performs integer division. The input arguments
are
integers; the function returns the quotient and the remainder in a
structure
of
type
div-t.
The structure
is
defined
as
follows:
typedef
struct
{
int
quot;
int
rem;
div_t;
/*
quotient
*/
/*
remainder
*/
• The
Idiv
function performs long integer division. The input argu-
ments
are
long integers; the function returns the quotient and the re-
mainder in a structure
of
type
Idiv-t.
The structure
is
defined
as
follows:
typedef
struct
{
long
int
quot;
long
int
rem;
ldiv-ti
/*
quotient
*/
/*
remainder
*/
If
the division produces a remainder, then the sign
of
the quotient
is
the
same
as
the algebraic quotient, and the magnitude
of
the resulting quotient
is
the largest integer
less
than the magnitude
of
the algebraic quotient.
Since ints and longs
are
equivalent types in TMS3401 0
C,
these functions
are
also equivalent
..