Project

General

Profile

Bug #918 » lldiv.patch

rumcic, 01/23/2008 05:29 PM

View differences:

src/lib/libc/stdlib/lldiv.3 2008-01-15 16:26:51 +0100
.\" Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
.\" All rights reserved.
.\"
.\" 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.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
.\"
.\" $FreeBSD: src/lib/libc/stdlib/lldiv.3,v 1.2 2001/11/21 16:19:50 ru Exp $
.\"
.Dd November 14, 2001
.Dt LLDIV 3
.Os
.Sh NAME
.Nm lldiv
.Nd returns quotient and remainder
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In stdlib.h
.Ft lldiv_t
.Fn lldiv "long long numer" "long long denom"
.Sh DESCRIPTION
The
.Fn lldiv
function computes the value of
.Fa numer
divided by
.Fa denom
and returns the stored result in the form of the
.Vt lldiv_t
type.
.Pp
The
.Vt lldiv_t
type is defined as:
.Bd -literal -offset indent
typedef struct {
long long quot; /* Quotient. */
long long rem; /* Remainder. */
} lldiv_t;
.Ed
.Sh SEE ALSO
.Xr div 3 ,
.Xr imaxdiv 3 ,
.Xr ldiv 3 ,
.Xr math 3
.Sh STANDARDS
The
.Fn lldiv
function conforms to
.St -isoC-99 .
.Sh HISTORY
The
.Fn lldiv
function first appeared in
.Fx 5.0 .
-- /dev/null 2008-01-15 16:02:39 +0100
++ src/lib/libc/stdlib/lldiv.c 2008-01-15 16:28:49 +0100
/*-
* Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $FreeBSD: src/lib/libc/stdlib/lldiv.c,v 1.1 2001/11/15 02:05:03 mike Exp $
*/
#include <stdlib.h> /* lldiv_t */
lldiv_t
lldiv(long long numer, long long denom)
{
lldiv_t retval;
/* see div.c for comments */
retval.quot = numer / denom;
retval.rem = numer % denom;
if (numer >= 0 && retval.rem < 0) {
retval.quot++;
retval.rem -= denom;
}
return (retval);
}
-- src/include/stdlib.h.orig 2007-12-02 18:08:33 +0100
++ src/include/stdlib.h 2008-01-15 16:00:42 +0100
long rem; /* remainder */
} ldiv_t;
#if __ISO_C_VISIBLE >= 1999
typedef struct {
long long quot;
long long rem;
} lldiv_t;
#endif
#ifndef NULL
#define NULL 0
#endif
......
char *getenv(const char *);
long labs(long) __pure2;
ldiv_t ldiv(long, long) __pure2;
#if __ISO_C_VISIBLE >= 1999
lldiv_t lldiv(long long, long long) __pure2;
#endif
void *malloc(size_t);
void qsort(void *, size_t, size_t, int(*)(const void *, const void *));
int rand(void);
-- /dev/null 2008-01-23 00:12:16 +0100
++ src/lib/libc/stdlib/imaxdiv.3 2008-01-23 00:26:29 +0100
......
.\" Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
.\" All rights reserved.
.\"
.\" 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.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
.\"
.\" $FreeBSD: src/lib/libc/stdlib/imaxdiv.3,v 1.2 2001/11/21 16:19:50 ru Exp $
.\"
.Dd November 14, 2001
.Dt IMAXDIV 3
.Os
.Sh NAME
.Nm imaxdiv
.Nd returns quotient and remainder
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In inttypes.h
.Ft imaxdiv_t
.Fn imaxdiv "intmax_t numer" "intmax_t denom"
.Sh DESCRIPTION
The
.Fn imaxdiv
function computes the value of
.Fa numer
divided by
.Fa denom
and returns the stored result in the form of the
.Vt imaxdiv_t
type.
.Pp
The
.Vt imaxdiv_t
type is defined as:
.Bd -literal -offset indent
typedef struct {
intmax_t quot; /* Quotient. */
intmax_t rem; /* Remainder. */
} imaxdiv_t;
.Ed
.Sh SEE ALSO
.Xr div 3 ,
.Xr ldiv 3 ,
.Xr lldiv 3 ,
.Xr math 3
.Sh STANDARDS
The
.Fn imaxdiv
function conforms to
.St -isoC-99 .
.Sh HISTORY
The
.Fn imaxdiv
function first appeared in
.Fx 5.0 .
......
-- /dev/null 2008-01-23 00:12:16 +0100
++ src/lib/libc/stdlib/imaxdiv.c 2008-01-23 00:30:49 +0100
......
/*-
* Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
* All rights reserved.
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $FreeBSD: src/lib/libc/stdlib/imaxdiv.c,v 1.1 2001/11/15 02:05:03 mike Exp $
*/
#include <inttypes.h>
imaxdiv_t
imaxdiv(intmax_t numer, intmax_t denom)
{
imaxdiv_t retval;
/* see div.c for comments */
retval.quot = numer / denom;
retval.rem = numer % denom;
if (numer >= 0 && retval.rem < 0) {
retval.quot++;
retval.rem -= denom;
}
return (retval);
}
......
-- src/lib/libc/stdlib/Makefile.inc.orig 2007-12-02 04:00:18 +0100
++ src/lib/libc/stdlib/Makefile.inc 2008-01-23 00:42:00 +0100
......
MISRCS+=abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c bsearch.c calloc.c div.c \
exit.c getenv.c getopt.c getopt_long.c getsubopt.c hcreate.c heapsort.c \
imaxabs.c \
labs.c ldiv.c llabs.c malloc.c merge.c putenv.c qsort.c radixsort.c rand.c \
random.c reallocf.c realpath.c setenv.c strtod.c strtoimax.c strtol.c \
imaxabs.c imaxdiv.c \
labs.c ldiv.c lldiv.c llabs.c malloc.c merge.c putenv.c qsort.c radixsort.c \
rand.c random.c reallocf.c realpath.c setenv.c strtod.c strtoimax.c strtol.c \
strtoll.c strtonum.c strtoq.c strtoul.c strtoull.c strtoumax.c \
strtouq.c system.c tdelete.c tfind.c tsearch.c twalk.c
......
.if ${LIB} == "c"
MAN+= abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \
div.3 exit.3 getenv.3 getopt.3 getopt_long.3 getsubopt.3 hcreate.3 \
imaxabs.3 \
labs.3 ldiv.3 llabs.3 malloc.3 memory.3 qsort.3 radixsort.3 rand.3 random.3 \
realpath.3 strtod.3 strtol.3 strtonum.3 strtoul.3 system.3 tsearch.3
imaxabs.3 imaxdiv.3 \
labs.3 ldiv.3 lldiv.3 llabs.3 malloc.3 memory.3 qsort.3 radixsort.3 rand.3 \
random.3 realpath.3 strtod.3 strtol.3 strtonum.3 strtoul.3 system.3 tsearch.3
MLINKS+=atol.3 atoll.3
MLINKS+=exit.3 _Exit.3
(2-2/2)