1div(3)                     Library Functions Manual                     div(3)
2
3
4

NAME

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

LIBRARY

10       Standard C library (libc, -lc)
11

SYNOPSIS

13       #include <stdlib.h>
14
15       div_t div(int numerator, int denominator);
16       ldiv_t ldiv(long numerator, long denominator);
17       lldiv_t lldiv(long long numerator, long long denominator);
18
19       #include <inttypes.h>
20
21       imaxdiv_t imaxdiv(intmax_t numerator, intmax_t denominator);
22
23   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
24
25       lldiv():
26           _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
27

DESCRIPTION

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

RETURN VALUE

41       The div_t (etc.) structure.
42

ATTRIBUTES

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

STANDARDS

54       C11, POSIX.1-2008.
55

HISTORY

57       POSIX.1-2001, C89, C99, SVr4, 4.3BSD.
58
59       lldiv() and imaxdiv() were added in C99.
60

EXAMPLES

62       After
63
64           div_t q = div(-5, 3);
65
66       the values q.quot and q.rem are -1 and -2, respectively.
67

SEE ALSO

69       abs(3), remainder(3)
70
71
72
73Linux man-pages 6.05              2023-07-20                            div(3)
Impressum