summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorjruoho <jruoho@NetBSD.org>2011-04-13 07:12:52 +0000
committerjruoho <jruoho@NetBSD.org>2011-04-13 07:12:52 +0000
commitb9f828cf3063fd098a3e0c3c543c3cf45e1249d6 (patch)
treecb1377427746f9f144c07f1c7284195d790e4003 /lib/libc/stdlib
parentb9e32a00b03476d61f5df37d71610ee5cfe19915 (diff)
Collect also the division functions to single place, div(3).
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/Makefile.inc9
-rw-r--r--lib/libc/stdlib/div.364
-rw-r--r--lib/libc/stdlib/imaxdiv.375
-rw-r--r--lib/libc/stdlib/ldiv.373
-rw-r--r--lib/libc/stdlib/lldiv.373
5 files changed, 46 insertions, 248 deletions
diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc
index 7c29254f7e4..dab369f5f47 100644
--- a/lib/libc/stdlib/Makefile.inc
+++ b/lib/libc/stdlib/Makefile.inc
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.76 2011/04/13 06:56:50 jruoho Exp $
+# $NetBSD: Makefile.inc,v 1.77 2011/04/13 07:12:52 jruoho Exp $
# from: @(#)Makefile.inc 8.3 (Berkeley) 2/4/95
# stdlib sources
@@ -43,9 +43,9 @@ MAN+= a64l.3 abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 atoll.3 \
exit.3 \
getenv.3 getopt.3 getopt_long.3 getsubopt.3 grantpt.3 \
hcreate.3 \
- imaxdiv.3 insque.3 \
+ insque.3 \
jemalloc.3 \
- ldiv.3 lldiv.3 lsearch.3 \
+ lsearch.3 \
malloc.3 memory.3 mi_vector_hash.3 \
posix_memalign.3 posix_openpt.3 ptsname.3 \
qabs.3 qdiv.3 qsort.3 \
@@ -59,6 +59,9 @@ MLINKS+=a64l.3 l64a_r.3
MLINKS+=abs.3 labs.3 \
abs.3 llabs.3 \
abs.3 imaxabs.3
+MLINKS+=div.3 ldiv.3 \
+ div.3 lldiv.3 \
+ div.3 imaxdiv.3
MLINKS+=getenv.3 setenv.3 getenv.3 unsetenv.3 getenv.3 putenv.3
MLINKS+=getenv.3 getenv_r.3
MLINKS+=hcreate.3 hdestroy.3 hcreate.3 hsearch.3
diff --git a/lib/libc/stdlib/div.3 b/lib/libc/stdlib/div.3
index 062837d4277..6ce7d89fd7f 100644
--- a/lib/libc/stdlib/div.3
+++ b/lib/libc/stdlib/div.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: div.3,v 1.12 2008/08/04 21:29:27 matt Exp $
+.\" $NetBSD: div.3,v 1.13 2011/04/13 07:12:52 jruoho Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -31,41 +31,57 @@
.\"
.\" from: @(#)div.3 8.1 (Berkeley) 6/4/93
.\"
-.Dd June 4, 1993
+.Dd April 13, 2011
.Dt DIV 3
.Os
.Sh NAME
-.Nm div
-.Nd return quotient and remainder from division
+.Nm div ,
+.Nm ldiv ,
+.Nm lldiv ,
+.Nm imaxdiv
+.Nd quotient and remainder from division
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In stdlib.h
.Ft div_t
.Fn div "int num" "int denom"
+.Ft ldiv_t
+.Fn ldiv "long int num" "long int denom"
+.Ft lldiv_t
+.Fn lldiv "long long int num" "long long int denom"
+.In inttypes.h
+.Ft imaxdiv_t
+.Fn imaxdiv "intmax_t num" "intmax_t denom"
.Sh DESCRIPTION
-The
-.Fn div
-function
-computes the value
-.Fa num/denom
-and returns the quotient and remainder in a structure named
-.Fa div_t
-that contains two
-.Em int
-members named
-.Fa quot
+These functions compute the value of
+.Fa num / denom
+and return the quotient and remainder in a specific divison structure.
+The functions differ only with respect to the type of the return value and
+the parameters.
+.Pp
+The returned structure always contains two members named
+.Vt quot
and
-.Fa rem .
+.Vt rem ,
+denoting the quotient and the remainder.
+The type of these correspond with the underlying type of the function.
+.Sh EXAMPLES
+The following example demonstrate the basic usage of the functions.
+.Bd -literal -offset indent
+div_t d;
+
+int a = 4321;
+int b = 1234;
+
+d = div(a, b);
+
+(void)printf(\*[q]%d %d\en\*[q], d.quot, d.rem);
+.Ed
.Sh SEE ALSO
-.Xr imaxdiv 3 ,
-.Xr ldiv 3 ,
-.Xr lldiv 3 ,
+.Xr fast_divide32 3 ,
.Xr math 3 ,
.Xr qdiv 3
.Sh STANDARDS
-The
-.Fn div
-function
-conforms to
-.St -ansiC .
+All described functions conform to
+.St -isoC-99 .
diff --git a/lib/libc/stdlib/imaxdiv.3 b/lib/libc/stdlib/imaxdiv.3
deleted file mode 100644
index ebfd7f1ead5..00000000000
--- a/lib/libc/stdlib/imaxdiv.3
+++ /dev/null
@@ -1,75 +0,0 @@
-.\" $NetBSD: imaxdiv.3,v 1.1 2008/08/04 21:29:27 matt Exp $
-.\"
-.\" Copyright (c) 1990, 1991, 1993
-.\" 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. 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: @(#)ldiv.3 8.1 (Berkeley) 6/4/93
-.\"
-.Dd March 6, 2000
-.Dt IMAXDIV 3
-.Os
-.Sh NAME
-.Nm imaxdiv
-.Nd return quotient and remainder from division
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In inttypes.h
-.Ft imaxdiv_t
-.Fn imaxdiv "intmax_t num" "intmax_t denom"
-.Sh DESCRIPTION
-The
-.Fn imaxdiv
-function
-divides
-.Ar num
-by
-.Ar denom
-and returns the resulting quotient and remainder in a structure named
-.Ar imaxdiv_t
-that contains two
-.Em imaxint_t
-members named
-.Ar quot
-and
-.Ar rem .
-.Sh SEE ALSO
-.Xr div 3 ,
-.Xr ldiv 3 ,
-.Xr lldiv 3 ,
-.Xr math 3 ,
-.Xr qdiv 3
-.Sh STANDARDS
-The
-.Fn imaxdiv
-function
-conforms to
-.St -isoC-99 .
diff --git a/lib/libc/stdlib/ldiv.3 b/lib/libc/stdlib/ldiv.3
deleted file mode 100644
index 95852ce71c6..00000000000
--- a/lib/libc/stdlib/ldiv.3
+++ /dev/null
@@ -1,73 +0,0 @@
-.\" $NetBSD: ldiv.3,v 1.13 2008/08/04 21:29:27 matt Exp $
-.\"
-.\" Copyright (c) 1990, 1991, 1993
-.\" 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. 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: @(#)ldiv.3 8.1 (Berkeley) 6/4/93
-.\"
-.Dd June 4, 1993
-.Dt LDIV 3
-.Os
-.Sh NAME
-.Nm ldiv
-.Nd return quotient and remainder from division
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In stdlib.h
-.Ft ldiv_t
-.Fn ldiv "long int num" "long int denom"
-.Sh DESCRIPTION
-The
-.Fn ldiv
-function
-computes the value
-.Ar num/denom
-and returns the quotient and remainder in a structure named
-.Ar ldiv_t
-that contains two
-.Em long integer
-members named
-.Ar quot
-and
-.Ar rem .
-.Sh SEE ALSO
-.Xr div 3 ,
-.Xr imaxdiv 3 ,
-.Xr lldiv 3 ,
-.Xr math 3 ,
-.Xr qdiv 3
-.Sh STANDARDS
-The
-.Fn ldiv
-function
-conforms to
-.St -ansiC .
diff --git a/lib/libc/stdlib/lldiv.3 b/lib/libc/stdlib/lldiv.3
deleted file mode 100644
index 4d2ccb0fd77..00000000000
--- a/lib/libc/stdlib/lldiv.3
+++ /dev/null
@@ -1,73 +0,0 @@
-.\" $NetBSD: lldiv.3,v 1.7 2008/08/04 21:29:27 matt Exp $
-.\"
-.\" Copyright (c) 1990, 1991, 1993
-.\" 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. 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: @(#)ldiv.3 8.1 (Berkeley) 6/4/93
-.\"
-.Dd March 6, 2000
-.Dt LLDIV 3
-.Os
-.Sh NAME
-.Nm lldiv
-.Nd return quotient and remainder from division
-.Sh LIBRARY
-.Lb libc
-.Sh SYNOPSIS
-.In stdlib.h
-.Ft lldiv_t
-.Fn lldiv "long long int num" "long long int denom"
-.Sh DESCRIPTION
-The
-.Fn lldiv
-function
-computes the value
-.Ar num/denom
-and returns the quotient and remainder in a structure named
-.Ar lldiv_t
-that contains two
-.Em long long integer
-members named
-.Ar quot
-and
-.Ar rem .
-.Sh SEE ALSO
-.Xr div 3 ,
-.Xr imaxdiv 3 ,
-.Xr ldiv 3 ,
-.Xr math 3 ,
-.Xr qdiv 3
-.Sh STANDARDS
-The
-.Fn lldiv
-function
-conforms to
-.St -isoC-99 .