diff options
author | arphaman <arphaman@gmail.com> | 2013-09-04 12:47:44 +0100 |
---|---|---|
committer | arphaman <arphaman@gmail.com> | 2013-09-04 12:47:44 +0100 |
commit | b0930584ad6c1f8590c306bc8d92f923b4da8f2c (patch) | |
tree | 6d4663d95e2b5c1c7ac04fbaf5c4885169e9b399 /lib | |
parent | 1e6e1abbcdd3fada164c5f3fa8b6bbabacce4766 (diff) | |
download | libflangrt-b0930584ad6c1f8590c306bc8d92f923b4da8f2c.tar.gz |
added integer power functions
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Numerical/CMakeLists.txt | 3 | ||||
-rw-r--r-- | lib/Numerical/Integer.cpp | 29 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/Numerical/CMakeLists.txt b/lib/Numerical/CMakeLists.txt index 780074a..5311879 100644 --- a/lib/Numerical/CMakeLists.txt +++ b/lib/Numerical/CMakeLists.txt @@ -1,2 +1,3 @@ add_libflang_library(libflangNumerical - Complex.cpp) + Complex.cpp + Integer.cpp) diff --git a/lib/Numerical/Integer.cpp b/lib/Numerical/Integer.cpp new file mode 100644 index 0000000..fd3060e --- /dev/null +++ b/lib/Numerical/Integer.cpp @@ -0,0 +1,29 @@ +#include "Numerical/Integer.h" + +template<typename T> +static T ipow(T x, T y) { + if(y >= 0) { + T result = 1; + for(; y != 0; --y) + result *= x; + return result; + } + return 0; +} + +LIBFLANG_ABI int8_t libflang_pow_i1_i1(int8_t x, int8_t y) { + return ipow(x, y); +} + +LIBFLANG_ABI int16_t libflang_pow_i2_i2(int16_t x, int16_t y) { + return ipow(x, y); +} + +LIBFLANG_ABI int32_t libflang_pow_i4_i4(int32_t x, int32_t y) { + return ipow(x, y); +} + +LIBFLANG_ABI int64_t libflang_pow_i8_i8(int64_t x, int64_t y) { + return ipow(x, y); +} + |