xref: /minix3/lib/libc/stdlib/div.3 (revision f14fb602092e015ff630df58e17c2a9cd57d29b3)
1*f14fb602SLionel Sambuc.\"	$NetBSD: div.3,v 1.14 2011/05/03 09:36:24 wiz Exp $
22fe8fb19SBen Gras.\"
32fe8fb19SBen Gras.\" Copyright (c) 1990, 1991, 1993
42fe8fb19SBen Gras.\"	The Regents of the University of California.  All rights reserved.
52fe8fb19SBen Gras.\"
62fe8fb19SBen Gras.\" This code is derived from software contributed to Berkeley by
72fe8fb19SBen Gras.\" Chris Torek.
82fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
92fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
102fe8fb19SBen Gras.\" are met:
112fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
122fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
132fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
142fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
152fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
162fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors
172fe8fb19SBen Gras.\"    may be used to endorse or promote products derived from this software
182fe8fb19SBen Gras.\"    without specific prior written permission.
192fe8fb19SBen Gras.\"
202fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
212fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
222fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
232fe8fb19SBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
242fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
252fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
262fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
272fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
282fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
292fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
302fe8fb19SBen Gras.\" SUCH DAMAGE.
312fe8fb19SBen Gras.\"
322fe8fb19SBen Gras.\"     from: @(#)div.3	8.1 (Berkeley) 6/4/93
332fe8fb19SBen Gras.\"
34*f14fb602SLionel Sambuc.Dd April 13, 2011
352fe8fb19SBen Gras.Dt DIV 3
362fe8fb19SBen Gras.Os
372fe8fb19SBen Gras.Sh NAME
38*f14fb602SLionel Sambuc.Nm div ,
39*f14fb602SLionel Sambuc.Nm ldiv ,
40*f14fb602SLionel Sambuc.Nm lldiv ,
41*f14fb602SLionel Sambuc.Nm imaxdiv
42*f14fb602SLionel Sambuc.Nd quotient and remainder from division
432fe8fb19SBen Gras.Sh LIBRARY
442fe8fb19SBen Gras.Lb libc
452fe8fb19SBen Gras.Sh SYNOPSIS
462fe8fb19SBen Gras.In stdlib.h
472fe8fb19SBen Gras.Ft div_t
482fe8fb19SBen Gras.Fn div "int num" "int denom"
49*f14fb602SLionel Sambuc.Ft ldiv_t
50*f14fb602SLionel Sambuc.Fn ldiv "long int num" "long int denom"
51*f14fb602SLionel Sambuc.Ft lldiv_t
52*f14fb602SLionel Sambuc.Fn lldiv "long long int num" "long long int denom"
53*f14fb602SLionel Sambuc.In inttypes.h
54*f14fb602SLionel Sambuc.Ft imaxdiv_t
55*f14fb602SLionel Sambuc.Fn imaxdiv "intmax_t num" "intmax_t denom"
562fe8fb19SBen Gras.Sh DESCRIPTION
57*f14fb602SLionel SambucThese functions compute the value of
582fe8fb19SBen Gras.Fa num / denom
59*f14fb602SLionel Sambucand return the quotient and remainder in a specific divison structure.
60*f14fb602SLionel SambucThe functions differ only with respect to the type of the return value and
61*f14fb602SLionel Sambucthe parameters.
62*f14fb602SLionel Sambuc.Pp
63*f14fb602SLionel SambucThe returned structure always contains two members named
64*f14fb602SLionel Sambuc.Vt quot
652fe8fb19SBen Grasand
66*f14fb602SLionel Sambuc.Vt rem ,
67*f14fb602SLionel Sambucdenoting the quotient and the remainder.
68*f14fb602SLionel SambucThe type of these correspond with the underlying type of the function.
69*f14fb602SLionel Sambuc.Sh EXAMPLES
70*f14fb602SLionel SambucThe following example demonstrate the basic usage of the functions.
71*f14fb602SLionel Sambuc.Bd -literal -offset indent
72*f14fb602SLionel Sambucdiv_t d;
73*f14fb602SLionel Sambuc
74*f14fb602SLionel Sambucint a = 4321;
75*f14fb602SLionel Sambucint b = 1234;
76*f14fb602SLionel Sambuc
77*f14fb602SLionel Sambucd = div(a, b);
78*f14fb602SLionel Sambuc
79*f14fb602SLionel Sambuc(void)printf("%d %d\en", d.quot, d.rem);
80*f14fb602SLionel Sambuc.Ed
812fe8fb19SBen Gras.Sh SEE ALSO
82*f14fb602SLionel Sambuc.Xr fast_divide32 3 ,
832fe8fb19SBen Gras.Xr math 3 ,
842fe8fb19SBen Gras.Xr qdiv 3
852fe8fb19SBen Gras.Sh STANDARDS
86*f14fb602SLionel SambucAll described functions conform to
87*f14fb602SLionel Sambuc.St -isoC-99 .
88