diff --git a/libc/Makefile b/libc/Makefile index 8670e0ee..09cba051 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -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 \ diff --git a/libc/inttypes/imaxabs.cpp b/libc/inttypes/imaxabs.cpp new file mode 100644 index 00000000..058ab4f9 --- /dev/null +++ b/libc/inttypes/imaxabs.cpp @@ -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 . + + inttypes/imaxabs.cpp + Computes the absolute value of an integer. + +*******************************************************************************/ + +#include + +extern "C" intmax_t imaxabs(intmax_t val) +{ + return val < 0 ? -val : val; +} diff --git a/libc/stdlib/abs.cpp b/libc/stdlib/abs.cpp index a48ccdea..9dd9d1b6 100644 --- a/libc/stdlib/abs.cpp +++ b/libc/stdlib/abs.cpp @@ -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 . stdlib/abs.cpp - Allows taking the absolute value of integer types. + Computes the absolute value of an integer. *******************************************************************************/ -#include #include -#include -template 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); } diff --git a/libc/stdlib/labs.cpp b/libc/stdlib/labs.cpp new file mode 100644 index 00000000..cf9980c2 --- /dev/null +++ b/libc/stdlib/labs.cpp @@ -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 . + + stdlib/labs.cpp + Computes the absolute value of an integer. + +*******************************************************************************/ + +#include + +extern "C" long int labs(long int val) +{ + return val < 0 ? -val : val; +} diff --git a/libc/stdlib/llabs.cpp b/libc/stdlib/llabs.cpp new file mode 100644 index 00000000..ca8fdaab --- /dev/null +++ b/libc/stdlib/llabs.cpp @@ -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 . + + stdlib/llabs.cpp + Computes the absolute value of an integer. + +*******************************************************************************/ + +#include + +extern "C" long long int llabs(long long int val) +{ + return val < 0 ? -val : val; +}