o Implement imaxabs(), imaxdiv(), llabs(), lldiv().
o Update abs(3), div(3), labs(3), ldiv(3) to reflect standards conformance and add additional references. Reviewed by: bde, wollman
This commit is contained in:
parent
f209c33139
commit
7a4a63270f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=86368
@ -42,8 +42,8 @@ typedef struct {
|
|||||||
intmax_t rem; /* Remainder. */
|
intmax_t rem; /* Remainder. */
|
||||||
} imaxdiv_t;
|
} imaxdiv_t;
|
||||||
|
|
||||||
intmax_t imaxabs(intmax_t);
|
intmax_t imaxabs(intmax_t) __pure2;
|
||||||
imaxdiv_t imaxdiv(intmax_t, intmax_t);
|
imaxdiv_t imaxdiv(intmax_t, intmax_t) __pure2;
|
||||||
|
|
||||||
/* XXX: The following functions are missing the restrict type qualifier. */
|
/* XXX: The following functions are missing the restrict type qualifier. */
|
||||||
intmax_t strtoimax(const char *, char **, int);
|
intmax_t strtoimax(const char *, char **, int);
|
||||||
|
@ -68,6 +68,13 @@ typedef struct {
|
|||||||
long rem; /* remainder */
|
long rem; /* remainder */
|
||||||
} ldiv_t;
|
} ldiv_t;
|
||||||
|
|
||||||
|
#ifdef __LONG_LONG_SUPPORTED
|
||||||
|
typedef struct {
|
||||||
|
long long quot;
|
||||||
|
long long rem;
|
||||||
|
} lldiv_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
#endif
|
#endif
|
||||||
@ -118,6 +125,12 @@ int wctomb __P((char *, wchar_t));
|
|||||||
int mbtowc __P((wchar_t *, const char *, size_t));
|
int mbtowc __P((wchar_t *, const char *, size_t));
|
||||||
size_t wcstombs __P((char *, const wchar_t *, size_t));
|
size_t wcstombs __P((char *, const wchar_t *, size_t));
|
||||||
|
|
||||||
|
#ifdef __LONG_LONG_SUPPORTED
|
||||||
|
long long
|
||||||
|
llabs __P((long long)) __pure2;
|
||||||
|
lldiv_t lldiv __P((long long, long long)) __pure2;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
|
#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
|
||||||
extern char *_malloc_options;
|
extern char *_malloc_options;
|
||||||
extern void (*_malloc_message)__P((char *p1, char *p2, char *p3, char *p4));
|
extern void (*_malloc_message)__P((char *p1, char *p2, char *p3, char *p4));
|
||||||
|
@ -5,8 +5,9 @@
|
|||||||
.PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/stdlib ${.CURDIR}/../libc/stdlib
|
.PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/stdlib ${.CURDIR}/../libc/stdlib
|
||||||
|
|
||||||
MISRCS+=abort.c abs.c atexit.c atof.c atoi.c atol.c bsearch.c calloc.c div.c \
|
MISRCS+=abort.c abs.c atexit.c atof.c atoi.c atol.c bsearch.c calloc.c div.c \
|
||||||
exit.c getenv.c getopt.c getsubopt.c hcreate.c heapsort.c labs.c \
|
exit.c getenv.c getopt.c getsubopt.c hcreate.c heapsort.c \
|
||||||
ldiv.c malloc.c merge.c putenv.c qsort.c radixsort.c rand.c random.c \
|
imaxabs.c imaxdiv.c labs.c ldiv.c llabs.c lldiv.c \
|
||||||
|
malloc.c merge.c putenv.c qsort.c radixsort.c rand.c random.c \
|
||||||
reallocf.c realpath.c setenv.c strfmon.c strhash.c strtol.c \
|
reallocf.c realpath.c setenv.c strfmon.c strhash.c strtol.c \
|
||||||
strtoll.c strtoq.c strtoul.c strtoull.c strtouq.c system.c \
|
strtoll.c strtoq.c strtoul.c strtoull.c strtouq.c system.c \
|
||||||
tdelete.c tfind.c tsearch.c twalk.c
|
tdelete.c tfind.c tsearch.c twalk.c
|
||||||
@ -27,8 +28,9 @@ SRCS+= strtod.c
|
|||||||
|
|
||||||
.if ${LIB} == "c"
|
.if ${LIB} == "c"
|
||||||
MAN+= abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \
|
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 getsubopt.3 hcreate.3 labs.3 \
|
div.3 exit.3 getenv.3 getopt.3 getsubopt.3 hcreate.3 \
|
||||||
ldiv.3 malloc.3 memory.3 qsort.3 radixsort.3 rand.3 random.3 \
|
imaxabs.3 imaxdiv.3 labs.3 ldiv.3 llabs.3 lldiv.3 \
|
||||||
|
malloc.3 memory.3 qsort.3 radixsort.3 rand.3 random.3 \
|
||||||
realpath.3 strfmon.3 strtod.3 strtol.3 strtoul.3 system.3 tsearch.3
|
realpath.3 strfmon.3 strtod.3 strtol.3 strtoul.3 system.3 tsearch.3
|
||||||
|
|
||||||
MLINKS+=getenv.3 putenv.3 getenv.3 setenv.3 getenv.3 unsetenv.3
|
MLINKS+=getenv.3 putenv.3 getenv.3 setenv.3 getenv.3 unsetenv.3
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
.\" @(#)abs.3 8.1 (Berkeley) 6/4/93
|
.\" @(#)abs.3 8.1 (Berkeley) 6/4/93
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd June 4, 1993
|
.Dd November 14, 2001
|
||||||
.Dt ABS 3
|
.Dt ABS 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -66,12 +66,14 @@ the absolute value.
|
|||||||
.Xr fabs 3 ,
|
.Xr fabs 3 ,
|
||||||
.Xr floor 3 ,
|
.Xr floor 3 ,
|
||||||
.Xr hypot 3 ,
|
.Xr hypot 3 ,
|
||||||
|
.Xr imaxabs 3 ,
|
||||||
.Xr labs 3 ,
|
.Xr labs 3 ,
|
||||||
|
.Xr llabs 3 ,
|
||||||
.Xr math 3
|
.Xr math 3
|
||||||
.Sh STANDARDS
|
.Sh STANDARDS
|
||||||
The
|
The
|
||||||
.Fn abs
|
.Fn abs
|
||||||
function conforms to
|
function conforms to
|
||||||
.St -isoC .
|
.St -isoC-99 .
|
||||||
.Sh BUGS
|
.Sh BUGS
|
||||||
The absolute value of the most negative integer remains negative.
|
The absolute value of the most negative integer remains negative.
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
.\" @(#)div.3 8.1 (Berkeley) 6/4/93
|
.\" @(#)div.3 8.1 (Berkeley) 6/4/93
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd June 4, 1993
|
.Dd November 14, 2001
|
||||||
.Dt DIV 3
|
.Dt DIV 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -61,10 +61,12 @@ members named
|
|||||||
and
|
and
|
||||||
.Fa rem .
|
.Fa rem .
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr ldiv 3
|
.Xr imaxdiv 3 ,
|
||||||
|
.Xr ldiv 3 ,
|
||||||
|
.Xr lldiv 3
|
||||||
.Sh STANDARDS
|
.Sh STANDARDS
|
||||||
The
|
The
|
||||||
.Fn div
|
.Fn div
|
||||||
function
|
function
|
||||||
conforms to
|
conforms to
|
||||||
.St -isoC .
|
.St -isoC-99 .
|
||||||
|
62
lib/libc/stdlib/imaxabs.3
Normal file
62
lib/libc/stdlib/imaxabs.3
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
.\" 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$
|
||||||
|
.\"
|
||||||
|
.Dd November 14, 2001
|
||||||
|
.Dt IMAXABS 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm imaxabs
|
||||||
|
.Nd returns absolute value
|
||||||
|
.Sh LIBRARY
|
||||||
|
.Lb libc
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In inttypes.h
|
||||||
|
.Ft "intmax_t"
|
||||||
|
.Fn imaxabs "intmax_t j"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn imaxabs
|
||||||
|
function returns the absolute value of
|
||||||
|
.Fa j .
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr abs 3 ,
|
||||||
|
.Xr fabs 3 ,
|
||||||
|
.Xr hypot 3 ,
|
||||||
|
.Xr labs 3 ,
|
||||||
|
.Xr llabs 3 ,
|
||||||
|
.Xr math 3
|
||||||
|
.Sh STANDARDS
|
||||||
|
The
|
||||||
|
.Fm imaxabs
|
||||||
|
function conforms to
|
||||||
|
.St -isoC-99 .
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn imaxabs
|
||||||
|
function first appeared in
|
||||||
|
.Fx 5.0 .
|
||||||
|
.Sh BUGS
|
||||||
|
The absolute value of the most negative integer remains negative.
|
36
lib/libc/stdlib/imaxabs.c
Normal file
36
lib/libc/stdlib/imaxabs.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*-
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
intmax_t
|
||||||
|
imaxabs(intmax_t j)
|
||||||
|
{
|
||||||
|
return (j < 0 ? -j : j);
|
||||||
|
}
|
71
lib/libc/stdlib/imaxdiv.3
Normal file
71
lib/libc/stdlib/imaxdiv.3
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
.\" 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$
|
||||||
|
.\"
|
||||||
|
.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 imaxabs "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 imaxdiv_t type.
|
||||||
|
.Pp
|
||||||
|
The imaxdiv_t type is defined as:
|
||||||
|
.Pp
|
||||||
|
.Bd -literal -offset indent -compact
|
||||||
|
typedef struct {
|
||||||
|
intmax_t quot; /* Quotient. */
|
||||||
|
intmax_t rem; /* Remainder. */
|
||||||
|
} imaxdiv_t;
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
.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 .
|
45
lib/libc/stdlib/imaxdiv.c
Normal file
45
lib/libc/stdlib/imaxdiv.c
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*-
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
/* See comments in div.c for implementation details. */
|
||||||
|
imaxdiv_t
|
||||||
|
imaxdiv(intmax_t numer, intmax_t denom)
|
||||||
|
{
|
||||||
|
imaxdiv_t retval;
|
||||||
|
|
||||||
|
retval.quot = numer / denom;
|
||||||
|
retval.rem = numer % denom;
|
||||||
|
if (numer >= 0 && retval.rem < 0) {
|
||||||
|
retval.quot++;
|
||||||
|
retval.rem -= denom;
|
||||||
|
}
|
||||||
|
return (retval);
|
||||||
|
}
|
@ -36,7 +36,7 @@
|
|||||||
.\" @(#)labs.3 8.1 (Berkeley) 6/4/93
|
.\" @(#)labs.3 8.1 (Berkeley) 6/4/93
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd June 4, 1993
|
.Dd November 14, 2001
|
||||||
.Dt LABS 3
|
.Dt LABS 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -58,6 +58,8 @@ returns the absolute value of the long integer
|
|||||||
.Xr abs 3 ,
|
.Xr abs 3 ,
|
||||||
.Xr cabs 3 ,
|
.Xr cabs 3 ,
|
||||||
.Xr floor 3 ,
|
.Xr floor 3 ,
|
||||||
|
.Xr imaxabs 3 ,
|
||||||
|
.Xr llabs 3 ,
|
||||||
.Xr math 3
|
.Xr math 3
|
||||||
.Sh STANDARDS
|
.Sh STANDARDS
|
||||||
The
|
The
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
.\" @(#)ldiv.3 8.1 (Berkeley) 6/4/93
|
.\" @(#)ldiv.3 8.1 (Berkeley) 6/4/93
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd June 4, 1993
|
.Dd November 14, 2001
|
||||||
.Dt LDIV 3
|
.Dt LDIV 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -64,10 +64,12 @@ and
|
|||||||
.Ar rem .
|
.Ar rem .
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr div 3 ,
|
.Xr div 3 ,
|
||||||
|
.Xr imaxdiv 3 ,
|
||||||
|
.Xr lldiv 3 ,
|
||||||
.Xr math 3
|
.Xr math 3
|
||||||
.Sh STANDARDS
|
.Sh STANDARDS
|
||||||
The
|
The
|
||||||
.Fn ldiv
|
.Fn ldiv
|
||||||
function
|
function
|
||||||
conforms to
|
conforms to
|
||||||
.St -isoC .
|
.St -isoC-99 .
|
||||||
|
62
lib/libc/stdlib/llabs.3
Normal file
62
lib/libc/stdlib/llabs.3
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
.\" 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$
|
||||||
|
.\"
|
||||||
|
.Dd November 14, 2001
|
||||||
|
.Dt LLABS 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm llabs
|
||||||
|
.Nd returns absolute value
|
||||||
|
.Sh LIBRARY
|
||||||
|
.Lb libc
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In stdlib.h
|
||||||
|
.Ft "long long"
|
||||||
|
.Fn llabs "long long j"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn llabs
|
||||||
|
function returns the absolute value of
|
||||||
|
.Fa j .
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr abs 3 ,
|
||||||
|
.Xr fabs 3 ,
|
||||||
|
.Xr hypot 3 ,
|
||||||
|
.Xr imaxabs 3 ,
|
||||||
|
.Xr labs 3 ,
|
||||||
|
.Xr math 3
|
||||||
|
.Sh STANDARDS
|
||||||
|
The
|
||||||
|
.Fm llabs
|
||||||
|
function conforms to
|
||||||
|
.St -isoC-99 .
|
||||||
|
.Sh HISTORY
|
||||||
|
The
|
||||||
|
.Fn llabs
|
||||||
|
function first appeared in
|
||||||
|
.Fx 5.0 .
|
||||||
|
.Sh BUGS
|
||||||
|
The absolute value of the most negative integer remains negative.
|
36
lib/libc/stdlib/llabs.c
Normal file
36
lib/libc/stdlib/llabs.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*-
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
long long
|
||||||
|
llabs(long long j)
|
||||||
|
{
|
||||||
|
return (j < 0 ? -j : j);
|
||||||
|
}
|
71
lib/libc/stdlib/lldiv.3
Normal file
71
lib/libc/stdlib/lldiv.3
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
.\" 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$
|
||||||
|
.\"
|
||||||
|
.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 llabs "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 lldiv_t type.
|
||||||
|
.Pp
|
||||||
|
The lldiv_t type is defined as:
|
||||||
|
.Pp
|
||||||
|
.Bd -literal -offset indent -compact
|
||||||
|
typedef struct {
|
||||||
|
long long quot; /* Quotient. */
|
||||||
|
long long rem; /* Remainder. */
|
||||||
|
} lldiv_t;
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
.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 .
|
45
lib/libc/stdlib/lldiv.c
Normal file
45
lib/libc/stdlib/lldiv.c
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*-
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/* See comments in div.c for implementation details. */
|
||||||
|
lldiv_t
|
||||||
|
lldiv(long long numer, long long denom)
|
||||||
|
{
|
||||||
|
lldiv_t retval;
|
||||||
|
|
||||||
|
retval.quot = numer / denom;
|
||||||
|
retval.rem = numer % denom;
|
||||||
|
if (numer >= 0 && retval.rem < 0) {
|
||||||
|
retval.quot++;
|
||||||
|
retval.rem -= denom;
|
||||||
|
}
|
||||||
|
return (retval);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user