Changes: Ready for 5.13
[man-pages.git] / man3 / div.3
blob5b4e2f17825122e9a6ce6e800f4f933e95c7aa2f
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\"
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
33 .\"
34 .TH DIV 3 2021-03-22 "" "Linux Programmer's Manual"
35 .SH NAME
36 div, ldiv, lldiv, imaxdiv \- compute quotient and remainder of
37 an integer division
38 .SH SYNOPSIS
39 .nf
40 .B #include <stdlib.h>
41 .PP
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 );
45 .PP
46 .B #include <inttypes.h>
47 .PP
48 .BI "imaxdiv_t imaxdiv(intmax_t " numerator ", intmax_t " denominator );
49 .fi
50 .PP
51 .RS -4
52 Feature Test Macro Requirements for glibc (see
53 .BR feature_test_macros (7)):
54 .RE
55 .PP
56 .BR lldiv ():
57 .nf
58     _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
59 .fi
60 .SH DESCRIPTION
61 The
62 .BR div ()
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.
70 .PP
71 The
72 .BR ldiv (),
73 .BR lldiv (),
74 and
75 .BR imaxdiv ()
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.
81 .SH RETURN VALUE
82 The \fIdiv_t\fP (etc.) structure.
83 .SH ATTRIBUTES
84 For an explanation of the terms used in this section, see
85 .BR attributes (7).
86 .ad l
87 .nh
88 .TS
89 allbox;
90 lbx lb lb
91 l l l.
92 Interface       Attribute       Value
94 .BR div (),
95 .BR ldiv (),
96 .BR lldiv (),
97 .BR imaxdiv ()
98 T}      Thread safety   MT-Safe
99 .TE
102 .sp 1
103 .SH CONFORMING TO
104 POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
105 The functions
106 .BR lldiv ()
108 .BR imaxdiv ()
109 were added in C99.
110 .SH EXAMPLES
111 After
113 .in +4n
115 div_t q = div(\-5, 3);
119 the values \fIq.quot\fP and \fIq.rem\fP are \-1 and \-2, respectively.
120 .SH SEE ALSO
121 .BR abs (3),
122 .BR remainder (3)