]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
2 | .\" | |
3 | .\" Permission is granted to make and distribute verbatim copies of this | |
4 | .\" manual provided the copyright notice and this permission notice are | |
5 | .\" preserved on all copies. | |
6 | .\" | |
7 | .\" Permission is granted to copy and distribute modified versions of this | |
8 | .\" manual under the conditions for verbatim copying, provided that the | |
9 | .\" entire resulting derived work is distributed under the terms of a | |
10 | .\" permission notice identical to this one. | |
c13182ef | 11 | .\" |
fea681da MK |
12 | .\" Since the Linux kernel and libraries are constantly changing, this |
13 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
14 | .\" responsibility for errors or omissions, or for damages resulting from | |
15 | .\" the use of the information contained herein. The author(s) may not | |
16 | .\" have taken the same level of care in the production of this manual, | |
17 | .\" which is licensed free of charge, as they might when working | |
18 | .\" professionally. | |
c13182ef | 19 | .\" |
fea681da MK |
20 | .\" Formatted or processed versions of this manual, if unaccompanied by |
21 | .\" the source, must acknowledge the copyright and authors of this work. | |
22 | .\" | |
23 | .\" References consulted: | |
24 | .\" Linux libc source code | |
25 | .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) | |
26 | .\" 386BSD man pages | |
27 | .\" | |
28 | .\" Modified 1993-03-29, David Metcalfe | |
29 | .\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu) | |
30 | .\" Modified 2002-08-10, 2003-11-01 Walter Harms, aeb | |
31 | .\" | |
32 | .TH DIV 3 2003-11-01 "" "Linux Programmer's Manual" | |
33 | .SH NAME | |
c13182ef | 34 | div, ldiv, lldiv, imaxdiv \- compute quotient and remainder of |
35478399 | 35 | an integer division |
fea681da MK |
36 | .SH SYNOPSIS |
37 | .nf | |
38 | .B #include <stdlib.h> | |
39 | .sp | |
40 | .BI "div_t div(int " numerator ", int " denominator ); | |
41 | .br | |
42 | .BI "ldiv_t ldiv(long " numerator ", long " denominator ); | |
43 | .br | |
44 | .BI "lldiv_t lldiv(long long " numerator ", long long " denominator ); | |
45 | .sp | |
46 | .B #include <inttypes.h> | |
47 | .sp | |
48 | .BI "imaxdiv_t imaxdiv(intmax_t " numerator ", intmax_t " denominator ); | |
49 | .fi | |
50 | .SH DESCRIPTION | |
60a90ecd MK |
51 | The |
52 | .BR div () | |
53 | function computes the value | |
35478399 | 54 | \fInumerator\fP/\fIdenominator\fP and |
c13182ef | 55 | returns the quotient and remainder in a structure |
35478399 | 56 | named \fIdiv_t\fP that contains |
fea681da MK |
57 | two integer members (in unspecified order) named \fIquot\fP and \fIrem\fP. |
58 | The quotient is rounded towards zero. | |
59 | The result satisfies \fIquot\fP*\fIdenominator\fP+\fIrem\fP = \fInumerator\fP. | |
60 | .LP | |
60a90ecd MK |
61 | The |
62 | .BR ldiv () and | |
63 | .BR lldiv () | |
64 | and | |
65 | .BR imaxdiv () | |
66 | functions do the same, | |
c13182ef | 67 | dividing numbers of the indicated type and |
35478399 | 68 | returning the result in a structure |
fea681da MK |
69 | of the indicated name, in all cases with fields \fIquot\fP and \fIrem\fP |
70 | of the same type as the function arguments. | |
71 | .SH "RETURN VALUE" | |
72 | The \fIdiv_t\fP (etc.) structure. | |
fea681da | 73 | .SH "CONFORMING TO" |
68e1685c | 74 | SVr4, 4.3BSD, C89. |
c13182ef MK |
75 | The functions |
76 | .BR lldiv () | |
77 | and | |
b5cc2ffb | 78 | .BR imaxdiv () |
68e1685c | 79 | were added in C99. |
2b2581ee MK |
80 | .SH EXAMPLE |
81 | After | |
82 | .nf | |
83 | div_t q = div(\-5, 3); | |
84 | .fi | |
85 | the values \fIq.quot\fP and \fIq.rem\fP are \-1 and \-2, respectively. | |
fea681da | 86 | .SH "SEE ALSO" |
36268806 MK |
87 | .BR abs (3), |
88 | .BR remainder (3) |