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