DIV(3C) DIV(3C)
div, ldiv - perform integer division
#include <stdlib.h>
div_t div (int numer, int denom);
ldiv_t ldiv (long int numer, long int denom);
div and ldiv compute the quotient and remainder resulting from the
division of the integer dividend numer by the integer divisor denom. If
the division is inexact, the quotient will be the nearest integer with
less magnitude than the algebraic quotient (e.g., div(5/2) yields 2, and
div(-5/2) yields -2).
div operates on and returns int quantities. ldiv operates on and returns
long int quantities.
Unless the result cannot be represented, div and ldiv return the result
in a structure (div_t for div, ldiv_t for ldiv) which has two integer
members: the quotient, quot, and the remainder, rem. These members are
of type int for div, and long int for ldiv.
If div or ldiv is invoked with a zero denom, the same integer divide-byzero
trap occurs as if the integer division had occurred in-line.
PPPPaaaaggggeeee 1111 [ Back ]
|