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/inttypes/imaxabs.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/inttypes') diff --git a/src/inttypes/imaxabs.c b/src/inttypes/imaxabs.c index 7d6be923..be184ebf 100644 --- a/src/inttypes/imaxabs.c +++ b/src/inttypes/imaxabs.c @@ -1,28 +1,24 @@ #include "stddef.h" #include +/** absolute value **/ + intmax_t imaxabs(intmax_t j) { - /* returns the absolute value of j */ - /* if imaxabs(j) can't be representeted (i.e. imaxabs(INTMAX_MIN), behavior is undefined */ -/* - if (j == INTMAX_MIN) { - __ungol_libc_undefined("Cannot represent absolute value of %" PRIxMAX "\n", j); - } -*/ if (j == INTMAX_MIN) { /* undefined behavior */ return INTMAX_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