1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
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.
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.
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
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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
32 .TH DIV 3 2007-07-26 "" "Linux Programmer's Manual"
34 div, ldiv, lldiv, imaxdiv \- compute quotient and remainder of
38 .B #include <stdlib.h>
40 .BI "div_t div(int " numerator ", int " denominator );
42 .BI "ldiv_t ldiv(long " numerator ", long " denominator );
44 .BI "lldiv_t lldiv(long long " numerator ", long long " denominator );
46 .B #include <inttypes.h>
48 .BI "imaxdiv_t imaxdiv(intmax_t " numerator ", intmax_t " denominator );
52 Feature Test Macro Requirements for glibc (see
53 .BR feature_test_macros (7)):
57 _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE; or
62 function computes the value
63 \fInumerator\fP/\fIdenominator\fP and
64 returns the quotient and remainder in a structure
65 named \fIdiv_t\fP that contains
66 two integer members (in unspecified order) named \fIquot\fP and \fIrem\fP.
67 The quotient is rounded towards zero.
68 The result satisfies \fIquot\fP*\fIdenominator\fP+\fIrem\fP = \fInumerator\fP.
75 functions do the same,
76 dividing numbers of the indicated type and
77 returning the result in a structure
78 of the indicated name, in all cases with fields \fIquot\fP and \fIrem\fP
79 of the same type as the function arguments.
81 The \fIdiv_t\fP (etc.) structure.
93 div_t q = div(\-5, 3);
96 the values \fIq.quot\fP and \fIq.rem\fP are \-1 and \-2, respectively.