Split stdlib/abs.cpp into multiple files.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-07-19 23:27:11 +02:00
parent 02013158e7
commit 070a319006
5 changed files with 97 additions and 11 deletions

View File

@ -25,6 +25,7 @@ dirent/alphasort.o \
dirent/dir.o \
dirent/versionsort.o \
errno/errno.o \
inttypes/imaxabs.o \
inttypes/imaxdiv.o \
inttypes/strtoimax.o \
inttypes/strtoumax.o \
@ -91,7 +92,9 @@ stdlib/bsearch.o \
stdlib/calloc.o \
stdlib/div.o \
stdlib/heap.o \
stdlib/labs.o \
stdlib/ldiv.o \
stdlib/llabs.o \
stdlib/lldiv.o \
stdlib/mblen.o \
stdlib/mbstowcs.o \

30
libc/inttypes/imaxabs.cpp Normal file
View File

@ -0,0 +1,30 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2013.
This file is part of the Sortix C Library.
The Sortix C Library 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.
The Sortix C Library 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 the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
inttypes/imaxabs.cpp
Computes the absolute value of an integer.
*******************************************************************************/
#include <inttypes.h>
extern "C" intmax_t imaxabs(intmax_t val)
{
return val < 0 ? -val : val;
}

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2012.
Copyright(C) Jonas 'Sortie' Termansen 2013.
This file is part of the Sortix C Library.
@ -18,20 +18,13 @@
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
stdlib/abs.cpp
Allows taking the absolute value of integer types.
Computes the absolute value of an integer.
*******************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include <inttypes.h>
template <class T> T Absolute(T t)
extern "C" int abs(int val)
{
return t < 0 ? -t : t;
return val < 0 ? -val : val;
}
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); }

30
libc/stdlib/labs.cpp Normal file
View File

@ -0,0 +1,30 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2013.
This file is part of the Sortix C Library.
The Sortix C Library 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.
The Sortix C Library 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 the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
stdlib/labs.cpp
Computes the absolute value of an integer.
*******************************************************************************/
#include <stdlib.h>
extern "C" long int labs(long int val)
{
return val < 0 ? -val : val;
}

30
libc/stdlib/llabs.cpp Normal file
View File

@ -0,0 +1,30 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2013.
This file is part of the Sortix C Library.
The Sortix C Library 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.
The Sortix C Library 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 the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
stdlib/llabs.cpp
Computes the absolute value of an integer.
*******************************************************************************/
#include <stdlib.h>
extern "C" long long int llabs(long long int val)
{
return val < 0 ? -val : val;
}