Last change
on this file since 577 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 | /* |
---|
2 | FUNCTION |
---|
3 | <<labs>>---long integer absolute value |
---|
4 | |
---|
5 | INDEX |
---|
6 | labs |
---|
7 | |
---|
8 | SYNOPSIS |
---|
9 | #include <stdlib.h> |
---|
10 | long labs(long <[i]>); |
---|
11 | |
---|
12 | DESCRIPTION |
---|
13 | <<labs>> returns |
---|
14 | @tex |
---|
15 | $|x|$, |
---|
16 | @end tex |
---|
17 | the absolute value of <[i]> (also called the magnitude |
---|
18 | of <[i]>). That is, if <[i]> is negative, the result is the opposite |
---|
19 | of <[i]>, but if <[i]> is nonnegative the result is <[i]>. |
---|
20 | |
---|
21 | The similar function <<abs>> uses and returns <<int>> rather than |
---|
22 | <<long>> values. |
---|
23 | |
---|
24 | RETURNS |
---|
25 | The result is a nonnegative long integer. |
---|
26 | |
---|
27 | PORTABILITY |
---|
28 | <<labs>> is ANSI. |
---|
29 | |
---|
30 | No supporting OS subroutine calls are required. |
---|
31 | */ |
---|
32 | |
---|
33 | #include <stdlib.h> |
---|
34 | |
---|
35 | long |
---|
36 | labs (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.