1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" %%%LICENSE_START(VERBATIM)
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" References consulted:
26 .\" Linux libc source code
27 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
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
34 .TH DIV 3 2021-03-22 "" "Linux Programmer's Manual"
36 div, ldiv, lldiv, imaxdiv \- compute quotient and remainder of
40 .B #include <stdlib.h>
42 .BI "div_t div(int " numerator ", int " denominator );
43 .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)):
58 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
63 function computes the value
64 \fInumerator\fP/\fIdenominator\fP and
65 returns the quotient and remainder in a structure
66 named \fIdiv_t\fP that contains
67 two integer members (in unspecified order) named \fIquot\fP and \fIrem\fP.
68 The quotient is rounded toward zero.
69 The result satisfies \fIquot\fP*\fIdenominator\fP+\fIrem\fP = \fInumerator\fP.
76 functions do the same,
77 dividing numbers of the indicated type and
78 returning the result in a structure
79 of the indicated name, in all cases with fields \fIquot\fP and \fIrem\fP
80 of the same type as the function arguments.
82 The \fIdiv_t\fP (etc.) structure.
84 For an explanation of the terms used in this section, see
92 Interface Attribute Value
98 T} Thread safety MT-Safe
104 POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
115 div_t q = div(\-5, 3);
119 the values \fIq.quot\fP and \fIq.rem\fP are \-1 and \-2, respectively.