diff options
| author | Mike Barcroft <mike@FreeBSD.org> | 2001-11-15 02:05:03 +0000 | 
|---|---|---|
| committer | Mike Barcroft <mike@FreeBSD.org> | 2001-11-15 02:05:03 +0000 | 
| commit | 7a4a63270ffd4cf0deae379b3ad32f57ea3c3e9d (patch) | |
| tree | 65345c27494b147fb94a03b0e7ab6a7afb3725cd | |
| parent | f209c331393ab8a2b716c21543e696a07809e512 (diff) | |
Notes
| -rw-r--r-- | include/inttypes.h | 4 | ||||
| -rw-r--r-- | include/stdlib.h | 13 | ||||
| -rw-r--r-- | lib/libc/stdlib/Makefile.inc | 10 | ||||
| -rw-r--r-- | lib/libc/stdlib/abs.3 | 6 | ||||
| -rw-r--r-- | lib/libc/stdlib/div.3 | 8 | ||||
| -rw-r--r-- | lib/libc/stdlib/imaxabs.3 | 62 | ||||
| -rw-r--r-- | lib/libc/stdlib/imaxabs.c | 36 | ||||
| -rw-r--r-- | lib/libc/stdlib/imaxdiv.3 | 71 | ||||
| -rw-r--r-- | lib/libc/stdlib/imaxdiv.c | 45 | ||||
| -rw-r--r-- | lib/libc/stdlib/labs.3 | 4 | ||||
| -rw-r--r-- | lib/libc/stdlib/ldiv.3 | 6 | ||||
| -rw-r--r-- | lib/libc/stdlib/llabs.3 | 62 | ||||
| -rw-r--r-- | lib/libc/stdlib/llabs.c | 36 | ||||
| -rw-r--r-- | lib/libc/stdlib/lldiv.3 | 71 | ||||
| -rw-r--r-- | lib/libc/stdlib/lldiv.c | 45 | 
15 files changed, 465 insertions, 14 deletions
| diff --git a/include/inttypes.h b/include/inttypes.h index f6b19229b0a5..63871914aa9e 100644 --- a/include/inttypes.h +++ b/include/inttypes.h @@ -42,8 +42,8 @@ typedef struct {  	intmax_t	rem;		/* Remainder. */  } imaxdiv_t; -intmax_t	imaxabs(intmax_t); -imaxdiv_t	imaxdiv(intmax_t, intmax_t); +intmax_t	imaxabs(intmax_t) __pure2; +imaxdiv_t	imaxdiv(intmax_t, intmax_t) __pure2;  /* XXX: The following functions are missing the restrict type qualifier. */  intmax_t	strtoimax(const char *, char **, int); diff --git a/include/stdlib.h b/include/stdlib.h index c0ec98709476..3e7ce25b0237 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -68,6 +68,13 @@ typedef struct {  	long rem;		/* remainder */  } ldiv_t; +#ifdef __LONG_LONG_SUPPORTED +typedef struct { +	long long quot; +	long long rem; +} lldiv_t; +#endif +  #ifndef NULL  #define	NULL	0  #endif @@ -118,6 +125,12 @@ int	 wctomb __P((char *, wchar_t));  int	 mbtowc __P((wchar_t *, const char *, 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)  extern char *_malloc_options;  extern void (*_malloc_message)__P((char *p1, char *p2, char *p3, char *p4)); diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc index 077f35ccff7f..ac2539f9c47e 100644 --- a/lib/libc/stdlib/Makefile.inc +++ b/lib/libc/stdlib/Makefile.inc @@ -5,8 +5,9 @@  .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 \ -	exit.c getenv.c getopt.c getsubopt.c hcreate.c heapsort.c labs.c \ -	ldiv.c malloc.c merge.c putenv.c qsort.c radixsort.c rand.c random.c \ +	exit.c getenv.c getopt.c getsubopt.c hcreate.c heapsort.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 \  	strtoll.c strtoq.c strtoul.c strtoull.c strtouq.c system.c \  	tdelete.c tfind.c tsearch.c twalk.c @@ -27,8 +28,9 @@ SRCS+=	strtod.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 getsubopt.3 hcreate.3 labs.3 \ -	ldiv.3 malloc.3 memory.3 qsort.3 radixsort.3 rand.3 random.3 \ +	div.3 exit.3 getenv.3 getopt.3 getsubopt.3 hcreate.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  MLINKS+=getenv.3 putenv.3 getenv.3 setenv.3 getenv.3 unsetenv.3 diff --git a/lib/libc/stdlib/abs.3 b/lib/libc/stdlib/abs.3 index 92d9c12d5d61..9dee8ed2d2ed 100644 --- a/lib/libc/stdlib/abs.3 +++ b/lib/libc/stdlib/abs.3 @@ -36,7 +36,7 @@  .\"     @(#)abs.3	8.1 (Berkeley) 6/4/93  .\" $FreeBSD$  .\" -.Dd June 4, 1993 +.Dd November 14, 2001  .Dt ABS 3  .Os  .Sh NAME @@ -66,12 +66,14 @@ the absolute value.  .Xr fabs 3 ,  .Xr floor 3 ,  .Xr hypot 3 , +.Xr imaxabs 3 ,  .Xr labs 3 , +.Xr llabs 3 ,  .Xr math 3  .Sh STANDARDS  The  .Fn abs  function conforms to -.St -isoC . +.St -isoC-99 .  .Sh BUGS  The absolute value of the most negative integer remains negative. diff --git a/lib/libc/stdlib/div.3 b/lib/libc/stdlib/div.3 index b45255ab8cde..31fc7424cca6 100644 --- a/lib/libc/stdlib/div.3 +++ b/lib/libc/stdlib/div.3 @@ -34,7 +34,7 @@  .\"     @(#)div.3	8.1 (Berkeley) 6/4/93  .\" $FreeBSD$  .\" -.Dd June 4, 1993 +.Dd November 14, 2001  .Dt DIV 3  .Os  .Sh NAME @@ -61,10 +61,12 @@ members named  and  .Fa rem .  .Sh SEE ALSO -.Xr ldiv 3 +.Xr imaxdiv 3 , +.Xr ldiv 3 , +.Xr lldiv 3  .Sh STANDARDS  The  .Fn div  function  conforms to -.St -isoC . +.St -isoC-99 . diff --git a/lib/libc/stdlib/imaxabs.3 b/lib/libc/stdlib/imaxabs.3 new file mode 100644 index 000000000000..3b92563ce29b --- /dev/null +++ b/lib/libc/stdlib/imaxabs.3 @@ -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. diff --git a/lib/libc/stdlib/imaxabs.c b/lib/libc/stdlib/imaxabs.c new file mode 100644 index 000000000000..35e3dee79d36 --- /dev/null +++ b/lib/libc/stdlib/imaxabs.c @@ -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); +} diff --git a/lib/libc/stdlib/imaxdiv.3 b/lib/libc/stdlib/imaxdiv.3 new file mode 100644 index 000000000000..b451064c0941 --- /dev/null +++ b/lib/libc/stdlib/imaxdiv.3 @@ -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 . diff --git a/lib/libc/stdlib/imaxdiv.c b/lib/libc/stdlib/imaxdiv.c new file mode 100644 index 000000000000..7dae4675e2b1 --- /dev/null +++ b/lib/libc/stdlib/imaxdiv.c @@ -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); +} diff --git a/lib/libc/stdlib/labs.3 b/lib/libc/stdlib/labs.3 index 3f8199df6e2f..9831bdbdbb7b 100644 --- a/lib/libc/stdlib/labs.3 +++ b/lib/libc/stdlib/labs.3 @@ -36,7 +36,7 @@  .\"     @(#)labs.3	8.1 (Berkeley) 6/4/93  .\" $FreeBSD$  .\" -.Dd June 4, 1993 +.Dd November 14, 2001  .Dt LABS 3  .Os  .Sh NAME @@ -58,6 +58,8 @@ returns the absolute value of the long integer  .Xr abs 3 ,  .Xr cabs 3 ,  .Xr floor 3 , +.Xr imaxabs 3 , +.Xr llabs 3 ,  .Xr math 3  .Sh STANDARDS  The diff --git a/lib/libc/stdlib/ldiv.3 b/lib/libc/stdlib/ldiv.3 index f6b247745e0d..8e09cdf3dde1 100644 --- a/lib/libc/stdlib/ldiv.3 +++ b/lib/libc/stdlib/ldiv.3 @@ -36,7 +36,7 @@  .\"     @(#)ldiv.3	8.1 (Berkeley) 6/4/93  .\" $FreeBSD$  .\" -.Dd June 4, 1993 +.Dd November 14, 2001  .Dt LDIV 3  .Os  .Sh NAME @@ -64,10 +64,12 @@ and  .Ar rem .  .Sh SEE ALSO  .Xr div 3 , +.Xr imaxdiv 3 , +.Xr lldiv 3 ,  .Xr math 3  .Sh STANDARDS  The  .Fn ldiv  function  conforms to -.St -isoC . +.St -isoC-99 . diff --git a/lib/libc/stdlib/llabs.3 b/lib/libc/stdlib/llabs.3 new file mode 100644 index 000000000000..b417a07ef3fe --- /dev/null +++ b/lib/libc/stdlib/llabs.3 @@ -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. diff --git a/lib/libc/stdlib/llabs.c b/lib/libc/stdlib/llabs.c new file mode 100644 index 000000000000..2bfbada80d93 --- /dev/null +++ b/lib/libc/stdlib/llabs.c @@ -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); +} diff --git a/lib/libc/stdlib/lldiv.3 b/lib/libc/stdlib/lldiv.3 new file mode 100644 index 000000000000..980ab67695d9 --- /dev/null +++ b/lib/libc/stdlib/lldiv.3 @@ -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 . diff --git a/lib/libc/stdlib/lldiv.c b/lib/libc/stdlib/lldiv.c new file mode 100644 index 000000000000..b34b65e8632d --- /dev/null +++ b/lib/libc/stdlib/lldiv.c @@ -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); +} | 
