OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / original / man3 / div.3
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 2007-07-26 "" "Linux Programmer's Manual"
33 .SH NAME
34 div, ldiv, lldiv, imaxdiv \- compute quotient and remainder of
35 an integer division
36 .SH SYNOPSIS
37 .nf
38 .B #include <stdlib.h>
39 .sp
40 .BI "div_t div(int " numerator ", int " denominator );
41 .br
42 .BI "ldiv_t ldiv(long " numerator ", long " denominator );
43 .br
44 .BI "lldiv_t lldiv(long long " numerator ", long long " denominator );
45 .sp
46 .B #include <inttypes.h>
47 .sp
48 .BI "imaxdiv_t imaxdiv(intmax_t " numerator ", intmax_t " denominator );
49 .fi
50 .sp
51 .in -4n
52 Feature Test Macro Requirements for glibc (see
53 .BR feature_test_macros (7)):
54 .in
55 .sp
56 .BR lldiv ():
57 _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE; or
58 .I cc\ -std=c99
59 .SH DESCRIPTION
60 The
61 .BR div ()
62 function computes the value
63 \fInumerator\fP/\fIdenominator\fP and
64 returns the quotient and remainder in a structure
65 named \fIdiv_t\fP that contains
66 two integer members (in unspecified order) named \fIquot\fP and \fIrem\fP.
67 The quotient is rounded towards zero.
68 The result satisfies \fIquot\fP*\fIdenominator\fP+\fIrem\fP = \fInumerator\fP.
69 .LP
70 The
71 .BR ldiv (),
72 .BR lldiv (),
73 and
74 .BR imaxdiv ()
75 functions do the same,
76 dividing numbers of the indicated type and
77 returning the result in a structure
78 of the indicated name, in all cases with fields \fIquot\fP and \fIrem\fP
79 of the same type as the function arguments.
80 .SH "RETURN VALUE"
81 The \fIdiv_t\fP (etc.) structure.
82 .SH "CONFORMING TO"
83 SVr4, 4.3BSD, C89.
84 The functions
85 .BR lldiv ()
86 and
87 .BR imaxdiv ()
88 were added in C99.
89 .SH EXAMPLE
90 After
91 .nf
92
93         div_t q = div(\-5, 3);
94
95 .fi
96 the values \fIq.quot\fP and \fIq.rem\fP are \-1 and \-2, respectively.
97 .SH "SEE ALSO"
98 .BR abs (3),
99 .BR remainder (3)