libc: add labs() and llabs()

Add support for abs with additional integer types.

This is needed to make LLVM quiet and stop warning about abs being used
with int64_t and such.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2020-11-18 15:42:37 -05:00 committed by Alberto Escolar
commit 43989ca675
2 changed files with 16 additions and 3 deletions

View file

@ -261,9 +261,9 @@ This is implemented as part of the minimal C library available in Zephyr.
isspace(),+
isupper(),+
isxdigit(),+
labs(),
labs(),+
ldiv(),
llabs(),
llabs(),+
lldiv(),
localeconv(),
localtime(),+

View file

@ -39,7 +39,20 @@ void abort(void);
int rand(void);
#define abs(x) ((x) < 0 ? -(x) : (x))
static inline int abs(int __n)
{
return (__n < 0) ? -__n : __n;
}
static inline long labs(long __n)
{
return (__n < 0L) ? -__n : __n;
}
static inline long long llabs(long long __n)
{
return (__n < 0LL) ? -__n : __n;
}
#ifdef __cplusplus
}