1DIV(3)                     Linux Programmer's Manual                    DIV(3)
2
3
4

NAME

6       div,  ldiv, lldiv, imaxdiv - compute quotient and remainder of an inte‐
7       ger division
8

SYNOPSIS

10       #include <stdlib.h>
11
12       div_t div(int numerator, int denominator);
13       ldiv_t ldiv(long numerator, long denominator);
14       lldiv_t lldiv(long long numerator, long long denominator);
15
16       #include <inttypes.h>
17
18       imaxdiv_t imaxdiv(intmax_t numerator, intmax_t denominator);
19

DESCRIPTION

21       The div() function computes the value numerator/denominator and returns
22       the quotient and remainder in a structure named div_t that contains two
23       integer members (in unspecified order) named quot and  rem.   The  quo‐
24       tient  is  rounded  towards  zero.  The result satisfies quot*denomina‐
25       tor+rem = numerator.
26
27       The ldiv() and lldiv() and imaxdiv() functions do  the  same,  dividing
28       numbers  of  the indicated type and returning the result in a structure
29       of the indicated name, in all cases with fields quot  and  rem  of  the
30       same type as the function arguments.
31

RETURN VALUE

33       The div_t (etc.) structure.
34

EXAMPLE

36       After
37               div_t q = div(-5, 3);
38       the values q.quot and q.rem are -1 and -2, respectively.
39

CONFORMING TO

41       SVr4,  4.3BSD,  C89.  The functions lldiv() and imaxdiv() were added in
42       C99.
43

SEE ALSO

45       abs(3), remainder(3)
46
47
48
49                                  2003-11-01                            DIV(3)
Impressum