updated complex
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -18,23 +18,26 @@ namespace cmp
|
|||||||
__host__ __device__ explicit cucomp128(const double &other);
|
__host__ __device__ explicit cucomp128(const double &other);
|
||||||
__host__ __device__ explicit cucomp128(const double &_real, const double &_imag);
|
__host__ __device__ explicit cucomp128(const double &_real, const double &_imag);
|
||||||
|
|
||||||
__host__ __device__ cucomp128& operator=(cucomp128& other);
|
__host__ __device__ cucomp128& operator=(const cucomp128& other);
|
||||||
__host__ __device__ const cucomp128& operator=(const cucomp128& other);
|
__host__ __device__ cucomp128& operator=(const double& other);
|
||||||
__host__ __device__ cucomp128& operator=(double& other);
|
|
||||||
__host__ __device__ const cucomp128& operator=(const double& other);
|
|
||||||
|
|
||||||
__host__ __device__ double& operator[](int& ind);
|
__host__ __device__ double& operator[](int& ind);
|
||||||
__host__ __device__ const double& operator[](const int& ind) const;
|
__host__ __device__ const double& operator[](const int& ind) const;
|
||||||
|
|
||||||
__host__ __device__ cucomp128 operator+(const cucomp128& z);
|
__host__ __device__ cucomp128 operator+(const cucomp128& z) const;
|
||||||
__host__ __device__ cucomp128 operator-(const cucomp128& z);
|
__host__ __device__ cucomp128 operator-(const cucomp128& z) const;
|
||||||
__host__ __device__ cucomp128 operator*(const cucomp128& z);
|
__host__ __device__ cucomp128 operator*(const cucomp128& z) const;
|
||||||
__host__ __device__ cucomp128 operator/(const cucomp128& z);
|
__host__ __device__ cucomp128 operator/(const cucomp128& z) const;
|
||||||
|
|
||||||
__host__ __device__ cucomp128 operator+(const double& z);
|
__host__ __device__ friend cucomp128 operator+(const cucomp128& z1, const double& z2);
|
||||||
__host__ __device__ cucomp128 operator-(const double& z);
|
__host__ __device__ friend cucomp128 operator-(const cucomp128& z1, const double& z2);
|
||||||
__host__ __device__ cucomp128 operator*(const double& z);
|
__host__ __device__ friend cucomp128 operator*(const cucomp128& z1, const double& z2);
|
||||||
__host__ __device__ cucomp128 operator/(const double& z);
|
__host__ __device__ friend cucomp128 operator/(const cucomp128& z1, const double& z2);
|
||||||
|
|
||||||
|
__host__ __device__ friend cucomp128 operator+(const double& z1, const cucomp128& z2);
|
||||||
|
__host__ __device__ friend cucomp128 operator-(const double& z1, const cucomp128& z2);
|
||||||
|
__host__ __device__ friend cucomp128 operator*(const double& z1, const cucomp128& z2);
|
||||||
|
__host__ __device__ friend cucomp128 operator/(const double& z1, const cucomp128& z2);
|
||||||
|
|
||||||
__host__ __device__ friend cucomp128 operator-(const cucomp128& z); //negation sign
|
__host__ __device__ friend cucomp128 operator-(const cucomp128& z); //negation sign
|
||||||
|
|
||||||
@ -54,30 +57,42 @@ namespace cmp
|
|||||||
__host__ __device__ bool iszero() const;
|
__host__ __device__ bool iszero() const;
|
||||||
__host__ __device__ double arg() const;
|
__host__ __device__ double arg() const;
|
||||||
__host__ __device__ double mag() const;
|
__host__ __device__ double mag() const;
|
||||||
|
__host__ __device__ double abs() const;
|
||||||
__host__ __device__ cucomp128 conj() const;
|
__host__ __device__ cucomp128 conj() const;
|
||||||
|
|
||||||
|
//accumulation operators
|
||||||
|
__host__ __device__ cucomp128& operator+=(const cucomp128& z);
|
||||||
|
__host__ __device__ cucomp128& operator-=(const cucomp128& z);
|
||||||
|
__host__ __device__ cucomp128& operator*=(const cucomp128& z);
|
||||||
|
__host__ __device__ cucomp128& operator/=(const cucomp128& z);
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128& operator+=(const double& z);
|
||||||
|
__host__ __device__ cucomp128& operator-=(const double& z);
|
||||||
|
__host__ __device__ cucomp128& operator*=(const double& z);
|
||||||
|
__host__ __device__ cucomp128& operator/=(const double& z);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
__host__ __device__ double arg(cucomp128 z);
|
__host__ __device__ double arg(const cucomp128 &z);
|
||||||
|
__host__ __device__ double real(const cucomp128 &z);
|
||||||
__host__ __device__ double real(cucomp128 z);
|
__host__ __device__ double imag(const cucomp128 &z);
|
||||||
__host__ __device__ double imag(cucomp128 z);
|
__host__ __device__ cucomp128 sin(const cucomp128 &z);
|
||||||
__host__ __device__ cucomp128 sin(cucomp128 z);
|
__host__ __device__ cucomp128 cos(const cucomp128 &z);
|
||||||
__host__ __device__ cucomp128 cos(cucomp128 z);
|
__host__ __device__ cucomp128 tan(const cucomp128 &z);
|
||||||
__host__ __device__ cucomp128 tan(cucomp128 z);
|
__host__ __device__ cucomp128 exp(const cucomp128 &z);
|
||||||
__host__ __device__ cucomp128 exp(cucomp128 z);
|
__host__ __device__ cucomp128 log(const cucomp128 &z);
|
||||||
__host__ __device__ cucomp128 log(cucomp128 z);
|
__host__ __device__ double abs(const cucomp128 &z);
|
||||||
__host__ __device__ double abs(cucomp128 z);
|
__host__ __device__ cucomp128 conj(const cucomp128 &z);
|
||||||
__host__ __device__ cucomp128 conj(cucomp128 z);
|
|
||||||
|
|
||||||
// //need hyperbolic trig Functions
|
// //need hyperbolic trig Functions
|
||||||
__host__ __device__ cucomp128 cosh(cucomp128 z);
|
__host__ __device__ cucomp128 cosh(const cucomp128 &z);
|
||||||
__host__ __device__ cucomp128 sinh(cucomp128 z);
|
__host__ __device__ cucomp128 sinh(const cucomp128 &z);
|
||||||
__host__ __device__ cucomp128 tanh(cucomp128 z);
|
__host__ __device__ cucomp128 tanh(const cucomp128 &z);
|
||||||
|
|
||||||
__host__ __device__ cucomp128 pow(cucomp128 z1, cucomp128 z2);
|
__host__ __device__ cucomp128 pow(const cucomp128 &z1, const cucomp128 &z2);
|
||||||
|
|
||||||
// //returns "complex sign" of complex number - 0, or a unit number with same argument
|
// //returns "complex sign" of complex number - 0, or a unit number with same argument
|
||||||
__host__ __device__ cucomp128 csgn(cucomp128 z);
|
__host__ __device__ cucomp128 csgn(const cucomp128 &z);
|
||||||
|
|
||||||
void test_cucomp128_1();
|
void test_cucomp128_1();
|
||||||
|
|
||||||
|
|||||||
@ -5,438 +5,530 @@ namespace amscuda
|
|||||||
namespace cmp
|
namespace cmp
|
||||||
{
|
{
|
||||||
|
|
||||||
__host__ __device__ cucomp128::cucomp128()
|
__host__ __device__ cucomp128::cucomp128()
|
||||||
{
|
|
||||||
real = 0.0;
|
|
||||||
imag = 0.0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128::~cucomp128()
|
|
||||||
{
|
|
||||||
real = 0.0;
|
|
||||||
imag = 0.0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128::cucomp128(const cucomp128 &other)
|
|
||||||
{
|
|
||||||
real = other.real;
|
|
||||||
imag = other.imag;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128::cucomp128(const double &other)
|
|
||||||
{
|
|
||||||
real = other;
|
|
||||||
imag = 0.0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128& cucomp128::operator=(cucomp128& other)
|
|
||||||
{
|
|
||||||
real = other.real;
|
|
||||||
imag = other.imag;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ const cucomp128& cucomp128::operator=(const cucomp128& other)
|
|
||||||
{
|
|
||||||
this->real = other.real;
|
|
||||||
this->imag = other.imag;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128& cucomp128::operator=(double& other)
|
|
||||||
{
|
|
||||||
real = other;
|
|
||||||
imag = 0.0;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ const cucomp128& cucomp128::operator=(const double& other)
|
|
||||||
{
|
|
||||||
this->real = other;
|
|
||||||
this->imag = 0.0;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ double& cucomp128::operator[](int& ind)
|
|
||||||
{
|
|
||||||
if(ind==0)
|
|
||||||
{
|
{
|
||||||
return this->real;
|
real = 0.0;
|
||||||
}
|
imag = 0.0;
|
||||||
else
|
return;
|
||||||
{
|
|
||||||
return this->imag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ const double& cucomp128::operator[](const int& ind) const
|
|
||||||
{
|
|
||||||
if(ind==0)
|
|
||||||
{
|
|
||||||
return this->real;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return this->imag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 cucomp128::operator+(const cucomp128& z)
|
|
||||||
{
|
|
||||||
cucomp128 ret;
|
|
||||||
ret.real = real + z.real;
|
|
||||||
ret.imag = imag + z.imag;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 cucomp128::operator-(const cucomp128& z)
|
|
||||||
{
|
|
||||||
cucomp128 ret;
|
|
||||||
ret.real = real - z.real;
|
|
||||||
ret.imag = imag - z.imag;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 cucomp128::operator*(const cucomp128& z)
|
|
||||||
{
|
|
||||||
cucomp128 ret;
|
|
||||||
ret.real = (real*z.real - imag*z.imag);
|
|
||||||
ret.imag = (imag*z.real + real*z.imag);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 cucomp128::operator/(const cucomp128& z)
|
|
||||||
{
|
|
||||||
cucomp128 ret;
|
|
||||||
double zm2 = z.real*z.real+z.imag*z.imag;
|
|
||||||
|
|
||||||
if(zm2>0.0)
|
|
||||||
{
|
|
||||||
ret.real = (this->real*z.real+this->imag*z.imag)/zm2;
|
|
||||||
ret.imag = (this->imag*z.real-this->real*z.imag)/zm2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret.real = (double) finf;
|
|
||||||
ret.imag = (double) finf;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 cucomp128::operator+(const double& z)
|
|
||||||
{
|
|
||||||
cucomp128 ret;
|
|
||||||
ret.real = this->real + z;
|
|
||||||
ret.imag = this->imag;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
__host__ __device__ cucomp128 cucomp128::operator-(const double& z)
|
|
||||||
{
|
|
||||||
cucomp128 ret;
|
|
||||||
ret.real = real-z;
|
|
||||||
ret.imag = imag;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
__host__ __device__ cucomp128 cucomp128::operator*(const double& z)
|
|
||||||
{
|
|
||||||
cucomp128 ret;
|
|
||||||
ret.real = real*z;
|
|
||||||
ret.imag = imag*z;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
__host__ __device__ cucomp128 cucomp128::operator/(const double& z)
|
|
||||||
{
|
|
||||||
cucomp128 ret;
|
|
||||||
if(z!=0.0f)
|
|
||||||
{
|
|
||||||
ret.real = real/z;
|
|
||||||
ret.imag = imag/z;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret.real = finf;
|
|
||||||
ret.imag = finf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
__host__ __device__ cucomp128::~cucomp128()
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ bool cucomp128::operator==(const cucomp128& z) const
|
|
||||||
{
|
|
||||||
bool ret = 0;
|
|
||||||
if(z.real == real && z.imag == imag)
|
|
||||||
{
|
{
|
||||||
ret = 1;
|
real = 0.0;
|
||||||
|
imag = 0.0;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ bool cucomp128::operator!=(const cucomp128& z) const
|
__host__ __device__ cucomp128::cucomp128(const cucomp128 &other)
|
||||||
{
|
|
||||||
return !(*this==z);
|
|
||||||
}
|
|
||||||
|
|
||||||
//sort first by real value, then by imaginary value
|
|
||||||
//this is done so that an ordering exists, as long as two values aren't equal
|
|
||||||
__host__ __device__ bool cucomp128::operator>(const cucomp128& z) const
|
|
||||||
{
|
|
||||||
bool ret = 0;
|
|
||||||
if(this->real>z.real)
|
|
||||||
{
|
{
|
||||||
ret = 1;
|
real = other.real;
|
||||||
|
imag = other.imag;
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if(this->real==z.real)
|
|
||||||
|
__host__ __device__ cucomp128::cucomp128(const double &other)
|
||||||
{
|
{
|
||||||
if(this->imag>z.imag)
|
real = other;
|
||||||
|
imag = 0.0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128::cucomp128(const double &_real, const double &_imag)
|
||||||
|
{
|
||||||
|
real = _real;
|
||||||
|
imag = _imag;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128& cucomp128::operator=(const cucomp128& other)
|
||||||
|
{
|
||||||
|
real = other.real;
|
||||||
|
imag = other.imag;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128& cucomp128::operator=(const double& other)
|
||||||
|
{
|
||||||
|
real = other;
|
||||||
|
imag = 0.0;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ double& cucomp128::operator[](int& ind)
|
||||||
|
{
|
||||||
|
if(ind==0)
|
||||||
|
{
|
||||||
|
return this->real;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this->imag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ const double& cucomp128::operator[](const int& ind) const
|
||||||
|
{
|
||||||
|
if(ind==0)
|
||||||
|
{
|
||||||
|
return this->real;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this->imag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 cucomp128::operator+(const cucomp128& z) const
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
ret.real = real + z.real;
|
||||||
|
ret.imag = imag + z.imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 cucomp128::operator-(const cucomp128& z) const
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
ret.real = real - z.real;
|
||||||
|
ret.imag = imag - z.imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 cucomp128::operator*(const cucomp128& z) const
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
ret.real = real*z.real - imag*z.imag;
|
||||||
|
ret.imag = imag*z.real + real*z.imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 cucomp128::operator/(const cucomp128& z) const
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
double zm2 = z.real*z.real+z.imag*z.imag;
|
||||||
|
|
||||||
|
// if(zm2>0.0)
|
||||||
|
// {
|
||||||
|
ret.real = (real*z.real+imag*z.imag)/zm2;
|
||||||
|
ret.imag = (imag*z.real-real*z.imag)/zm2;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// ret.real = (double) finf;
|
||||||
|
// ret.imag = (double) finf;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 operator+(const cucomp128& z1, const double& z2)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
ret.real = z1.real+z2;
|
||||||
|
ret.imag = z1.imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 operator-(const cucomp128& z1, const double& z2)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
ret.real = z1.real-z2;
|
||||||
|
ret.imag = z1.imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 operator*(const cucomp128& z1, const double& z2)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
ret.real = z1.real*z2;
|
||||||
|
ret.imag = z1.imag*z2;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 operator/(const cucomp128& z1, const double& z2)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
ret.real = z1.real/z2;
|
||||||
|
ret.imag = z1.imag/z2;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 operator+(const double& z1, const cucomp128& z2)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
ret.real = z1 + z2.real;
|
||||||
|
ret.imag = z2.imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 operator-(const double& z1, const cucomp128& z2)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
ret.real = z1 - z2.real;
|
||||||
|
ret.imag = -z2.imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 operator*(const double& z1, const cucomp128& z2)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
ret.real = z1*z2.real;
|
||||||
|
ret.imag = z1*z2.imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 operator/(const double& z1, const cucomp128& z2)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
double zmg = z2.real*z2.real + z2.imag*z2.imag;
|
||||||
|
ret.real = z1*(z2.real)/zmg;
|
||||||
|
ret.imag = -z1*(z2.imag)/zmg;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ bool cucomp128::operator==(const cucomp128& z) const
|
||||||
|
{
|
||||||
|
bool ret = 0;
|
||||||
|
if(z.real == real && z.imag == imag)
|
||||||
{
|
{
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ bool cucomp128::operator!=(const cucomp128& z) const
|
||||||
|
{
|
||||||
|
return !(*this==z);
|
||||||
|
}
|
||||||
|
|
||||||
|
//sort first by real value, then by imaginary value
|
||||||
|
//this is done so that an ordering exists, as long as two values aren't equal
|
||||||
|
__host__ __device__ bool cucomp128::operator>(const cucomp128& z) const
|
||||||
|
{
|
||||||
|
bool ret = 0;
|
||||||
|
if(this->real>z.real)
|
||||||
|
{
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
else if(this->real==z.real)
|
||||||
|
{
|
||||||
|
if(this->imag>z.imag)
|
||||||
|
{
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ bool cucomp128::operator<(const cucomp128& z) const
|
__host__ __device__ bool cucomp128::operator<(const cucomp128& z) const
|
||||||
{
|
|
||||||
bool ret = 0;
|
|
||||||
if(this->real<z.real)
|
|
||||||
{
|
{
|
||||||
ret = 1;
|
bool ret = 0;
|
||||||
}
|
if(this->real<z.real)
|
||||||
else if(this->real==z.real)
|
|
||||||
{
|
|
||||||
if(this->imag<z.imag)
|
|
||||||
{
|
{
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
else if(this->real==z.real)
|
||||||
|
{
|
||||||
|
if(this->imag<z.imag)
|
||||||
|
{
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
__host__ __device__ cucomp128 operator-(const cucomp128 &z)
|
||||||
{
|
{
|
||||||
ret = 0;
|
cucomp128 ret;
|
||||||
|
ret.real = -z.real;
|
||||||
|
ret.imag = -z.imag;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 operator-(const cucomp128 &z)
|
__host__ __device__ bool cucomp128::operator>=(const cucomp128& z) const
|
||||||
{
|
|
||||||
cucomp128 ret;
|
|
||||||
ret.real = -z.real;
|
|
||||||
ret.imag = -z.imag;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ bool cucomp128::operator>=(const cucomp128& z) const
|
|
||||||
{
|
|
||||||
bool ret = (*this==z || *this>z);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ bool cucomp128::operator<=(const cucomp128& z) const
|
|
||||||
{
|
|
||||||
bool ret = (*this==z || *this<z);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ bool cucomp128::isnan() const
|
|
||||||
{
|
|
||||||
bool ret = 0;
|
|
||||||
if(::isnan(this->real) || ::isnan(this->imag))
|
|
||||||
{
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ bool cucomp128::isinf() const
|
|
||||||
{
|
|
||||||
bool ret = 0;
|
|
||||||
//calls math.h isinf()
|
|
||||||
if(::isinf(this->real) || ::isinf(this->imag))
|
|
||||||
{
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ bool cucomp128::isreal() const
|
|
||||||
{
|
|
||||||
bool ret = 1;
|
|
||||||
if(imag!=0.0f)
|
|
||||||
{
|
{
|
||||||
ret = 0;
|
bool ret = (*this==z || *this>z);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ bool cucomp128::isimag() const
|
__host__ __device__ bool cucomp128::operator<=(const cucomp128& z) const
|
||||||
{
|
|
||||||
bool ret = 1;
|
|
||||||
if(real!=0.0f)
|
|
||||||
{
|
{
|
||||||
ret = 0;
|
bool ret = (*this==z || *this<z);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ bool cucomp128::iszero() const
|
__host__ __device__ bool cucomp128::isnan() const
|
||||||
{
|
|
||||||
bool ret = 1;
|
|
||||||
if(real!=0.0f || imag!=0.0f)
|
|
||||||
{
|
{
|
||||||
ret = 0;
|
bool ret = 0;
|
||||||
|
if(::isnan(this->real) || ::isnan(this->imag))
|
||||||
|
{
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ double cucomp128::arg() const
|
__host__ __device__ bool cucomp128::isinf() const
|
||||||
{
|
{
|
||||||
double ret = 0.0;
|
bool ret = 0;
|
||||||
ret = (double) amscuda::arg((double)real,(double)imag);
|
//calls math.h isinf()
|
||||||
return ret;
|
if(::isinf(this->real) || ::isinf(this->imag))
|
||||||
}
|
{
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
__host__ __device__ double cucomp128::mag() const
|
__host__ __device__ bool cucomp128::isreal() const
|
||||||
{
|
{
|
||||||
double ret = 0.0;
|
bool ret = 1;
|
||||||
ret = ::sqrt(real*real+imag*imag);
|
if(imag!=0.0)
|
||||||
return ret;
|
{
|
||||||
}
|
ret = 0;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp128 cucomp128::conj() const
|
__host__ __device__ bool cucomp128::isimag() const
|
||||||
{
|
{
|
||||||
cucomp128 ret;
|
bool ret = 1;
|
||||||
ret.real = real;
|
if(real!=0.0)
|
||||||
ret.imag = -imag;
|
{
|
||||||
return ret;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
__host__ __device__ double arg(cucomp128 z)
|
__host__ __device__ bool cucomp128::iszero() const
|
||||||
{
|
{
|
||||||
return z.arg();
|
bool ret = 1;
|
||||||
}
|
if(real!=0.0 || imag!=0.0)
|
||||||
|
{
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
__host__ __device__ double abs(cucomp128 z)
|
__host__ __device__ double cucomp128::arg() const
|
||||||
{
|
{
|
||||||
return z.mag();
|
double ret = 0.0;
|
||||||
}
|
ret = (double) amscuda::arg((double)real,(double)imag);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp128 dtocomp(double _r, double _i)
|
__host__ __device__ double cucomp128::mag() const
|
||||||
{
|
{
|
||||||
cucomp128 ret;
|
double ret = 0.0;
|
||||||
ret.real = _r;
|
ret = ::sqrt(real*real+imag*imag);
|
||||||
ret.imag = _i;
|
return ret;
|
||||||
return ret;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ double real(cucomp128 z)
|
__host__ __device__ double cucomp128::abs() const
|
||||||
{
|
{
|
||||||
return z.real;
|
double ret = 0.0;
|
||||||
}
|
ret = ::sqrt(real*real+imag*imag);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
__host__ __device__ double imag(cucomp128 z)
|
__host__ __device__ cucomp128 cucomp128::conj() const
|
||||||
{
|
{
|
||||||
return z.imag;
|
cucomp128 ret;
|
||||||
}
|
ret.real = real;
|
||||||
|
ret.imag = -imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp128 sin(cucomp128 z)
|
__host__ __device__ double arg(const cucomp128 &z)
|
||||||
{
|
{
|
||||||
cucomp128 ret;
|
return z.arg();
|
||||||
cucomp128 im1 = dtocomp(0.0f,1.0f);
|
}
|
||||||
cucomp128 div = dtocomp(0.0f,2.0f);
|
|
||||||
|
|
||||||
ret = (exp(im1*z)-exp(-im1*z))/div;
|
__host__ __device__ double abs(const cucomp128 &z)
|
||||||
|
{
|
||||||
|
return z.mag();
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
__host__ __device__ double real(const cucomp128 &z)
|
||||||
}
|
{
|
||||||
|
return z.real;
|
||||||
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp128 cos(cucomp128 z)
|
__host__ __device__ double imag(const cucomp128 &z)
|
||||||
{
|
{
|
||||||
cucomp128 ret;
|
return z.imag;
|
||||||
cucomp128 im1 = dtocomp(0.0f,1.0f);
|
}
|
||||||
cucomp128 div = dtocomp(2.0f,0.0f);
|
|
||||||
|
|
||||||
ret = (exp(im1*z)+exp(-im1*z))/div;
|
__host__ __device__ cucomp128 sin(const cucomp128 &z)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
cucomp128 im1 = cucomp128(0.0,1.0f);
|
||||||
|
cucomp128 div = cucomp128(0.0,2.0f);
|
||||||
|
|
||||||
return ret;
|
ret = (exp(im1*z)-exp(-im1*z))/div;
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 tan(cucomp128 z)
|
return ret;
|
||||||
{
|
}
|
||||||
return sin(z)/cos(z);
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 exp(cucomp128 z)
|
__host__ __device__ cucomp128 cos(const cucomp128 &z)
|
||||||
{
|
{
|
||||||
cucomp128 ret;
|
cucomp128 ret;
|
||||||
ret.real = ::exp(z.real)*::cos(z.imag);
|
cucomp128 im1 = cucomp128(0.0,1.0f);
|
||||||
ret.imag = ::exp(z.real)*::sin(z.imag);
|
cucomp128 div = cucomp128(2.0f,0.0);
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 log(cucomp128 z)
|
ret = (exp(im1*z)+exp(-im1*z))/div;
|
||||||
{
|
|
||||||
cucomp128 ret;
|
|
||||||
ret.real = ::log(::sqrt(z.real*z.real+z.imag*z.imag));
|
|
||||||
ret.imag = amscuda::arg(z.real,z.imag);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 conj(cucomp128 z)
|
return ret;
|
||||||
{
|
}
|
||||||
return z.conj();
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 cosh(cucomp128 z)
|
__host__ __device__ cucomp128 tan(const cucomp128 &z)
|
||||||
{
|
{
|
||||||
cucomp128 ret;
|
return sin(z)/cos(z);
|
||||||
cucomp128 div = dtocomp(2.0f,0.0f);
|
}
|
||||||
|
|
||||||
ret = (exp(z)+exp(-z))/div;
|
__host__ __device__ cucomp128 exp(const cucomp128 &z)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
ret.real = ::exp(z.real)*::cos(z.imag);
|
||||||
|
ret.imag = ::exp(z.real)*::sin(z.imag);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
__host__ __device__ cucomp128 log(const cucomp128 &z)
|
||||||
}
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
ret.real = ::log(::sqrt(z.real*z.real+z.imag*z.imag));
|
||||||
|
ret.imag = amscuda::arg(z.real,z.imag);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp128 sinh(cucomp128 z)
|
__host__ __device__ cucomp128 conj(const cucomp128 &z)
|
||||||
{
|
{
|
||||||
cucomp128 ret;
|
return z.conj();
|
||||||
cucomp128 div = dtocomp(2.0f,0.0f);
|
}
|
||||||
|
|
||||||
ret = (exp(z)-exp(-z))/div;
|
__host__ __device__ cucomp128 cosh(const cucomp128 &z)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
cucomp128 div = cucomp128(2.0f,0.0);
|
||||||
|
|
||||||
return ret;
|
ret = (exp(z)+exp(-z))/div;
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 tanh(cucomp128 z)
|
return ret;
|
||||||
{
|
}
|
||||||
return sinh(z)/cosh(z);
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp128 pow(cucomp128 z1, cucomp128 z2)
|
__host__ __device__ cucomp128 sinh(const cucomp128 &z)
|
||||||
{
|
{
|
||||||
cucomp128 ret;
|
cucomp128 ret;
|
||||||
if(z1.mag()>0.0)
|
cucomp128 div = cucomp128(2.0f,0.0);
|
||||||
ret = exp(z2*log(z1));
|
|
||||||
else
|
ret = (exp(z)-exp(-z))/div;
|
||||||
ret = dtocomp(0.0f,0.0f);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 tanh(const cucomp128 &z)
|
||||||
|
{
|
||||||
|
return sinh(z)/cosh(z);
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128 pow(const cucomp128 &z1, const cucomp128 &z2)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
if(z1.mag()>0.0)
|
||||||
|
ret = amscuda::cmp::exp(amscuda::cmp::log(z1)*z2);
|
||||||
|
else
|
||||||
|
ret = cucomp128(0.0,0.0);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// //returns "complex sign" of complex number - 0, or a unit number with same argument
|
||||||
|
__host__ __device__ cucomp128 csgn(const cucomp128 &z)
|
||||||
|
{
|
||||||
|
cucomp128 ret;
|
||||||
|
double mag = z.mag();
|
||||||
|
if(mag>0.0)
|
||||||
|
{
|
||||||
|
ret = z;
|
||||||
|
ret = ret/mag;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////
|
||||||
|
//accumulation operators//
|
||||||
|
//////////////////////////
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128& cucomp128::operator+=(const cucomp128& z)
|
||||||
|
{
|
||||||
|
real += z.real;
|
||||||
|
imag += z.imag;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128& cucomp128::operator-=(const cucomp128& z)
|
||||||
|
{
|
||||||
|
real -= z.real;
|
||||||
|
imag -= z.imag;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128& cucomp128::operator*=(const cucomp128& z)
|
||||||
|
{
|
||||||
|
cucomp128 t = (*this);
|
||||||
|
real = t.real*z.real - t.imag*z.imag;
|
||||||
|
imag = t.real*z.imag + t.imag*z.real;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128& cucomp128::operator/=(const cucomp128& z)
|
||||||
|
{
|
||||||
|
amscuda::cmp::cucomp128 t = *this;
|
||||||
|
*this = t/z;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128& cucomp128::operator+=(const double& z)
|
||||||
|
{
|
||||||
|
real += z;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128& cucomp128::operator-=(const double& z)
|
||||||
|
{
|
||||||
|
real -= z;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128& cucomp128::operator*=(const double& z)
|
||||||
|
{
|
||||||
|
real *= z;
|
||||||
|
imag *= z;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp128& cucomp128::operator/=(const double& z)
|
||||||
|
{
|
||||||
|
real /= z;
|
||||||
|
imag /= z;
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void test_cucomp128_1()
|
void test_cucomp128_1()
|
||||||
@ -444,15 +536,15 @@ void test_cucomp128_1()
|
|||||||
cucomp128 z1;
|
cucomp128 z1;
|
||||||
cucomp128 a,b,c;
|
cucomp128 a,b,c;
|
||||||
double d1;
|
double d1;
|
||||||
double f1;
|
float f1;
|
||||||
|
|
||||||
printf("sizeof double=%ld\n",(long)(8*sizeof(f1)));
|
printf("sizeof float=%ld\n",(long)(8*sizeof(f1)));
|
||||||
printf("sizeof double=%ld\n",(long)(8*sizeof(d1)));
|
printf("sizeof double=%ld\n",(long)(8*sizeof(d1)));
|
||||||
printf("sizeof complex=%ld\n",(long)(8*sizeof(z1)));
|
printf("sizeof complex=%ld\n",(long)(8*sizeof(z1)));
|
||||||
printf("sizeof cucomp128=%ld\n",(long)(8*sizeof(a)));
|
printf("sizeof cucomp128=%ld\n",(long)(8*sizeof(a)));
|
||||||
|
|
||||||
a = dtocomp(1.0,1.0);
|
a = cucomp128(1.0,1.0);
|
||||||
b = dtocomp(1.0,-1.0);
|
b = cucomp128(1.0,-1.0);
|
||||||
|
|
||||||
printf("a=%1.4f + %1.4fi\n",a[0],a[1]);
|
printf("a=%1.4f + %1.4fi\n",a[0],a[1]);
|
||||||
printf("b=%1.4f + %1.4fi\n",b[0],b[1]);
|
printf("b=%1.4f + %1.4fi\n",b[0],b[1]);
|
||||||
|
|||||||
@ -329,7 +329,7 @@ __host__ __device__ bool cucomp64::iszero() const
|
|||||||
__host__ __device__ float cucomp64::arg() const
|
__host__ __device__ float cucomp64::arg() const
|
||||||
{
|
{
|
||||||
float ret = 0.0f;
|
float ret = 0.0f;
|
||||||
ret = (float) amscuda::arg((double)real,(double)imag);
|
ret = (float) amscuda::argf(real,imag);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user