]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/div.3
share/mk/: distcheck: Run 'check' after 'build'
[thirdparty/man-pages.git] / man3 / div.3
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 2016-03-15 "" "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 .in -4n
52 Feature Test Macro Requirements for glibc (see
53 .BR feature_test_macros (7)):
54 .in
55 .ad l
56 .PP
57 .BR lldiv ():
58 .RS 4
59 _ISOC99_SOURCE || _POSIX_C_SOURCE\ >=\ 200112L
60 .RE
61 .ad
62 .SH DESCRIPTION
63 The
64 .BR div ()
65 function computes the value
66 \fInumerator\fP/\fIdenominator\fP and
67 returns the quotient and remainder in a structure
68 named \fIdiv_t\fP that contains
69 two integer members (in unspecified order) named \fIquot\fP and \fIrem\fP.
70 The quotient is rounded toward zero.
71 The result satisfies \fIquot\fP*\fIdenominator\fP+\fIrem\fP = \fInumerator\fP.
72 .PP
73 The
74 .BR ldiv (),
75 .BR lldiv (),
76 and
77 .BR imaxdiv ()
78 functions do the same,
79 dividing numbers of the indicated type and
80 returning the result in a structure
81 of the indicated name, in all cases with fields \fIquot\fP and \fIrem\fP
82 of the same type as the function arguments.
83 .SH RETURN VALUE
84 The \fIdiv_t\fP (etc.) structure.
85 .SH ATTRIBUTES
86 For an explanation of the terms used in this section, see
87 .BR attributes (7).
88 .TS
89 allbox;
90 lbw33 lb lb
91 l l l.
92 Interface Attribute Value
93 T{
94 .BR div (),
95 .BR ldiv (),
96 .BR lldiv (),
97 .BR imaxdiv ()
98 T} Thread safety MT-Safe
99 .TE
100 .SH CONFORMING TO
101 POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
102 The functions
103 .BR lldiv ()
104 and
105 .BR imaxdiv ()
106 were added in C99.
107 .SH EXAMPLE
108 After
109 .PP
110 .in +4n
111 .EX
112 div_t q = div(\-5, 3);
113 .EE
114 .in
115 .PP
116 the values \fIq.quot\fP and \fIq.rem\fP are \-1 and \-2, respectively.
117 .SH SEE ALSO
118 .BR abs (3),
119 .BR remainder (3)