1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" References consulted:
6 .\" Linux libc source code
7 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
10 .\" Modified 1993-03-29, David Metcalfe
11 .\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu)
12 .\" Modified 2002-08-10, 2003-11-01 Walter Harms, aeb
14 .TH DIV 3 2021-03-22 "" "Linux Programmer's Manual"
16 div, ldiv, lldiv, imaxdiv \- compute quotient and remainder of
20 .RI ( libc ", " \-lc )
23 .B #include <stdlib.h>
25 .BI "div_t div(int " numerator ", int " denominator );
26 .BI "ldiv_t ldiv(long " numerator ", long " denominator );
27 .BI "lldiv_t lldiv(long long " numerator ", long long " denominator );
29 .B #include <inttypes.h>
31 .BI "imaxdiv_t imaxdiv(intmax_t " numerator ", intmax_t " denominator );
35 Feature Test Macro Requirements for glibc (see
36 .BR feature_test_macros (7)):
41 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
46 function computes the value
47 \fInumerator\fP/\fIdenominator\fP and
48 returns the quotient and remainder in a structure
49 named \fIdiv_t\fP that contains
50 two integer members (in unspecified order) named \fIquot\fP and \fIrem\fP.
51 The quotient is rounded toward zero.
52 The result satisfies \fIquot\fP*\fIdenominator\fP+\fIrem\fP = \fInumerator\fP.
59 functions do the same,
60 dividing numbers of the indicated type and
61 returning the result in a structure
62 of the indicated name, in all cases with fields \fIquot\fP and \fIrem\fP
63 of the same type as the function arguments.
65 The \fIdiv_t\fP (etc.) structure.
67 For an explanation of the terms used in this section, see
75 Interface Attribute Value
81 T} Thread safety MT-Safe
87 POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
98 div_t q = div(\-5, 3);
102 the values \fIq.quot\fP and \fIq.rem\fP are \-1 and \-2, respectively.