diff --git a/libmaxsi/Makefile b/libmaxsi/Makefile index face365e..72f8f3a2 100644 --- a/libmaxsi/Makefile +++ b/libmaxsi/Makefile @@ -49,6 +49,7 @@ $(CPU)/signal.o \ start.o \ time.o \ random.o \ +abs.o \ integer.o \ c++.o \ memory.o \ diff --git a/libmaxsi/abs.cpp b/libmaxsi/abs.cpp new file mode 100644 index 00000000..a2476e65 --- /dev/null +++ b/libmaxsi/abs.cpp @@ -0,0 +1,38 @@ +/******************************************************************************* + + COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + abs.cpp + Allows taking the absolute value of integer types. + +*******************************************************************************/ + +#include +#include +#include + +template T Absolute(T t) +{ + return t < 0 ? -t : t; +} + +extern "C" int abs(int val) { return Absolute(val); } +extern "C" long int labs(long int val) { return Absolute(val); } +extern "C" long long int llabs(long long int val) { return Absolute(val); } +extern "C" intmax_t imaxabs(intmax_t val) { return Absolute(val); } + diff --git a/libmaxsi/include/inttypes.h b/libmaxsi/include/inttypes.h new file mode 100644 index 00000000..181c9aa1 --- /dev/null +++ b/libmaxsi/include/inttypes.h @@ -0,0 +1,39 @@ +/******************************************************************************* + + COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + inttypes.h + Fixed size integer types. + +*******************************************************************************/ + +#ifndef _INTTYPES_H +#define _INTTYPES_H 1 + +#include +#include + +/* TODO: This header does not fully comply with POSIX and the ISO C Standard. */ + +__BEGIN_DECLS + +intmax_t imaxabs(intmax_t); + +__END_DECLS + +#endif diff --git a/libmaxsi/include/stdlib.h b/libmaxsi/include/stdlib.h index 95b9048b..f7faea4a 100644 --- a/libmaxsi/include/stdlib.h +++ b/libmaxsi/include/stdlib.h @@ -1,6 +1,6 @@ -/****************************************************************************** +/******************************************************************************* - COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011. + COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012. This file is part of LibMaxsi. @@ -11,8 +11,8 @@ LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for - more details. + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. You should have received a copy of the GNU Lesser General Public License along with LibMaxsi. If not, see . @@ -20,7 +20,7 @@ stdlib.h Standard library definitions. -******************************************************************************/ +*******************************************************************************/ #ifndef _STDLIB_H #define _STDLIB_H 1 @@ -48,6 +48,7 @@ typedef int div_t, ldiv_t, lldiv_t; /* TODO: WEXITSTATUS, WIFEXITED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WSTOPSIG, WTERMSIG, WUNTRACED is missing here */ void abort(void); +int abs(int value); int atoi(const char*); long atol(const char*); long long atoll(const char*); @@ -56,6 +57,8 @@ void exit(int); void _Exit(int status); void free(void*); char* getenv(const char*); +long labs(long); +long long llabs(long long); void* malloc(size_t); #if !defined(_SORTIX_SOURCE) char* mktemp(char* templ); @@ -71,7 +74,6 @@ long long strtoll(const char* restrict, char** restrict, int); /* TODO: These are not implemented in libmaxsi/sortix yet. */ #if defined(__SORTIX_SHOW_UNIMPLEMENTED) long a64l(const char* s); -int abs(int value); int atexit(void (*function)(void)); double atof(const char* value); void* bsearch(const void*, const void*, size_t, size_t, int (*)(const void*, const void*)); @@ -83,10 +85,8 @@ int grantpt(int); char* initstate(unsigned, char*, size_t); long jrand48(unsigned short [3]); char* l64a(long); -long labs(long); void lcong48(unsigned short [7]); ldiv_t ldiv(long, long); -long long llabs(long long); lldiv_t lldiv(long long, long long); long lrand48(void); int mblen(const char*, size_t);