aboutsummaryrefslogtreecommitdiffstats
path: root/src/pdclib/functions/stdlib/labs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdclib/functions/stdlib/labs.c')
-rw-r--r--src/pdclib/functions/stdlib/labs.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/pdclib/functions/stdlib/labs.c b/src/pdclib/functions/stdlib/labs.c
new file mode 100644
index 0000000..3653453
--- /dev/null
+++ b/src/pdclib/functions/stdlib/labs.c
@@ -0,0 +1,32 @@
+/* labs( long 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
+
+long int labs( long int j )
+{
+ return ( j >= 0 ) ? j : -j;
+}
+
+#endif
+
+#ifdef TEST
+
+#include "_PDCLIB_test.h"
+
+#include <limits.h>
+
+int main( void )
+{
+ TESTCASE( labs( 0 ) == 0 );
+ TESTCASE( labs( LONG_MAX ) == LONG_MAX );
+ TESTCASE( labs( LONG_MIN + 1 ) == -( LONG_MIN + 1 ) );
+ return TEST_RESULTS;
+}
+
+#endif