]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
2 | .\" | |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
4 | .\" Permission is granted to make and distribute verbatim copies of this |
5 | .\" manual provided the copyright notice and this permission notice are | |
6 | .\" preserved on all copies. | |
7 | .\" | |
8 | .\" Permission is granted to copy and distribute modified versions of this | |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
c13182ef | 12 | .\" |
fea681da MK |
13 | .\" Since the Linux kernel and libraries are constantly changing, this |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da MK |
24 | .\" |
25 | .\" References consulted: | |
26 | .\" Linux libc source code | |
27 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
28 | .\" 386BSD man pages | |
29 | .\" | |
30 | .\" Modified 1993-03-29, David Metcalfe | |
31 | .\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu) | |
32 | .\" Modified 2002-08-10, 2003-11-01 Walter Harms, aeb | |
33 | .\" | |
97986708 | 34 | .TH DIV 3 2016-03-15 "" "Linux Programmer's Manual" |
fea681da | 35 | .SH NAME |
c13182ef | 36 | div, ldiv, lldiv, imaxdiv \- compute quotient and remainder of |
35478399 | 37 | an integer division |
fea681da MK |
38 | .SH SYNOPSIS |
39 | .nf | |
40 | .B #include <stdlib.h> | |
68e4db0a | 41 | .PP |
fea681da | 42 | .BI "div_t div(int " numerator ", int " denominator ); |
fea681da | 43 | .BI "ldiv_t ldiv(long " numerator ", long " denominator ); |
fea681da | 44 | .BI "lldiv_t lldiv(long long " numerator ", long long " denominator ); |
68e4db0a | 45 | .PP |
fea681da | 46 | .B #include <inttypes.h> |
68e4db0a | 47 | .PP |
fea681da MK |
48 | .BI "imaxdiv_t imaxdiv(intmax_t " numerator ", intmax_t " denominator ); |
49 | .fi | |
68e4db0a | 50 | .PP |
cc4615cc MK |
51 | .in -4n |
52 | Feature Test Macro Requirements for glibc (see | |
53 | .BR feature_test_macros (7)): | |
54 | .in | |
0bba23e4 | 55 | .ad l |
68e4db0a | 56 | .PP |
cc4615cc | 57 | .BR lldiv (): |
0bba23e4 | 58 | .RS 4 |
e464f054 | 59 | _ISOC99_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L |
0bba23e4 MK |
60 | .RE |
61 | .ad | |
fea681da | 62 | .SH DESCRIPTION |
60a90ecd MK |
63 | The |
64 | .BR div () | |
65 | function computes the value | |
35478399 | 66 | \fInumerator\fP/\fIdenominator\fP and |
c13182ef | 67 | returns the quotient and remainder in a structure |
35478399 | 68 | named \fIdiv_t\fP that contains |
fea681da | 69 | two integer members (in unspecified order) named \fIquot\fP and \fIrem\fP. |
5fab2e7c | 70 | The quotient is rounded toward zero. |
fea681da | 71 | The result satisfies \fIquot\fP*\fIdenominator\fP+\fIrem\fP = \fInumerator\fP. |
dd3568a1 | 72 | .PP |
60a90ecd | 73 | The |
1368e847 MK |
74 | .BR ldiv (), |
75 | .BR lldiv (), | |
60a90ecd MK |
76 | and |
77 | .BR imaxdiv () | |
78 | functions do the same, | |
c13182ef | 79 | dividing numbers of the indicated type and |
35478399 | 80 | returning the result in a structure |
fea681da MK |
81 | of the indicated name, in all cases with fields \fIquot\fP and \fIrem\fP |
82 | of the same type as the function arguments. | |
47297adb | 83 | .SH RETURN VALUE |
fea681da | 84 | The \fIdiv_t\fP (etc.) structure. |
a877cf92 | 85 | .SH ATTRIBUTES |
9f4ed48e MK |
86 | For an explanation of the terms used in this section, see |
87 | .BR attributes (7). | |
88 | .TS | |
89 | allbox; | |
90 | lbw33 lb lb | |
91 | l l l. | |
92 | Interface Attribute Value | |
93 | T{ | |
a877cf92 PH |
94 | .BR div (), |
95 | .BR ldiv (), | |
96 | .BR lldiv (), | |
a877cf92 | 97 | .BR imaxdiv () |
9f4ed48e MK |
98 | T} Thread safety MT-Safe |
99 | .TE | |
47297adb | 100 | .SH CONFORMING TO |
45e274cd | 101 | POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD. |
c13182ef MK |
102 | The functions |
103 | .BR lldiv () | |
104 | and | |
b5cc2ffb | 105 | .BR imaxdiv () |
68e1685c | 106 | were added in C99. |
2b2581ee MK |
107 | .SH EXAMPLE |
108 | After | |
207050fa MK |
109 | .PP |
110 | .in +4n | |
111 | .EX | |
112 | div_t q = div(\-5, 3); | |
113 | .EE | |
114 | .in | |
115 | .PP | |
2b2581ee | 116 | the values \fIq.quot\fP and \fIq.rem\fP are \-1 and \-2, respectively. |
47297adb | 117 | .SH SEE ALSO |
36268806 MK |
118 | .BR abs (3), |
119 | .BR remainder (3) |