27 #include <cuComplex.h>
33 template <
typename ValueType>
35 inline ValueType
cos(ValueType
x){
38 template <
typename ValueType>
40 inline ValueType
sin(ValueType
x){
43 template <
typename ValueType>
45 inline ValueType
tan(ValueType
x){
48 template <
typename ValueType>
50 inline ValueType
acos(ValueType
x){
53 template <
typename ValueType>
55 inline ValueType
asin(ValueType
x){
58 template <
typename ValueType>
60 inline ValueType
atan(ValueType
x){
63 template <
typename ValueType>
65 inline ValueType
atan2(ValueType
x,ValueType
y){
68 template <
typename ValueType>
70 inline ValueType
cosh(ValueType
x){
73 template <
typename ValueType>
75 inline ValueType
sinh(ValueType
x){
78 template <
typename ValueType>
80 inline ValueType
tanh(ValueType
x){
83 template <
typename ValueType>
85 inline ValueType
exp(ValueType
x){
88 template <
typename ValueType>
90 inline ValueType
log(ValueType
x){
93 template <
typename ValueType>
98 template <
typename ValueType,
typename ExponentType>
100 inline ValueType
pow(ValueType
x, ExponentType e){
103 template <
typename ValueType>
108 template <
typename ValueType>
110 inline ValueType
abs(ValueType
x){
113 template <
typename ValueType>
120 template <>
struct complex<float>;
121 template <>
struct complex<double>;
125 template<
typename ValueType>
129 template<
typename ValueType>
133 template<
typename ValueType>
138 template<
typename ValueType>
142 template<
typename ValueType>
148 template <
typename ValueType>
151 template <
typename ValueType>
154 template <
typename ValueType>
158 template <
typename ValueType>
169 template <
typename ValueType>
172 template <
typename ValueType>
175 template <
typename ValueType>
179 template <
typename ValueType>
182 template <
typename ValueType>
185 template <
typename ValueType>
190 template <
typename ValueType>
193 template <
typename ValueType>
199 template <
typename ValueType>
203 template <
typename ValueType>
207 template <
typename ValueType>
211 template <
typename ValueType>
215 template <
typename ValueType>
219 template <
typename ValueType>
223 template <
typename ValueType>
227 template <
typename ValueType>
232 template <
typename ValueType>
236 template <
typename ValueType>
240 template <
typename ValueType>
244 template <
typename ValueType>
248 template <
typename ValueType>
252 template <
typename ValueType>
259 template <
typename ValueType>
263 template <
typename ValueType>
267 template <
typename ValueType>
271 template <
typename ValueType>
275 template <
typename ValueType>
279 template <
typename ValueType>
286 template<
typename ValueType,
class charT,
class traits>
287 std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os,
const complex<ValueType>& z);
288 template<
typename ValueType,
typename charT,
class traits>
289 std::basic_istream<charT, traits>&
294 template<
typename ValueType,
class charT,
class traits>
295 std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os,
const complex<ValueType>& z)
297 os <<
'(' << z.
real() <<
',' << z.imag() <<
')';
301 template<
typename ValueType,
typename charT,
class traits>
302 std::basic_istream<charT, traits>&
322 is.setstate(std::ios_base::failbit);
331 is.setstate(std::ios_base::failbit);
343 template <
typename T>
347 template <
typename T>
352 template <
typename ValueType>
382 template <
typename T>
421 __host__ __device__
inline ValueType
real()
const volatile;
422 __host__ __device__
inline ValueType
imag()
const volatile;
423 __host__ __device__
inline ValueType
real()
const;
424 __host__ __device__
inline ValueType
imag()
const;
425 __host__ __device__
inline void real(ValueType)
volatile;
426 __host__ __device__
inline void imag(ValueType)
volatile;
427 __host__ __device__
inline void real(ValueType);
428 __host__ __device__
inline void imag(ValueType);
435 struct complex <float> :
public cuFloatComplex
452 : cuFloatComplex(z){}
456 : cuFloatComplex(z){}
466 template <
typename T>
475 template <
typename T>
521 __host__ __device__
inline float real()
const volatile{
return x; }
522 __host__ __device__
inline float imag()
const volatile{
return y; }
523 __host__ __device__
inline float real()
const{
return x; }
524 __host__ __device__
inline float imag()
const{
return y; }
525 __host__ __device__
inline void real(
float re)
volatile{
x = re; }
526 __host__ __device__
inline void imag(
float im)
volatile{
y = im; }
527 __host__ __device__
inline void real(
float re){
x = re; }
528 __host__ __device__
inline void imag(
float im){
y = im; }
531 inline operator std::complex<float>()
const {
return std::complex<float>(
real(),
imag()); }
536 struct complex <double> :
public cuDoubleComplex
553 : cuDoubleComplex(z) {}
557 : cuDoubleComplex(z) {}
567 template <
typename T>
576 template <
typename T>
622 __host__ __device__
inline double real()
const volatile {
return x; }
623 __host__ __device__
inline double imag()
const volatile {
return y; }
624 __host__ __device__
inline double real()
const {
return x; }
625 __host__ __device__
inline double imag()
const {
return y; }
626 __host__ __device__
inline void real(
double re)
volatile{
x = re; }
627 __host__ __device__
inline void imag(
double im)
volatile{
y = im; }
628 __host__ __device__
inline void real(
double re){
x = re; }
629 __host__ __device__
inline void imag(
double im){
y = im; }
632 inline operator std::complex<double>()
const {
return std::complex<double>(
real(),
imag()); }
642 template<
typename ValueType>
650 template<
typename ValueType>
658 template <
typename ValueType>
664 template <
typename ValueType>
671 template <
typename ValueType>
677 template <
typename ValueType>
683 template <
typename ValueType>
690 template <
typename ValueType>
699 template <
typename ValueType>
706 template <
typename ValueType>
714 template <
typename ValueType>
717 const ValueType cross_norm = lhs.
real() * rhs.
real() + lhs.
imag() * rhs.
imag();
718 const ValueType rhs_norm =
norm(rhs);
726 return cuCdivf(lhs,rhs);
732 return cuCdiv(lhs,rhs);
735 template <
typename ValueType>
742 template <
typename ValueType>
745 const ValueType cross_norm = lhs * rhs.
real();
746 const ValueType rhs_norm =
norm(rhs);
763 template <
typename ValueType>
768 template <
typename ValueType>
771 return rhs*-ValueType(1);
775 template <
typename ValueType>
783 template <
typename ValueType>
786 if(lhs == rhs.
real() && rhs.
imag() == 0){
791 template <
typename ValueType>
794 if(lhs.
real() == rhs && lhs.
imag() == 0){
800 template <
typename ValueType>
803 return !(lhs == rhs);
806 template <
typename ValueType>
809 return !(lhs == rhs);
812 template <
typename ValueType>
815 return !(lhs == rhs);
819 template <
typename ValueType>
825 template <
typename ValueType>
841 template <
typename ValueType>
857 template <
typename ValueType>
863 template <
typename ValueType>
872 return complex<float>(magnitude * ::cosf(angle),magnitude * ::sinf(angle));
882 template <
typename ValueType>
885 const ValueType re = z.
real();
886 const ValueType im = z.
imag();
893 const float re = z.
real();
894 const float im = z.
imag();
895 return complex<float>(cosf(re) * coshf(im), -sinf(re) * sinhf(im));
898 template <
typename ValueType>
901 const ValueType re = z.
real();
902 const ValueType im = z.
imag();
909 const float re = z.
real();
910 const float im = z.
imag();
911 return complex<float>(::coshf(re) * ::cosf(im), ::sinhf(re) * ::sinf(im));
915 template <
typename ValueType>
927 template <
typename ValueType>
940 template <
typename ValueType>
945 return log(z)/ValueType(2.30258509299404568402);
949 template <
typename ValueType>
952 return exp(
log(z)*exponent);
955 template <
typename ValueType>
958 return exp(
log(z)*exponent);
961 template <
typename ValueType>
964 return exp(::
log(x)*exponent);
970 return exp(::logf(x)*exponent);
973 template <
typename ValueType>
976 return exp(
log(z)*ValueType(exponent));
979 template <
typename ValueType>
982 const ValueType re = z.
real();
983 const ValueType im = z.
imag();
990 const float re = z.
real();
991 const float im = z.
imag();
992 return complex<float>(::sinf(re) * ::coshf(im), ::cosf(re) * ::sinhf(im));
995 template <
typename ValueType>
998 const ValueType re = z.
real();
999 const ValueType im = z.
imag();
1006 const float re = z.
real();
1007 const float im = z.
imag();
1008 return complex<float>(::sinhf(re) * ::cosf(im), ::coshf(re) * ::sinf(im));
1011 template <
typename ValueType>
1017 template <
typename ValueType>
1023 template <
typename ValueType>
1029 template <
typename ValueType>
1033 return (
exp(ValueType(2)*z)-ValueType(1))/(
exp(ValueType(2)*z)+ValueType(1));
1039 template <
typename ValueType>
1046 template <
typename ValueType>
1050 return -i*
asinh(i*z);
1053 template <
typename ValueType>
1057 return -i*
atanh(i*z);
1060 template <
typename ValueType>
1064 ValueType(2.0) * z.
real() * z.
imag());
1066 if (z.
real() < ValueType(0.0)){
1071 if (ret.
real() < ValueType(0.0)){
1085 template <
typename ValueType>
1088 return log(
sqrt(z*z+ValueType(1))+z);
1091 template <
typename ValueType>
1094 ValueType imag2 = z.
imag() * z.
imag();
1095 ValueType n = ValueType(1.0) + z.
real();
1098 ValueType d = ValueType(1.0) - z.
real();
1102 d = ValueType(1.0) - z.
real() * z.
real() - imag2;
1104 ret.
imag(ValueType(0.5) * ::
atan2(ValueType(2.0) * z.
imag(), d));
1109 template <
typename ValueType>
1113 float n = float(1.0) + z.
real();
1116 float d = float(1.0) - z.
real();
1120 d = float(1.0) - z.
real() * z.
real() - imag2;
1122 ret.
imag(
float(0.5) * ::atan2f(
float(2.0) * z.
imag(), d));
__host__ __device__ complex< float > sinh(const complex< float > &z)
__host__ __device__ ValueType tanh(ValueType x)
__host__ __device__ ValueType sinh(ValueType x)
__host__ __device__ complex< float > & operator-=(const complex< float > z)
__host__ __device__ complex< double > & operator=(const complex< T > z)
__host__ __device__ ValueType norm(const complex< ValueType > &z)
Returns the magnitude of z squared.
__host__ __device__ ValueType atan(ValueType x)
__host__ __device__ complex< double > & operator-=(const complex< double > z)
__host__ __device__ ValueType exp(ValueType x)
__host__ __device__ complex< float > & operator*=(const complex< float > z)
__host__ __device__ ValueType cosh(ValueType x)
__host__ __device__ void real(double re) volatile
__host__ __device__ ValueType sqrt(ValueType x)
__host__ __device__ complex< float > cosh(const complex< float > &z)
__host__ __device__ void real(float re)
__host__ __device__ ValueType imag() const volatile
__host__ __device__ complex< ValueType > tanh(const complex< ValueType > &z)
__host__ __device__ void imag(float im)
__host__ __device__ float real() const
std::basic_istream< charT, traits > & operator>>(std::basic_istream< charT, traits > &is, complex< ValueType > &z)
__host__ __device__ ValueType tan(ValueType x)
__host__ __device__ double imag() const
__host__ __device__ void imag(double im) volatile
__host__ __device__ complex< ValueType > & operator+=(const complex< ValueType > z)
__host__ __device__ void real(float re) volatile
__host__ __device__ complex< float > & operator=(const complex< T > z)
__host__ __device__ complex< ValueType > tan(const complex< ValueType > &z)
__host__ __device__ float imag() const
__host__ __device__ complex< ValueType > & operator-=(const complex< ValueType > z)
__host__ __device__ complex< ValueType > & operator*=(const complex< ValueType > z)
__host__ __device__ complex< ValueType > asin(const complex< ValueType > &z)
__host__ __device__ void imag(float im) volatile
__host__ __device__ ValueType sin(ValueType x)
__host__ __device__ complex< ValueType > acos(const complex< ValueType > &z)
__host__ __device__ complex< float > sin(const complex< float > &z)
__host__ __device__ complex< ValueType > operator-(const complex< ValueType > &lhs, const complex< ValueType > &rhs)
__host__ __device__ void real(double re)
__host__ __device__ ValueType atan2(ValueType x, ValueType y)
__host__ __device__ complex< float > cos(const complex< float > &z)
__host__ __device__ ValueType pow(ValueType x, ExponentType e)
__host__ __device__ void imag(double im)
__host__ __device__ float imag() const volatile
__host__ __device__ ValueType real() const volatile
__host__ __device__ complex< float > & operator/=(const complex< float > z)
__host__ __device__ complex< float > exp(const complex< float > &z)
__host__ __device__ complex< float > log(const complex< float > &z)
__host__ __device__ complex< double > & operator/=(const complex< double > z)
__host__ __device__ complex< ValueType > log10(const complex< ValueType > &z)
__host__ __device__ complex< ValueType > & operator/=(const complex< ValueType > z)
__host__ __device__ complex< ValueType > asinh(const complex< ValueType > &z)
__host__ __device__ complex< ValueType > & operator=(const complex< T > z)
__host__ __device__ ValueType log(ValueType x)
__host__ __device__ double imag() const volatile
__host__ __device__ complex< ValueType > operator/(const complex< ValueType > &lhs, const complex< ValueType > &rhs)
__host__ __device__ volatile complex< float > & operator=(const complex< T > z) volatile
__host__ __device__ ValueType log10(ValueType x)
__host__ __device__ complex< ValueType > operator*(const complex< ValueType > &lhs, const complex< ValueType > &rhs)
__host__ __device__ double abs(const complex< double > &z)
__host__ __device__ complex< ValueType > atan(const complex< ValueType > &z)
__host__ __device__ ValueType arg(const complex< ValueType > &z)
Returns the phase angle of z.
__host__ __device__ complex< float > sqrt(const complex< float > &z)
__host__ __device__ double real() const
__host__ __device__ ValueType cos(ValueType x)
__host__ __device__ complex< ValueType > polar(const ValueType &m, const ValueType &theta=0)
Returns the complex with magnitude m and angle theta in radians.
__host__ __device__ ValueType abs(ValueType x)
__host__ __device__ ValueType acos(ValueType x)
__host__ __device__ complex< float > pow(const float &x, const complex< float > &exponent)
__host__ __device__ ValueType conj(ValueType x)
__host__ __device__ complex< ValueType > operator+(const complex< ValueType > &lhs, const complex< ValueType > &rhs)
__host__ __device__ complex< double > & operator*=(const complex< double > z)
__host__ __device__ bool operator!=(const complex< ValueType > &lhs, const complex< ValueType > &rhs)
__host__ __device__ complex< ValueType > atanh(const complex< ValueType > &z)
__host__ __device__ complex< float > & operator+=(const complex< float > z)
__host__ __device__ volatile complex< double > & operator=(const complex< T > z) volatile
__host__ __device__ double real() const volatile
__host__ __device__ float real() const volatile
__host__ __device__ complex< ValueType > acosh(const complex< ValueType > &z)
__host__ __device__ bool operator==(const complex< ValueType > &lhs, const complex< ValueType > &rhs)
__host__ __device__ ValueType asin(ValueType x)
__host__ __device__ complex< double > & operator+=(const complex< double > z)