]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/div.3
Automated unformatting of parentheses using unformat_parens.sh
[thirdparty/man-pages.git] / man3 / div.3
CommitLineData
fea681da
MK
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2.\"
3.\" Permission is granted to make and distribute verbatim copies of this
4.\" manual provided the copyright notice and this permission notice are
5.\" preserved on all copies.
6.\"
7.\" Permission is granted to copy and distribute modified versions of this
8.\" manual under the conditions for verbatim copying, provided that the
9.\" entire resulting derived work is distributed under the terms of a
10.\" permission notice identical to this one.
11.\"
12.\" Since the Linux kernel and libraries are constantly changing, this
13.\" manual page may be incorrect or out-of-date. The author(s) assume no
14.\" responsibility for errors or omissions, or for damages resulting from
15.\" the use of the information contained herein. The author(s) may not
16.\" have taken the same level of care in the production of this manual,
17.\" which is licensed free of charge, as they might when working
18.\" professionally.
19.\"
20.\" Formatted or processed versions of this manual, if unaccompanied by
21.\" the source, must acknowledge the copyright and authors of this work.
22.\"
23.\" References consulted:
24.\" Linux libc source code
25.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26.\" 386BSD man pages
27.\"
28.\" Modified 1993-03-29, David Metcalfe
29.\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu)
30.\" Modified 2002-08-10, 2003-11-01 Walter Harms, aeb
31.\"
32.TH DIV 3 2003-11-01 "" "Linux Programmer's Manual"
33.SH NAME
34div, ldiv, lldiv, imaxdiv \- compute quotient and remainder of an integer division
35.SH SYNOPSIS
36.nf
37.B #include <stdlib.h>
38.sp
39.BI "div_t div(int " numerator ", int " denominator );
40.br
41.BI "ldiv_t ldiv(long " numerator ", long " denominator );
42.br
43.BI "lldiv_t lldiv(long long " numerator ", long long " denominator );
44.sp
45.B #include <inttypes.h>
46.sp
47.BI "imaxdiv_t imaxdiv(intmax_t " numerator ", intmax_t " denominator );
48.fi
49.SH DESCRIPTION
63aa9df0 50The \fBdiv\fP() function computes the value \fInumerator\fP/\fIdenominator\fP and
fea681da
MK
51returns the quotient and remainder in a structure named \fIdiv_t\fP that contains
52two integer members (in unspecified order) named \fIquot\fP and \fIrem\fP.
53The quotient is rounded towards zero.
54The result satisfies \fIquot\fP*\fIdenominator\fP+\fIrem\fP = \fInumerator\fP.
55.LP
63aa9df0 56The \fBldiv\fP() and \fBlldiv\fP() and \fBimaxdiv\fP() functions do the same,
fea681da
MK
57dividing numbers of the indicated type and returning the result in a structure
58of the indicated name, in all cases with fields \fIquot\fP and \fIrem\fP
59of the same type as the function arguments.
60.SH "RETURN VALUE"
61The \fIdiv_t\fP (etc.) structure.
62.SH EXAMPLE
63After
64.nf
2bc2f479 65 div_t q = div(\-5, 3);
fea681da
MK
66.fi
67the values \fIq.quot\fP and \fIq.rem\fP are \-1 and \-2, respectively.
68.SH "CONFORMING TO"
b14d4aa5 69SVID 3, 4.3BSD, ISO 9899.
fea681da
MK
70The functions lldiv() and imaxdiv() were added in ISO C99.
71.SH "SEE ALSO"
36268806
MK
72.BR abs (3),
73.BR remainder (3)