File: labs.c

package info (click to toggle)
picolibc 1.8.11-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 50,064 kB
  • sloc: ansic: 404,031; asm: 24,984; sh: 2,585; python: 2,289; perl: 680; pascal: 329; exp: 287; makefile: 222; cpp: 71; xml: 40
file content (46 lines) | stat: -rw-r--r-- 778 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Copyright (c) 1990 Regents of the University of California.
All rights reserved.
 */
/*
FUNCTION
<<labs>>---long integer absolute value

INDEX
        labs

SYNOPSIS
        #include <stdlib.h>
        long labs(long <[i]>);

DESCRIPTION
<<labs>> returns
@tex
$|x|$,
@end tex
the absolute value of <[i]> (also called the magnitude
of <[i]>).  That is, if <[i]> is negative, the result is the opposite
of <[i]>, but if <[i]> is nonnegative the result is <[i]>.

The similar function <<abs>> uses and returns <<int>> rather than
<<long>> values.

RETURNS
The result is a nonnegative long integer.

PORTABILITY
<<labs>> is ANSI.

No supporting OS subroutine calls are required.
*/

#include <stdlib.h>

long
labs(long x)
{
    if (x < 0) {
        x = -x;
    }
    return x;
}