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():
23 _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE ||
24 _POSIX_C_SOURCE >= 200112L;
25 or cc -std=c99
26
28 The div() function computes the value numerator/denominator and returns
29 the quotient and remainder in a structure named div_t that contains two
30 integer members (in unspecified order) named quot and rem. The quo‐
31 tient is rounded toward zero. The result satisfies quot*denomina‐
32 tor+rem = numerator.
33
34 The ldiv(), lldiv(), and imaxdiv() functions do the same, dividing num‐
35 bers of the indicated type and returning the result in a structure of
36 the indicated name, in all cases with fields quot and rem of the same
37 type as the function arguments.
38
40 The div_t (etc.) structure.
41
43 Multithreading (see pthreads(7))
44 The div(), ldiv(), lldiv(), and imaxdiv() functions are thread-safe.
45
47 SVr4, 4.3BSD, C89. C99. The functions lldiv() and imaxdiv() were added
48 in C99.
49
51 After
52
53 div_t q = div(-5, 3);
54
55 the values q.quot and q.rem are -1 and -2, respectively.
56
58 abs(3), remainder(3)
59
61 This page is part of release 3.53 of the Linux man-pages project. A
62 description of the project, and information about reporting bugs, can
63 be found at http://www.kernel.org/doc/man-pages/.
64
65
66
67 2013-07-05 DIV(3)