Added {,l,ll,imax}abs(3).
This commit is contained in:
parent
554b2e44cc
commit
cd0e402bbb
|
@ -49,6 +49,7 @@ $(CPU)/signal.o \
|
||||||
start.o \
|
start.o \
|
||||||
time.o \
|
time.o \
|
||||||
random.o \
|
random.o \
|
||||||
|
abs.o \
|
||||||
integer.o \
|
integer.o \
|
||||||
c++.o \
|
c++.o \
|
||||||
memory.o \
|
memory.o \
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
abs.cpp
|
||||||
|
Allows taking the absolute value of integer types.
|
||||||
|
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
template <class T> 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); }
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
inttypes.h
|
||||||
|
Fixed size integer types.
|
||||||
|
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef _INTTYPES_H
|
||||||
|
#define _INTTYPES_H 1
|
||||||
|
|
||||||
|
#include <features.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* TODO: This header does not fully comply with POSIX and the ISO C Standard. */
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
intmax_t imaxabs(intmax_t);
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,6 +1,6 @@
|
||||||
/******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011, 2012.
|
||||||
|
|
||||||
This file is part of LibMaxsi.
|
This file is part of LibMaxsi.
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@
|
||||||
|
|
||||||
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
|
LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||||
more details.
|
details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
stdlib.h
|
stdlib.h
|
||||||
Standard library definitions.
|
Standard library definitions.
|
||||||
|
|
||||||
******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#ifndef _STDLIB_H
|
#ifndef _STDLIB_H
|
||||||
#define _STDLIB_H 1
|
#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 */
|
/* TODO: WEXITSTATUS, WIFEXITED, WIFSIGNALED, WIFSTOPPED, WNOHANG, WSTOPSIG, WTERMSIG, WUNTRACED is missing here */
|
||||||
|
|
||||||
void abort(void);
|
void abort(void);
|
||||||
|
int abs(int value);
|
||||||
int atoi(const char*);
|
int atoi(const char*);
|
||||||
long atol(const char*);
|
long atol(const char*);
|
||||||
long long atoll(const char*);
|
long long atoll(const char*);
|
||||||
|
@ -56,6 +57,8 @@ void exit(int);
|
||||||
void _Exit(int status);
|
void _Exit(int status);
|
||||||
void free(void*);
|
void free(void*);
|
||||||
char* getenv(const char*);
|
char* getenv(const char*);
|
||||||
|
long labs(long);
|
||||||
|
long long llabs(long long);
|
||||||
void* malloc(size_t);
|
void* malloc(size_t);
|
||||||
#if !defined(_SORTIX_SOURCE)
|
#if !defined(_SORTIX_SOURCE)
|
||||||
char* mktemp(char* templ);
|
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. */
|
/* TODO: These are not implemented in libmaxsi/sortix yet. */
|
||||||
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
||||||
long a64l(const char* s);
|
long a64l(const char* s);
|
||||||
int abs(int value);
|
|
||||||
int atexit(void (*function)(void));
|
int atexit(void (*function)(void));
|
||||||
double atof(const char* value);
|
double atof(const char* value);
|
||||||
void* bsearch(const void*, const void*, size_t, size_t, int (*)(const void*, const void*));
|
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);
|
char* initstate(unsigned, char*, size_t);
|
||||||
long jrand48(unsigned short [3]);
|
long jrand48(unsigned short [3]);
|
||||||
char* l64a(long);
|
char* l64a(long);
|
||||||
long labs(long);
|
|
||||||
void lcong48(unsigned short [7]);
|
void lcong48(unsigned short [7]);
|
||||||
ldiv_t ldiv(long, long);
|
ldiv_t ldiv(long, long);
|
||||||
long long llabs(long long);
|
|
||||||
lldiv_t lldiv(long long, long long);
|
lldiv_t lldiv(long long, long long);
|
||||||
long lrand48(void);
|
long lrand48(void);
|
||||||
int mblen(const char*, size_t);
|
int mblen(const char*, size_t);
|
||||||
|
|
Loading…
Reference in New Issue