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