diff options
author | arphaman <arphaman@gmail.com> | 2013-07-12 18:41:54 +0100 |
---|---|---|
committer | arphaman <arphaman@gmail.com> | 2013-07-12 18:41:54 +0100 |
commit | 78cd387e394747fcbfdb0ffac54a0b9a8c8bec37 (patch) | |
tree | bc3261fc8bb7b5844664a6aa1d9572ba4873aa8e | |
parent | 7e433007c5e8dda8a993c279d86402257595d8e3 (diff) | |
download | libflangrt-78cd387e394747fcbfdb0ffac54a0b9a8c8bec37.tar.gz |
added complex number functions
-rw-r--r-- | include/Numerical/Complex.h | 56 | ||||
-rw-r--r-- | include/Strings/Character.h | 2 | ||||
-rw-r--r-- | lib/Numerical/CMakeLists.txt | 3 | ||||
-rw-r--r-- | lib/Numerical/Complex.cpp | 93 |
4 files changed, 152 insertions, 2 deletions
diff --git a/include/Numerical/Complex.h b/include/Numerical/Complex.h new file mode 100644 index 0000000..2706bd2 --- /dev/null +++ b/include/Numerical/Complex.h @@ -0,0 +1,56 @@ +//===--- Complex.h - Complex numbers library --------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBFLANG_NUMERICAL_COMPLEX_H +#define LLVM_LIBFLANG_NUMERICAL_COMPLEX_H + +#include "Libflang.h" + +struct Complex4 { + float Re, Im; +}; + +struct Complex8 { + double Re, Im; +}; + +LIBFLANG_ABI Complex8 libflang_cpow(double LHSRe, double LHSIm, + double RHSRe, double RHSIm); +LIBFLANG_ABI Complex4 libflang_cpowf(float LHSRe, float LHSIm, + float RHSRe, float RHSIm); + +LIBFLANG_ABI Complex8 libflang_cpowi(double Re, double Im, + int32_t power); +LIBFLANG_ABI Complex4 libflang_cpowif(float Re, float Im, + int32_t power); + +// intrinsics + +LIBFLANG_ABI double libflang_cabs(double Re, double Im); +LIBFLANG_ABI float libflang_cabsf(float Re, float Im); + +LIBFLANG_ABI Complex8 libflang_csqrt(double Re, double Im); +LIBFLANG_ABI Complex4 libflang_csqrtf(float Re, float Im); + +LIBFLANG_ABI Complex8 libflang_cexp(double Re, double Im); +LIBFLANG_ABI Complex4 libflang_cexpf(float Re, float Im); + +LIBFLANG_ABI Complex8 libflang_clog(double Re, double Im); +LIBFLANG_ABI Complex4 libflang_clogf(float Re, float Im); + +LIBFLANG_ABI Complex8 libflang_csin(double Re, double Im); +LIBFLANG_ABI Complex4 libflang_csinf(float Re, float Im); + +LIBFLANG_ABI Complex8 libflang_ccos(double Re, double Im); +LIBFLANG_ABI Complex4 libflang_ccosf(float Re, float Im); + +LIBFLANG_ABI Complex8 libflang_ctan(double Re, double Im); +LIBFLANG_ABI Complex4 libflang_ctanf(float Re, float Im); + +#endif diff --git a/include/Strings/Character.h b/include/Strings/Character.h index 7c67577..134d901 100644 --- a/include/Strings/Character.h +++ b/include/Strings/Character.h @@ -1,4 +1,4 @@ -//===--- Core.h - Core library --------------------------------*- C++ -*-===// +//===--- Character.h - Character library ------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // diff --git a/lib/Numerical/CMakeLists.txt b/lib/Numerical/CMakeLists.txt index 8b13789..780074a 100644 --- a/lib/Numerical/CMakeLists.txt +++ b/lib/Numerical/CMakeLists.txt @@ -1 +1,2 @@ - +add_libflang_library(libflangNumerical + Complex.cpp) diff --git a/lib/Numerical/Complex.cpp b/lib/Numerical/Complex.cpp new file mode 100644 index 0000000..ccc9dc6 --- /dev/null +++ b/lib/Numerical/Complex.cpp @@ -0,0 +1,93 @@ +#include <complex> +#include "Numerical/Complex.h" + +using namespace std; + +static inline Complex8 cmplx(complex<double> Value) { + Complex8 Result = { Value.real(), Value.imag() }; + return Result; +} + +static inline Complex4 cmplx(complex<float> Value) { + Complex4 Result = { Value.real(), Value.imag() }; + return Result; +} + +static inline complex<double> generic(double Re, double Im) { + return complex<double>(Re, Im); +} + +static inline complex<float> generic(float Re, float Im) { + return complex<float>(Re, Im); +} + +LIBFLANG_ABI Complex8 libflang_cpow(double LHSRe, double LHSIm, + double RHSRe, double RHSIm) { + return cmplx(pow(generic(LHSRe, LHSIm), + generic(RHSRe, RHSIm))); +} +LIBFLANG_ABI Complex4 libflang_cpowf(float LHSRe, float LHSIm, + float RHSRe, float RHSIm) { + return cmplx(pow(generic(LHSRe, LHSIm), + generic(RHSRe, RHSIm))); +} + +LIBFLANG_ABI Complex8 libflang_cpowi(double Re, double Im, + int32_t power) { + return cmplx(pow(generic(Re, Im), power)); +} +LIBFLANG_ABI Complex4 libflang_cpowif(float Re, float Im, + int32_t power) { + return cmplx(complex<float>(pow(generic(Re, Im), power))); +} + +// intrinsics + +LIBFLANG_ABI double libflang_cabs(double Re, double Im) { + return abs(generic(Re, Im)); +} +LIBFLANG_ABI float libflang_cabsf(float Re, float Im) { + return abs(generic(Re, Im)); +} + +LIBFLANG_ABI Complex8 libflang_csqrt(double Re, double Im) { + return cmplx(sqrt(generic(Re, Im))); +} +LIBFLANG_ABI Complex4 libflang_csqrtf(float Re, float Im) { + return cmplx(sqrt(generic(Re, Im))); +} + +LIBFLANG_ABI Complex8 libflang_cexp(double Re, double Im) { + return cmplx(exp(generic(Re, Im))); +} +LIBFLANG_ABI Complex4 libflang_cexpf(float Re, float Im) { + return cmplx(exp(generic(Re, Im))); +} + +LIBFLANG_ABI Complex8 libflang_clog(double Re, double Im) { + return cmplx(log(generic(Re, Im))); +} +LIBFLANG_ABI Complex4 libflang_clogf(float Re, float Im) { + return cmplx(log(generic(Re, Im))); +} + +LIBFLANG_ABI Complex8 libflang_csin(double Re, double Im) { + return cmplx(sin(generic(Re, Im))); +} +LIBFLANG_ABI Complex4 libflang_csinf(float Re, float Im) { + return cmplx(sin(generic(Re, Im))); +} + +LIBFLANG_ABI Complex8 libflang_ccos(double Re, double Im) { + return cmplx(cos(generic(Re, Im))); +} +LIBFLANG_ABI Complex4 libflang_ccosf(float Re, float Im) { + return cmplx(cos(generic(Re, Im))); +} + +LIBFLANG_ABI Complex8 libflang_ctan(double Re, double Im) { + return cmplx(tan(generic(Re, Im))); +} +LIBFLANG_ABI Complex4 libflang_ctanf(float Re, float Im) { + return cmplx(tan(generic(Re, Im))); +} |