HP-UX Reference (11i v1 05/09) - 3 Library Functions A-M (vol 6)

d
div(3C) div(3C)
NAME
div(), ldiv() - integer division and remainder
SYNOPSIS
#include <stdlib.h>
div_t div(int numer, int denom);
ldiv_t ldiv(long int numer, long int denom);
DESCRIPTION
div() Computes the quotient and remainder of the division of the numerator numer by the
denominator denom. If the division is inexact, the sign of the resulting quotient is that of
the algebraic quotient, and the magnitude of the resulting quotient is the largest integer
less than the magnitude of the algebraic quotient. If the result can be represented, the
result is returned in a structure of type
div_t (defined in <stdlib.h>) having
members quot and rem for the quotient and remainder respectively. Both members have
type
int and values such that quot × denom + rem = numer. If the result cannot be
represented, the behavior is undefined.
ldiv() Similar to div(), except that the arguments each have type long int and the result is
returned in a structure of type
ldiv_t (defined in <stdlib.h>) having long int
members quot and rem for the quotient and remainder respectively.
WARNINGS
Behavior is undefined if denom is zero.
SEE ALSO
floor(3M), thread_safety(5).
STANDARDS CONFORMANCE
div(): AES, SVID3, XPG4, ANSI C
ldiv(): AES, SVID3, XPG4, ANSI C
Section 3148 Hewlett-Packard Company 1 HP-UX 11i Version 1: September 2005