polishing cucomp64 type

This commit is contained in:
2026-04-11 12:18:19 -04:00
parent f315dfb6f6
commit 018d75a67d
19 changed files with 105 additions and 74 deletions

View File

@ -41,34 +41,21 @@ __host__ __device__ cucomp64::cucomp64(const float &_real, const float &_imag)
return;
}
__host__ __device__ cucomp64& cucomp64::operator=(cucomp64& other)
__host__ __device__ cucomp64& cucomp64::operator=(const cucomp64& other)
{
real = other.real;
imag = other.imag;
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;
imag = 0.0f;
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)
{
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;
ret.real = real + z.real;
@ -101,7 +88,7 @@ __host__ __device__ cucomp64 cucomp64::operator+(const cucomp64& z)
return ret;
}
__host__ __device__ cucomp64 cucomp64::operator-(const cucomp64& z)
__host__ __device__ cucomp64 cucomp64::operator-(const cucomp64& z) const
{
cucomp64 ret;
ret.real = real - z.real;
@ -109,68 +96,95 @@ __host__ __device__ cucomp64 cucomp64::operator-(const cucomp64& z)
return ret;
}
__host__ __device__ cucomp64 cucomp64::operator*(const cucomp64& z)
__host__ __device__ cucomp64 cucomp64::operator*(const cucomp64& z) const
{
cucomp64 ret;
ret.real = (real*z.real - imag*z.imag);
ret.imag = (imag*z.real + real*z.imag);
ret.real = real*z.real - imag*z.imag;
ret.imag = imag*z.real + real*z.imag;
return ret;
}
__host__ __device__ cucomp64 cucomp64::operator/(const cucomp64& z)
__host__ __device__ cucomp64 cucomp64::operator/(const cucomp64& z) const
{
cucomp64 ret;
float 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 = (float) finf;
ret.imag = (float) finf;
}
// 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 = (float) finf;
// ret.imag = (float) finf;
// }
return ret;
}
__host__ __device__ cucomp64 cucomp64::operator+(const float& z)
__host__ __device__ cucomp64 operator+(const cucomp64& z1, const float& z2)
{
cucomp64 ret;
ret.real = this->real + z;
ret.imag = this->imag;
ret.real = z1.real+z2;
ret.imag = z1.imag;
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;
}
@ -463,42 +477,56 @@ __host__ __device__ cucomp64 csgn(const cucomp64 &z)
__host__ __device__ cucomp64& cucomp64::operator+=(const cucomp64& z)
{
real += z.real;
imag += z.imag;
return (*this);
}
__host__ __device__ cucomp64& cucomp64::operator-=(const cucomp64& z)
{
real -= z.real;
imag -= z.imag;
return (*this);
}
__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);
}
__host__ __device__ cucomp64& cucomp64::operator/=(const cucomp64& z)
{
amscuda::cmp::cucomp64 t = *this;
*this = t/z;
return (*this);
}
__host__ __device__ cucomp64& cucomp64::operator+=(const float& z)
{
real += z;
return (*this);
}
__host__ __device__ cucomp64& cucomp64::operator-=(const float& z)
{
real -= z;
return (*this);
}
__host__ __device__ cucomp64& cucomp64::operator*=(const float& z)
{
real *= z;
imag *= z;
return (*this);
}
__host__ __device__ cucomp64& cucomp64::operator/=(const float& z)
{
real /= z;
imag /= z;
return (*this);
}