aboutsummaryrefslogtreecommitdiffstats
path: root/src/pdclib/functions/stdlib/abs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdclib/functions/stdlib/abs.c')
-rw-r--r--src/pdclib/functions/stdlib/abs.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/pdclib/functions/stdlib/abs.c b/src/pdclib/functions/stdlib/abs.c
new file mode 100644
index 0000000..7a634e3
--- /dev/null
+++ b/src/pdclib/functions/stdlib/abs.c
@@ -0,0 +1,32 @@
+/* abs( int )
+
+ This file is part of the Public Domain C Library (PDCLib).
+ Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <stdlib.h>
+
+#ifndef REGTEST
+
+int abs( int j )
+{
+ return ( j >= 0 ) ? j : -j;
+}
+
+#endif
+
+#ifdef TEST
+
+#include "_PDCLIB_test.h"
+
+#include <limits.h>
+
+int main( void )
+{
+ TESTCASE( abs( 0 ) == 0 );
+ TESTCASE( abs( INT_MAX ) == INT_MAX );
+ TESTCASE( abs( INT_MIN + 1 ) == -( INT_MIN + 1 ) );
+ return TEST_RESULTS;
+}
+
+#endif