diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-07-21 20:20:05 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-07-21 20:20:05 +0000 |
commit | 0f3c317e9c5d763ce502b3ada85651eece0cb841 (patch) | |
tree | 1d76e5fa562e22766db7231011a860054e30bd2f /lib | |
parent | a616ab63a7296d06ca47e01e7d7c05c2bb683d7b (diff) |
llabs(3) for C99
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/stdlib/labs.3 | 20 | ||||
-rw-r--r-- | lib/libc/stdlib/llabs.c | 45 |
2 files changed, 59 insertions, 6 deletions
diff --git a/lib/libc/stdlib/labs.3 b/lib/libc/stdlib/labs.3 index d00c3072761..742f3eedba3 100644 --- a/lib/libc/stdlib/labs.3 +++ b/lib/libc/stdlib/labs.3 @@ -29,22 +29,28 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: labs.3,v 1.6 2003/06/02 20:18:37 millert Exp $ +.\" $OpenBSD: labs.3,v 1.7 2003/07/21 20:20:04 millert Exp $ .\" -.Dd June 29, 1991 +.Dd May 14, 2003 .Dt LABS 3 .Os .Sh NAME -.Nm labs +.Nm labs, llabs .Nd return the absolute value of a long integer .Sh SYNOPSIS .Fd #include <stdlib.h> .Ft long -.Fn labs "long j" +.Fn labs "long i" +.Ft long long +.Fn llabs "long long j" .Sh DESCRIPTION The .Fn labs function returns the absolute value of the long integer +.Fa i . +The +.Fn llabs +function returns the absolute value of the long long integer .Fa j . .Sh SEE ALSO .Xr abs 3 , @@ -54,7 +60,9 @@ function returns the absolute value of the long integer .Sh STANDARDS The .Fn labs -function conforms to -.St -ansiC . +and +.Fn llabs +functions conform to +.St -ansiC-99 . .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 00000000000..9611b5aefd3 --- /dev/null +++ b/lib/libc/stdlib/llabs.c @@ -0,0 +1,45 @@ +/* $OpenBSD: llabs.c,v 1.1 2003/07/21 20:20:04 millert Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * 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. + * 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 *rcsid = "$OpenBSD: llabs.c,v 1.1 2003/07/21 20:20:04 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <stdlib.h> + +long long llabs(long long j) +{ + return (j < 0 ? -j : j); +} |