Browse Source

llabs(3) for C99

OPENBSD_3_4
millert 21 years ago
parent
commit
378610259f
2 changed files with 59 additions and 6 deletions
  1. +14
    -6
      src/lib/libc/stdlib/labs.3
  2. +45
    -0
      src/lib/libc/stdlib/llabs.c

+ 14
- 6
src/lib/libc/stdlib/labs.3 View File

@ -29,22 +29,28 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" 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 .Dt LABS 3
.Os .Os
.Sh NAME .Sh NAME
.Nm labs
.Nm labs, llabs
.Nd return the absolute value of a long integer .Nd return the absolute value of a long integer
.Sh SYNOPSIS .Sh SYNOPSIS
.Fd #include <stdlib.h> .Fd #include <stdlib.h>
.Ft long .Ft long
.Fn labs "long j"
.Fn labs "long i"
.Ft long long
.Fn llabs "long long j"
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Fn labs .Fn labs
function returns the absolute value of the long integer 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 . .Fa j .
.Sh SEE ALSO .Sh SEE ALSO
.Xr abs 3 , .Xr abs 3 ,
@ -54,7 +60,9 @@ function returns the absolute value of the long integer
.Sh STANDARDS .Sh STANDARDS
The The
.Fn labs .Fn labs
function conforms to
.St -ansiC .
and
.Fn llabs
functions conform to
.St -ansiC-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.

+ 45
- 0
src/lib/libc/stdlib/llabs.c View File

@ -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);
}

Loading…
Cancel
Save