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
20   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21
22       lldiv():
23           _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
24

DESCRIPTION

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

RETURN VALUE

38       The div_t (etc.) structure.
39

ATTRIBUTES

41       For   an   explanation   of   the  terms  used  in  this  section,  see
42       attributes(7).
43
44       ┌──────────────────────────────────┬───────────────┬─────────┐
45Interface                         Attribute     Value   
46       ├──────────────────────────────────┼───────────────┼─────────┤
47div(), ldiv(), lldiv(), imaxdiv() │ Thread safety │ MT-Safe │
48       └──────────────────────────────────┴───────────────┴─────────┘

CONFORMING TO

50       POSIX.1-2001, POSIX.1-2008, C89,  C99,  SVr4,  4.3BSD.   The  functions
51       lldiv() and imaxdiv() were added in C99.
52

EXAMPLE

54       After
55
56           div_t q = div(-5, 3);
57
58       the values q.quot and q.rem are -1 and -2, respectively.
59

SEE ALSO

61       abs(3), remainder(3)
62

COLOPHON

64       This  page  is  part of release 4.15 of the Linux man-pages project.  A
65       description of the project, information about reporting bugs,  and  the
66       latest     version     of     this    page,    can    be    found    at
67       https://www.kernel.org/doc/man-pages/.
68
69
70
71                                  2016-03-15                            DIV(3)
Impressum