]> pd.if.org Git - pdclib/blob - functions/stdlib/abs.c
da6aa9f2ea7f6fffed48f66a39f950b8b87a5b84
[pdclib] / functions / stdlib / abs.c
1 /* $Id$ */
2
3 /* abs( int )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <stdlib.h>
10
11 #ifndef REGTEST
12
13 int abs( int j )
14 {
15     return ( j >= 0 ) ? j : -j;
16 }
17
18 #endif
19
20 #ifdef TEST
21 #include <_PDCLIB_test.h>
22 #include <limits.h>
23
24 int main( void )
25 {
26     TESTCASE( abs( 0 ) == 0 );
27     TESTCASE( abs( INT_MAX ) == INT_MAX );
28     TESTCASE( abs( INT_MIN + 1 ) == -( INT_MIN + 1 ) );
29     return TEST_RESULTS;
30 }
31
32 #endif