From 9acbc30608fad91dba5d03aec73a6ad610969d16 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 9 Oct 2010 21:12:49 +0000 Subject: [PATCH] Add labs(), llabs(), and imaxabs() git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2986 42af7a65-404d-4744-a932-0658087f49c3 --- ChangeLog | 4 +++- Documentation/NuttX.html | 5 +++-- include/stdlib.h | 9 ++++++++- lib/Makefile | 2 +- lib/lib_abs.c | 8 ++++---- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8d8d37a1cf..6fb13b04a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1297,6 +1297,8 @@ for the AT91 UC3A/B family of AVR32 MCUs. * confgs/avr32dev1 - Add support for the Atmel AVR32DEV1 board featuring the AT91UC3B0256 MCU. This board is produced by www.mcuzone.com. - * include/stdlib.h, lib/Makefile and lib/lib_abs.c - Add abs(). + * include/stdlib.h, lib/Makefile, lib/lib_abs.c, lib/lib_labs.c, + lib_labs.c, lib_llabs.c, lib_imaxabs.c - Add abs(), labs(), llabs(), and + imaxabs(). diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html index 9f1fd03aae..99d372ebbe 100644 --- a/Documentation/NuttX.html +++ b/Documentation/NuttX.html @@ -1914,8 +1914,9 @@ nuttx-5.12 2010-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> for the AT91 UC3A/B family of AVR32 MCUs. * confgs/avr32dev1 - Add support for the Atmel AVR32DEV1 board featuring the AT91UC3B0256 MCU. This board is produced by www.mcuzone.com. - * include/stdlib.h, lib/Makefile and lib/lib_abs.c - Add abs(). - + * include/stdlib.h, lib/Makefile, lib/lib_abs.c, lib/lib_labs.c, + lib_labs.c, lib_llabs.c, lib_imaxabs.c - Add abs(), labs(), llabs(), and + imaxabs(). pascal-2.1 2010-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/include/stdlib.h b/include/stdlib.h index c30d07ee39..7509768a19 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -41,7 +41,9 @@ ****************************************************************************/ #include +#include #include +#include /**************************************************************************** * Definitions @@ -146,7 +148,12 @@ EXTERN FAR void *calloc(size_t, size_t); /* Misc */ -EXTERN int abs(int i); +EXTERN int abs(int j); +EXTERN long int labs(long int j); +#ifdef CONFIG_HAVE_LONG_LONG +EXTERN long long int llabs(long long int j); +#endif +EXTERN intmax_t imaxabs(intmax_t j); /* Sorting */ diff --git a/lib/Makefile b/lib/Makefile index b8897d842f..a08e721562 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -75,7 +75,7 @@ ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y) STDIO_SRCS += lib_dtoa.c endif -STDLIB_SRCS = lib_abs.c lib_rand.c lib_qsort.c +STDLIB_SRCS = lib_abs.c lib_imaxabs.c lib_labs.c lib_llabs.c lib_rand.c lib_qsort.c MATH_SRCS = lib_rint.c lib_fixedmath.c lib_b16sin.c lib_b16cos.c diff --git a/lib/lib_abs.c b/lib/lib_abs.c index 8ef131b875..39339b86cd 100644 --- a/lib/lib_abs.c +++ b/lib/lib_abs.c @@ -44,11 +44,11 @@ * Global Functions ************************************************************************/ -int abs(int i) +int abs(int j) { - if (i < 0) + if (j < 0) { - i = -i; + j = -j; } - return i; + return j; }