From faa4adc9bb20a530e1195a9ee9b9cadeb07e96de Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Wed, 27 Feb 2019 20:08:23 -0500 Subject: consistent (imax|ll|l)abs() behavior and documentation --- src/stdlib/labs.c | 4 +++- src/stdlib/llabs.c | 15 ++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src/stdlib') diff --git a/src/stdlib/labs.c b/src/stdlib/labs.c index fd092f5a..298c2e64 100644 --- a/src/stdlib/labs.c +++ b/src/stdlib/labs.c @@ -2,17 +2,19 @@ #include "limits.h" /** absolute value **/ + long int labs(long int j) { if (j == LONG_MIN) { /* undefined */ + return LONG_MIN; } return j < 0 ? -j : j; } /*** -function computes the absolute value of ARGUMENT(j). +computes the absolute value of ARGUMENT(j). ***/ /* diff --git a/src/stdlib/llabs.c b/src/stdlib/llabs.c index 6ccf9c49..9fc00ab6 100644 --- a/src/stdlib/llabs.c +++ b/src/stdlib/llabs.c @@ -1,19 +1,24 @@ #include #include "limits.h" +/** absolute value **/ + long long int llabs(long long int j) { if (j == LLONG_MIN) { /* undefined */ + return LLONG_MIN; } - if (j < 0) { - return -j; - } - - return j; + return j < 0 ? -j : j; } +/*** +computes the absolute value of ARGUMENT(j). +***/ + /* +UNDEFINED(ABS(ARGUMENT(j)) cannot be represented +RETURN_SUCCESS(ABS(ARGUMENT(j)) STDC(199901) */ -- cgit v1.2.1