.TH "div()" "" "" "General Function (libc)"
.PC "Perform integer division"
.B "#include <stdlib.h>"
\fBdiv_t div(\fInumerator\^\fB, \fIdenominator\^\fB)\fR
\fBint \fInumerator\^\fB, \fIdenominator\^\fB;\fR
.PP
.II div_t
.II "division, integer"
.II "integer division"
.B div()
divides
.I numerator
by
.IR denominator .
It returns a structure of the type
.BR div_t ,
which is structured as follows:
.DM
	typedef struct {
		int quot;
		int rem;
	} div_t;
.DE
.PP
.B div()
writes the quotient into
.B quot
and the remainder into
.BR rem .
.PP
The sign of the quotient is positive if the signs of the arguments are
the same; it is negative if the signs of the arguments differ.
The sign of the remainder is the same as the sign of the numerator.
.PP
If the remainder is non-zero, the magnitude of the quotient is the
largest integer less than the magnitude of the algebraic quotient.
This is not guaranteed by the operators
.B /
and
.BR % ,
which merely do what the machine implements for divide.
.SH "See Also"
.Xr "ldiv()," ldiv
.Xr "libc," libc
.Xr "stdlib.h" stdlib.h
.br
\*(AS, \(sc7.10.6.2
.SH Notes
The \*(AS includes this function to permit a useful feature found in
most versions of FORTRAN, where the sign of the remainder will be the
same as the sign of the numerator.
Also, on most machines, division produces a remainder.
This allows a quotient and remainder to be returned from one
machine-divide operation.
.PP
If the result of division cannot be represented (e.g., because
.I denominator
is set to zero), the behavior of
.B div()
is undefined.
.I "Caveat utilitor."
