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