polishing cucomp64 type
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.
Binary file not shown.
Binary file not shown.
@ -18,23 +18,26 @@ namespace cmp
|
|||||||
__host__ __device__ explicit cucomp64(const float &other);
|
__host__ __device__ explicit cucomp64(const float &other);
|
||||||
__host__ __device__ explicit cucomp64(const float &_real, const float &_imag);
|
__host__ __device__ explicit cucomp64(const float &_real, const float &_imag);
|
||||||
|
|
||||||
__host__ __device__ cucomp64& operator=(cucomp64& other);
|
__host__ __device__ cucomp64& operator=(const cucomp64& other);
|
||||||
__host__ __device__ const cucomp64& operator=(const cucomp64& other);
|
__host__ __device__ cucomp64& operator=(const float& other);
|
||||||
__host__ __device__ cucomp64& operator=(float& other);
|
|
||||||
__host__ __device__ const cucomp64& operator=(const float& other);
|
|
||||||
|
|
||||||
__host__ __device__ float& operator[](int& ind);
|
__host__ __device__ float& operator[](int& ind);
|
||||||
__host__ __device__ const float& operator[](const int& ind) const;
|
__host__ __device__ const float& operator[](const int& ind) const;
|
||||||
|
|
||||||
__host__ __device__ cucomp64 operator+(const cucomp64& z);
|
__host__ __device__ cucomp64 operator+(const cucomp64& z) const;
|
||||||
__host__ __device__ cucomp64 operator-(const cucomp64& z);
|
__host__ __device__ cucomp64 operator-(const cucomp64& z) const;
|
||||||
__host__ __device__ cucomp64 operator*(const cucomp64& z);
|
__host__ __device__ cucomp64 operator*(const cucomp64& z) const;
|
||||||
__host__ __device__ cucomp64 operator/(const cucomp64& z);
|
__host__ __device__ cucomp64 operator/(const cucomp64& z) const;
|
||||||
|
|
||||||
__host__ __device__ cucomp64 operator+(const float& z);
|
__host__ __device__ friend cucomp64 operator+(const cucomp64& z1, const float& z2);
|
||||||
__host__ __device__ cucomp64 operator-(const float& z);
|
__host__ __device__ friend cucomp64 operator-(const cucomp64& z1, const float& z2);
|
||||||
__host__ __device__ cucomp64 operator*(const float& z);
|
__host__ __device__ friend cucomp64 operator*(const cucomp64& z1, const float& z2);
|
||||||
__host__ __device__ cucomp64 operator/(const float& z);
|
__host__ __device__ friend cucomp64 operator/(const cucomp64& z1, const float& z2);
|
||||||
|
|
||||||
|
__host__ __device__ friend cucomp64 operator+(const float& z1, const cucomp64& z2);
|
||||||
|
__host__ __device__ friend cucomp64 operator-(const float& z1, const cucomp64& z2);
|
||||||
|
__host__ __device__ friend cucomp64 operator*(const float& z1, const cucomp64& z2);
|
||||||
|
__host__ __device__ friend cucomp64 operator/(const float& z1, const cucomp64& z2);
|
||||||
|
|
||||||
__host__ __device__ friend cucomp64 operator-(const cucomp64& z); //negation sign
|
__host__ __device__ friend cucomp64 operator-(const cucomp64& z); //negation sign
|
||||||
|
|
||||||
|
|||||||
@ -41,34 +41,21 @@ __host__ __device__ cucomp64::cucomp64(const float &_real, const float &_imag)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64& cucomp64::operator=(cucomp64& other)
|
__host__ __device__ cucomp64& cucomp64::operator=(const cucomp64& other)
|
||||||
{
|
{
|
||||||
real = other.real;
|
real = other.real;
|
||||||
imag = other.imag;
|
imag = other.imag;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ const cucomp64& cucomp64::operator=(const cucomp64& other)
|
|
||||||
{
|
|
||||||
this->real = other.real;
|
|
||||||
this->imag = other.imag;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ cucomp64& cucomp64::operator=(float& other)
|
__host__ __device__ cucomp64& cucomp64::operator=(const float& other)
|
||||||
{
|
{
|
||||||
real = other;
|
real = other;
|
||||||
imag = 0.0f;
|
imag = 0.0f;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ const cucomp64& cucomp64::operator=(const float& other)
|
|
||||||
{
|
|
||||||
this->real = other;
|
|
||||||
this->imag = 0.0f;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
__host__ __device__ float& cucomp64::operator[](int& ind)
|
__host__ __device__ float& cucomp64::operator[](int& ind)
|
||||||
{
|
{
|
||||||
if(ind==0)
|
if(ind==0)
|
||||||
@ -93,7 +80,7 @@ __host__ __device__ const float& cucomp64::operator[](const int& ind) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64 cucomp64::operator+(const cucomp64& z)
|
__host__ __device__ cucomp64 cucomp64::operator+(const cucomp64& z) const
|
||||||
{
|
{
|
||||||
cucomp64 ret;
|
cucomp64 ret;
|
||||||
ret.real = real + z.real;
|
ret.real = real + z.real;
|
||||||
@ -101,7 +88,7 @@ __host__ __device__ cucomp64 cucomp64::operator+(const cucomp64& z)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64 cucomp64::operator-(const cucomp64& z)
|
__host__ __device__ cucomp64 cucomp64::operator-(const cucomp64& z) const
|
||||||
{
|
{
|
||||||
cucomp64 ret;
|
cucomp64 ret;
|
||||||
ret.real = real - z.real;
|
ret.real = real - z.real;
|
||||||
@ -109,68 +96,95 @@ __host__ __device__ cucomp64 cucomp64::operator-(const cucomp64& z)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64 cucomp64::operator*(const cucomp64& z)
|
__host__ __device__ cucomp64 cucomp64::operator*(const cucomp64& z) const
|
||||||
{
|
{
|
||||||
cucomp64 ret;
|
cucomp64 ret;
|
||||||
ret.real = (real*z.real - imag*z.imag);
|
ret.real = real*z.real - imag*z.imag;
|
||||||
ret.imag = (imag*z.real + real*z.imag);
|
ret.imag = imag*z.real + real*z.imag;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64 cucomp64::operator/(const cucomp64& z)
|
__host__ __device__ cucomp64 cucomp64::operator/(const cucomp64& z) const
|
||||||
{
|
{
|
||||||
cucomp64 ret;
|
cucomp64 ret;
|
||||||
float zm2 = z.real*z.real+z.imag*z.imag;
|
float zm2 = z.real*z.real+z.imag*z.imag;
|
||||||
|
|
||||||
if(zm2>0.0)
|
// if(zm2>0.0)
|
||||||
{
|
// {
|
||||||
ret.real = (this->real*z.real+this->imag*z.imag)/zm2;
|
ret.real = (real*z.real+imag*z.imag)/zm2;
|
||||||
ret.imag = (this->imag*z.real-this->real*z.imag)/zm2;
|
ret.imag = (imag*z.real-real*z.imag)/zm2;
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
ret.real = (float) finf;
|
// ret.real = (float) finf;
|
||||||
ret.imag = (float) finf;
|
// ret.imag = (float) finf;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64 cucomp64::operator+(const float& z)
|
__host__ __device__ cucomp64 operator+(const cucomp64& z1, const float& z2)
|
||||||
{
|
{
|
||||||
cucomp64 ret;
|
cucomp64 ret;
|
||||||
ret.real = this->real + z;
|
ret.real = z1.real+z2;
|
||||||
ret.imag = this->imag;
|
ret.imag = z1.imag;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
__host__ __device__ cucomp64 cucomp64::operator-(const float& z)
|
|
||||||
{
|
|
||||||
cucomp64 ret;
|
|
||||||
ret.real = real-z;
|
|
||||||
ret.imag = imag;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
__host__ __device__ cucomp64 cucomp64::operator*(const float& z)
|
|
||||||
{
|
|
||||||
cucomp64 ret;
|
|
||||||
ret.real = real*z;
|
|
||||||
ret.imag = imag*z;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
__host__ __device__ cucomp64 cucomp64::operator/(const float& z)
|
|
||||||
{
|
|
||||||
cucomp64 ret;
|
|
||||||
if(z!=0.0f)
|
|
||||||
{
|
|
||||||
ret.real = real/z;
|
|
||||||
ret.imag = imag/z;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret.real = finf;
|
|
||||||
ret.imag = finf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
__host__ __device__ cucomp64 operator-(const cucomp64& z1, const float& z2)
|
||||||
|
{
|
||||||
|
cucomp64 ret;
|
||||||
|
ret.real = z1.real-z2;
|
||||||
|
ret.imag = z1.imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp64 operator*(const cucomp64& z1, const float& z2)
|
||||||
|
{
|
||||||
|
cucomp64 ret;
|
||||||
|
ret.real = z1.real*z2;
|
||||||
|
ret.imag = z1.imag*z2;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp64 operator/(const cucomp64& z1, const float& z2)
|
||||||
|
{
|
||||||
|
cucomp64 ret;
|
||||||
|
ret.real = z1.real/z2;
|
||||||
|
ret.imag = z1.imag/z2;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp64 operator+(const float& z1, const cucomp64& z2)
|
||||||
|
{
|
||||||
|
cucomp64 ret;
|
||||||
|
ret.real = z1 + z2.real;
|
||||||
|
ret.imag = z2.imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp64 operator-(const float& z1, const cucomp64& z2)
|
||||||
|
{
|
||||||
|
cucomp64 ret;
|
||||||
|
ret.real = z1 - z2.real;
|
||||||
|
ret.imag = -z2.imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp64 operator*(const float& z1, const cucomp64& z2)
|
||||||
|
{
|
||||||
|
cucomp64 ret;
|
||||||
|
ret.real = z1*z2.real;
|
||||||
|
ret.imag = z1*z2.imag;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
__host__ __device__ cucomp64 operator/(const float& z1, const cucomp64& z2)
|
||||||
|
{
|
||||||
|
cucomp64 ret;
|
||||||
|
float zmg = z2.real*z2.real + z2.imag*z2.imag;
|
||||||
|
ret.real = z1*(z2.real)/zmg;
|
||||||
|
ret.imag = -z1*(z2.imag)/zmg;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,42 +477,56 @@ __host__ __device__ cucomp64 csgn(const cucomp64 &z)
|
|||||||
|
|
||||||
__host__ __device__ cucomp64& cucomp64::operator+=(const cucomp64& z)
|
__host__ __device__ cucomp64& cucomp64::operator+=(const cucomp64& z)
|
||||||
{
|
{
|
||||||
|
real += z.real;
|
||||||
|
imag += z.imag;
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64& cucomp64::operator-=(const cucomp64& z)
|
__host__ __device__ cucomp64& cucomp64::operator-=(const cucomp64& z)
|
||||||
{
|
{
|
||||||
|
real -= z.real;
|
||||||
|
imag -= z.imag;
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64& cucomp64::operator*=(const cucomp64& z)
|
__host__ __device__ cucomp64& cucomp64::operator*=(const cucomp64& z)
|
||||||
{
|
{
|
||||||
|
cucomp64 t = (*this);
|
||||||
|
real = t.real*z.real - t.imag*z.imag;
|
||||||
|
imag = t.real*z.imag + t.imag*z.real;
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64& cucomp64::operator/=(const cucomp64& z)
|
__host__ __device__ cucomp64& cucomp64::operator/=(const cucomp64& z)
|
||||||
{
|
{
|
||||||
|
amscuda::cmp::cucomp64 t = *this;
|
||||||
|
*this = t/z;
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64& cucomp64::operator+=(const float& z)
|
__host__ __device__ cucomp64& cucomp64::operator+=(const float& z)
|
||||||
{
|
{
|
||||||
|
real += z;
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64& cucomp64::operator-=(const float& z)
|
__host__ __device__ cucomp64& cucomp64::operator-=(const float& z)
|
||||||
{
|
{
|
||||||
|
real -= z;
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64& cucomp64::operator*=(const float& z)
|
__host__ __device__ cucomp64& cucomp64::operator*=(const float& z)
|
||||||
{
|
{
|
||||||
|
real *= z;
|
||||||
|
imag *= z;
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
__host__ __device__ cucomp64& cucomp64::operator/=(const float& z)
|
__host__ __device__ cucomp64& cucomp64::operator/=(const float& z)
|
||||||
{
|
{
|
||||||
|
real /= z;
|
||||||
|
imag /= z;
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user