DIV(3C) SysV DIV(3C)
NAME
div, ldiv - integer division
SYNOPSIS
#include <stdlib.h>
div_t div(numer, denom)
int numer;
int denom;
ldiv_t ldiv(lnumer, ldenom)
long int lnumer;
long int ldenom;
DESCRIPTION
div computes the quotient and remainder of the division of int numer by
the int denom. It returns the quotient and remainder in the structure
div_t, which <stdlib.h> defines as
typedef struct {
int quot;
int rem;
} div_t;
If the division is inexact, the resulting quotient is the integer of
lesser magnitude that is the nearest to the algebraic quotient. If the
result cannot be represented, the behavior is undefined; otherwise,
quot * denom + rem = numer
ldiv is similar to div, except that the arguments and the members of the
returned structure (which is of type ldiv_t) all are of the type long
int.
SEE ALSO
abs(3C)
NOTE
Parts of this discussion are adapted from ANS X3.159-1989.