]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/div.3
97d19334e58f431327c41a98adf6e91e975fcc21
[thirdparty/man-pages.git] / man3 / div.3
1 '\" t
2 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .\" References consulted:
7 .\" Linux libc source code
8 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
9 .\" 386BSD man pages
10 .\"
11 .\" Modified 1993-03-29, David Metcalfe
12 .\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu)
13 .\" Modified 2002-08-10, 2003-11-01 Walter Harms, aeb
14 .\"
15 .TH div 3 (date) "Linux man-pages (unreleased)"
16 .SH NAME
17 div, ldiv, lldiv, imaxdiv \- compute quotient and remainder of
18 an integer division
19 .SH LIBRARY
20 Standard C library
21 .RI ( libc ", " \-lc )
22 .SH SYNOPSIS
23 .nf
24 .B #include <stdlib.h>
25 .PP
26 .BI "div_t div(int " numerator ", int " denominator );
27 .BI "ldiv_t ldiv(long " numerator ", long " denominator );
28 .BI "lldiv_t lldiv(long long " numerator ", long long " denominator );
29 .PP
30 .B #include <inttypes.h>
31 .PP
32 .BI "imaxdiv_t imaxdiv(intmax_t " numerator ", intmax_t " denominator );
33 .fi
34 .PP
35 .RS -4
36 Feature Test Macro Requirements for glibc (see
37 .BR feature_test_macros (7)):
38 .RE
39 .PP
40 .BR lldiv ():
41 .nf
42 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
43 .fi
44 .SH DESCRIPTION
45 The
46 .BR div ()
47 function computes the value
48 \fInumerator\fP/\fIdenominator\fP and
49 returns the quotient and remainder in a structure
50 named \fIdiv_t\fP that contains
51 two integer members (in unspecified order) named \fIquot\fP and \fIrem\fP.
52 The quotient is rounded toward zero.
53 The result satisfies \fIquot\fP*\fIdenominator\fP+\fIrem\fP = \fInumerator\fP.
54 .PP
55 The
56 .BR ldiv (),
57 .BR lldiv (),
58 and
59 .BR imaxdiv ()
60 functions do the same,
61 dividing numbers of the indicated type and
62 returning the result in a structure
63 of the indicated name, in all cases with fields \fIquot\fP and \fIrem\fP
64 of the same type as the function arguments.
65 .SH RETURN VALUE
66 The \fIdiv_t\fP (etc.) structure.
67 .SH ATTRIBUTES
68 For an explanation of the terms used in this section, see
69 .BR attributes (7).
70 .ad l
71 .nh
72 .TS
73 allbox;
74 lbx lb lb
75 l l l.
76 Interface Attribute Value
77 T{
78 .BR div (),
79 .BR ldiv (),
80 .BR lldiv (),
81 .BR imaxdiv ()
82 T} Thread safety MT-Safe
83 .TE
84 .hy
85 .ad
86 .sp 1
87 .SH STANDARDS
88 C11, POSIX.1-2008.
89 .SH HISTORY
90 POSIX.1-2001, C89, C99, SVr4, 4.3BSD.
91 .PP
92 .BR lldiv ()
93 and
94 .BR imaxdiv ()
95 were added in C99.
96 .SH EXAMPLES
97 After
98 .PP
99 .in +4n
100 .EX
101 div_t q = div(\-5, 3);
102 .EE
103 .in
104 .PP
105 the values \fIq.quot\fP and \fIq.rem\fP are \-1 and \-2, respectively.
106 .SH SEE ALSO
107 .BR abs (3),
108 .BR remainder (3)