source: trunk/libs/newlib/src/newlib/libc/stdlib/labs.c @ 471

Last change on this file since 471 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 668 bytes
Line 
1/*
2FUNCTION
3<<labs>>---long integer absolute value
4
5INDEX
6        labs
7
8SYNOPSIS
9        #include <stdlib.h>
10        long labs(long <[i]>);
11
12DESCRIPTION
13<<labs>> returns
14@tex
15$|x|$,
16@end tex
17the absolute value of <[i]> (also called the magnitude
18of <[i]>).  That is, if <[i]> is negative, the result is the opposite
19of <[i]>, but if <[i]> is nonnegative the result is <[i]>.
20
21The similar function <<abs>> uses and returns <<int>> rather than
22<<long>> values.
23
24RETURNS
25The result is a nonnegative long integer.
26
27PORTABILITY
28<<labs>> is ANSI.
29
30No supporting OS subroutine calls are required.
31*/
32
33#include <stdlib.h>
34
35long
36labs (long x)
37{
38  if (x < 0)
39    {
40      x = -x;
41    }
42  return x;
43}
Note: See TracBrowser for help on using the repository browser.