OSDN Git Service

1909917defeececeba8a17d1a74e7bd00553de2e
[linuxjm/LDP_man-pages.git] / original / 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 2013-07-05 "" "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 .sp
42 .BI "div_t div(int " numerator ", int " denominator );
43 .br
44 .BI "ldiv_t ldiv(long " numerator ", long " denominator );
45 .br
46 .BI "lldiv_t lldiv(long long " numerator ", long long " denominator );
47 .sp
48 .B #include <inttypes.h>
49 .sp
50 .BI "imaxdiv_t imaxdiv(intmax_t " numerator ", intmax_t " denominator );
51 .fi
52 .sp
53 .in -4n
54 Feature Test Macro Requirements for glibc (see
55 .BR feature_test_macros (7)):
56 .in
57 .ad l
58 .sp
59 .BR lldiv ():
60 .RS 4
61 _XOPEN_SOURCE\ >=\ 600 || _ISOC99_SOURCE ||
62 _POSIX_C_SOURCE\ >=\ 200112L;
63 .br
64 or
65 .I cc\ -std=c99
66 .RE
67 .ad
68 .SH DESCRIPTION
69 The
70 .BR div ()
71 function computes the value
72 \fInumerator\fP/\fIdenominator\fP and
73 returns the quotient and remainder in a structure
74 named \fIdiv_t\fP that contains
75 two integer members (in unspecified order) named \fIquot\fP and \fIrem\fP.
76 The quotient is rounded toward zero.
77 The result satisfies \fIquot\fP*\fIdenominator\fP+\fIrem\fP = \fInumerator\fP.
78 .LP
79 The
80 .BR ldiv (),
81 .BR lldiv (),
82 and
83 .BR imaxdiv ()
84 functions do the same,
85 dividing numbers of the indicated type and
86 returning the result in a structure
87 of the indicated name, in all cases with fields \fIquot\fP and \fIrem\fP
88 of the same type as the function arguments.
89 .SH RETURN VALUE
90 The \fIdiv_t\fP (etc.) structure.
91 .SH ATTRIBUTES
92 .SS Multithreading (see pthreads(7))
93 The
94 .BR div (),
95 .BR ldiv (),
96 .BR lldiv (),
97 and
98 .BR imaxdiv ()
99 functions are thread-safe.
100 .SH CONFORMING TO
101 SVr4, 4.3BSD, C89. C99.
102 The functions
103 .BR lldiv ()
104 and
105 .BR imaxdiv ()
106 were added in C99.
107 .SH EXAMPLE
108 After
109 .nf
110
111         div_t q = div(\-5, 3);
112
113 .fi
114 the values \fIq.quot\fP and \fIq.rem\fP are \-1 and \-2, respectively.
115 .SH SEE ALSO
116 .BR abs (3),
117 .BR remainder (3)
118 .SH COLOPHON
119 This page is part of release 3.67 of the Linux
120 .I man-pages
121 project.
122 A description of the project,
123 information about reporting bugs,
124 and the latest version of this page,
125 can be found at
126 \%http://www.kernel.org/doc/man\-pages/.