1DIV(3) Linux Programmer's Manual DIV(3)
2
3
4
6 div, ldiv, lldiv, imaxdiv - compute quotient and remainder of an inte‐
7 ger division
8
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
20 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21
22 lldiv(): _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; or cc -std=c99
23
25 The div() function computes the value numerator/denominator and returns
26 the quotient and remainder in a structure named div_t that contains two
27 integer members (in unspecified order) named quot and rem. The quo‐
28 tient is rounded towards zero. The result satisfies quot*denomina‐
29 tor+rem = numerator.
30
31 The ldiv(), lldiv(), and imaxdiv() functions do the same, dividing num‐
32 bers of the indicated type and returning the result in a structure of
33 the indicated name, in all cases with fields quot and rem of the same
34 type as the function arguments.
35
37 The div_t (etc.) structure.
38
40 SVr4, 4.3BSD, C89. The functions lldiv() and imaxdiv() were added in
41 C99.
42
44 After
45
46 div_t q = div(-5, 3);
47
48 the values q.quot and q.rem are -1 and -2, respectively.
49
51 abs(3), remainder(3)
52
54 This page is part of release 3.22 of the Linux man-pages project. A
55 description of the project, and information about reporting bugs, can
56 be found at http://www.kernel.org/doc/man-pages/.
57
58
59
60 2007-07-26 DIV(3)