diff options
Diffstat (limited to 'src/stdlib/abs.c')
-rw-r--r-- | src/stdlib/abs.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/stdlib/abs.c b/src/stdlib/abs.c new file mode 100644 index 00000000..9bc6ca28 --- /dev/null +++ b/src/stdlib/abs.c @@ -0,0 +1,23 @@ +#include <stdlib.h> +#include "limits.h" + +/** absolute value **/ + +int abs(int j) +{ + if (j == INT_MIN) { + /* undefined behavior */ + } + + return j < 0 ? -j : j; +} + +/*** +computes the absolute value of ARGUMENT(j). +***/ + +/* +UNDEFINED(ABS(ARGUMENT(j)) cannot be represented) +RETURN_SUCCESS(ABS(j)); +STDC(1) +*/ |