1div(3C) Standard C Library Functions div(3C)
2
3
4
6 div, ldiv, lldiv - compute the quotient and remainder
7
9 #include <stdlib.h>
10
11 div_t div(int numer, int denom);
12
13
14 ldiv_t ldiv(long int numer, long int denom);
15
16
17 lldiv_t lldiv(long long numer, long long denom);
18
19
21 The div() function computes the quotient and remainder of the division
22 of the numerator numer by the denominator denom. It provides a well-
23 defined semantics for the signed integral division and remainder opera‐
24 tions, unlike the implementation-defined semantics of the built-in
25 operations. The sign of the resulting quotient is that of the alge‐
26 braic quotient, and if the division is inexact, the magnitude of the
27 resulting quotient is the largest integer less than the magnitude of
28 the algebraic quotient. If the result cannot be represented, the
29 behavior is undefined; otherwise, quotient * denom + remainder will
30 equal numer.
31
32
33 The ldiv() and lldiv() functions are similar to div(), except that the
34 arguments and the members of the returned structure are different. The
35 ldiv() function returns a structure of type ldiv_t and has type long
36 int. The lldiv() function returns a structure of type lldiv_t and has
37 type long long.
38
40 The div() function returns a structure of type div_t, comprising both
41 the quotient and remainder:
42
43 int quot; /*quotient*/
44 int rem; /*remainder*/
45
46
47
48 The ldiv() function returns a structure of type ldiv_t and lldiv()
49 returns a structure of type lldiv_t, comprising both the quotient and
50 remainder:
51
52 long int quot; /*quotient*/
53 long int rem; /*remainder*/
54
55
57 See attributes(5) for descriptions of the following attributes:
58
59
60
61
62 ┌─────────────────────────────┬─────────────────────────────┐
63 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
64 ├─────────────────────────────┼─────────────────────────────┤
65 │Interface Stability │Standard │
66 ├─────────────────────────────┼─────────────────────────────┤
67 │MT-Level │MT-Safe │
68 └─────────────────────────────┴─────────────────────────────┘
69
71 attributes(5), standards(5)
72
73
74
75SunOS 5.11 24 Jul 2002 div(3C)