summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorjtc <jtc@NetBSD.org>1995-03-21 23:12:35 +0000
committerjtc <jtc@NetBSD.org>1995-03-21 23:12:35 +0000
commitbfd7fc20d9d50639a3eaa0cfab03d1ffd10e1c5e (patch)
treeee76bd6592a6cd9f97a536d4a88c9f4acc21216b /lib/libc/stdlib
parentf442fd56dc6d2f09150d9df562e1236f350a22fc (diff)
New function qdiv. Like div and ldiv, but works with quad_t's.
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/Makefile.inc8
-rw-r--r--lib/libc/stdlib/qdiv.366
-rw-r--r--lib/libc/stdlib/qdiv.c59
3 files changed, 129 insertions, 4 deletions
diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc
index 32dca196659..99b1ae9d12f 100644
--- a/lib/libc/stdlib/Makefile.inc
+++ b/lib/libc/stdlib/Makefile.inc
@@ -1,5 +1,5 @@
# from: @(#)Makefile.inc 5.6 (Berkeley) 6/4/91
-# $Id: Makefile.inc,v 1.23 1995/02/10 17:46:54 cgd Exp $
+# $Id: Makefile.inc,v 1.24 1995/03/21 23:12:35 jtc Exp $
# stdlib sources
.PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/stdlib ${.CURDIR}/stdlib
@@ -9,7 +9,7 @@ SRCS+= a64l.c abort.c atexit.c atoi.c atof.c atol.c bsearch.c calloc.c \
multibyte.c putenv.c qsort.c radixsort.c rand.c random.c realpath.c \
setenv.c strtod.c strtol.c strtoq.c strtoul.c strtouq.c system.c \
_rand48.c drand48.c erand48.c jrand48.c lcong48.c lrand48.c \
- mrand48.c nrand48.c seed48.c srand48.c
+ mrand48.c nrand48.c seed48.c srand48.c qdiv.c
.if (${MACHINE_ARCH} == "m68k")
SRCS+= abs.S div.c labs.c ldiv.c
@@ -30,8 +30,8 @@ SRCS+= abs.c div.c labs.c ldiv.c
MAN+= abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \
calloc.3 div.3 exit.3 free.3 getenv.3 getopt.3 labs.3 ldiv.3 \
- malloc.3 memory.3 qsort.3 radixsort.3 rand48.3 rand.3 random.3 \
- realloc.3 realpath.3 strtod.3 strtol.3 strtoul.3 system.3
+ malloc.3 memory.3 qdiv.3 qsort.3 radixsort.3 rand48.3 rand.3 \
+ random.3 realloc.3 realpath.3 strtod.3 strtol.3 strtoul.3 system.3
MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3
MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3
diff --git a/lib/libc/stdlib/qdiv.3 b/lib/libc/stdlib/qdiv.3
new file mode 100644
index 00000000000..bb248939b20
--- /dev/null
+++ b/lib/libc/stdlib/qdiv.3
@@ -0,0 +1,66 @@
+.\" Copyright (c) 1990, 1991 The Regents of the University of California.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" Chris Torek and the American National Standards Committee X3,
+.\" on Information Processing Systems.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" from: @(#)qdiv.3 5.3 (Berkeley) 6/29/91
+.\" $Id: qdiv.3,v 1.1 1995/03/21 23:12:37 jtc Exp $
+.\"
+.Dd June 29, 1991
+.Dt LDIV 3
+.Os
+.Sh NAME
+.Nm qdiv
+.Nd return quotient and remainder from division
+.Sh SYNOPSIS
+.Fd #include <stdlib.h>
+.Ft qdiv_t
+.Fn qdiv "quad_t num" "quad_t denom"
+.Sh DESCRIPTION
+The
+.Fn qdiv
+function
+computes the value
+.Ar num/denom
+and returns the quotient and remainder in a structure named
+.Ar qdiv_t
+that contains two
+.Em quad integer
+members named
+.Ar quot
+and
+.Ar rem .
+.Sh SEE ALSO
+.Xr div 3 ,
+.Xr ldiv 3 ,
+.Xr math 3
diff --git a/lib/libc/stdlib/qdiv.c b/lib/libc/stdlib/qdiv.c
new file mode 100644
index 00000000000..890bc42efb9
--- /dev/null
+++ b/lib/libc/stdlib/qdiv.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+/*static char *sccsid = "from: @(#)ldiv.c 5.2 (Berkeley) 4/16/91";*/
+static char *rcsid = "$Id: qdiv.c,v 1.1 1995/03/21 23:12:38 jtc Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdlib.h> /* qdiv_t */
+
+qdiv_t
+qdiv(num, denom)
+ quad_t num, denom;
+{
+ qdiv_t r;
+
+ /* see div.c for comments */
+
+ r.quot = num / denom;
+ r.rem = num % denom;
+ if (num >= 0 && r.rem < 0) {
+ r.quot++;
+ r.rem -= denom;
+ }
+ return (r);
+}