NAME
div(), ldiv(), lldiv(), imaxdiv() — integer division and remainder
SYNOPSIS
#include <stdlib.h>
div_t div(int numer, int denom);
ldiv_t ldiv(long int numer, long int denom);
lldiv_t lldiv(long long numer, long long denom);
#include <inttypes.h>
imaxdiv_t imaxdiv(intmax_t numer, intmax_t 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
longint
and the result is returned in a structure of type
ldiv_t
(defined in
<stdlib.h>)
having
longint
members
quot
and
rem
for the quotient and remainder respectively.
- lldiv()
Similar to
div(),
except that the arguments each have type
longlong
and the result is returned in a structure of type
lldiv_t
(defined in
<stdlib.h>)
having
longlong
members
quot
and
rem
for the quotient and remainder respectively.
- imaxdiv()
Similar to
div(),
except that the arguments each have type
intmax_t
and the result is returned in a structure of type
imaxdiv_t
(defined in
<inttypes.h>)
having
intmax_t
members
quot
and
rem
for the quotient and remainder respectively.
WARNINGS
Behavior is undefined if
denom
is zero.
STANDARDS CONFORMANCE
div(): AES, SVID3, XPG4, ANSI C
ldiv(): AES, SVID3, XPG4, ANSI C
lldiv(): ISO/IEC 9899:1999 (C99), UNIX 03
imaxdiv(): ISO/IEC 9899:1999 (C99), UNIX 03