35 namespace colorspinor {
44 template <
typename ValueType>
46 inline ValueType
cos(ValueType x){
49 template <
typename ValueType>
51 inline ValueType
sin(ValueType x){
54 template <
typename ValueType>
56 inline ValueType
tan(ValueType x){
59 template <
typename ValueType>
61 inline ValueType
acos(ValueType x){
64 template <
typename ValueType>
66 inline ValueType
asin(ValueType x){
69 template <
typename ValueType>
71 inline ValueType
atan(ValueType x){
74 template <
typename ValueType>
76 inline ValueType
atan2(ValueType x,ValueType y){
79 template <
typename ValueType>
81 inline ValueType
cosh(ValueType x){
84 template <
typename ValueType>
86 inline ValueType
sinh(ValueType x){
89 template <
typename ValueType>
91 inline ValueType
tanh(ValueType x){
94 template <
typename ValueType>
96 inline ValueType
exp(ValueType x){
99 template <
typename ValueType>
101 inline ValueType
log(ValueType x){
104 template <
typename ValueType>
106 inline ValueType
log10(ValueType x){
109 template <
typename ValueType,
typename ExponentType>
111 inline ValueType
pow(ValueType x, ExponentType e){
112 #if (CUDA_VERSION < 7050) 113 return std::pow(x,static_cast<ValueType>(e));
118 template <
typename ValueType>
120 inline ValueType
sqrt(ValueType x){
123 template <
typename ValueType>
125 inline ValueType
abs(ValueType x){
128 template <
typename ValueType>
130 inline ValueType
conj(ValueType x){
134 template <
typename ValueType>
struct complex;
140 template<
typename ValueType>
142 ValueType
abs(
const complex<ValueType>& z);
144 template<
typename ValueType>
146 ValueType
arg(
const complex<ValueType>& z);
148 template<
typename ValueType>
150 ValueType
norm(
const complex<ValueType>& z);
153 template<
typename ValueType>
155 complex<ValueType>
conj(
const complex<ValueType>& z);
158 template<
typename ValueType>
160 complex<ValueType>
polar(
const ValueType& m,
const ValueType& theta = 0);
164 template <
typename ValueType>
166 inline complex<ValueType>
operator*(
const complex<ValueType>& lhs,
const complex<ValueType>& rhs);
167 template <
typename ValueType>
169 inline complex<ValueType>
operator*(
const complex<ValueType>& lhs,
const ValueType & rhs);
170 template <
typename ValueType>
172 inline complex<ValueType>
operator*(
const ValueType& lhs,
const complex<ValueType>& rhs);
174 template <
typename ValueType>
176 inline complex<ValueType>
operator/(
const complex<ValueType>& lhs,
const complex<ValueType>& rhs);
185 template <
typename ValueType>
187 inline complex<ValueType>
operator+(
const complex<ValueType>& lhs,
const complex<ValueType>& rhs);
188 template <
typename ValueType>
190 inline complex<ValueType>
operator+(
const complex<ValueType>& lhs,
const ValueType & rhs);
191 template <
typename ValueType>
193 inline complex<ValueType>
operator+(
const ValueType& lhs,
const complex<ValueType>& rhs);
195 template <
typename ValueType>
197 inline complex<ValueType>
operator-(
const complex<ValueType>& lhs,
const complex<ValueType>& rhs);
198 template <
typename ValueType>
200 inline complex<ValueType>
operator-(
const complex<ValueType>& lhs,
const ValueType & rhs);
201 template <
typename ValueType>
203 inline complex<ValueType>
operator-(
const ValueType& lhs,
const complex<ValueType>& rhs);
206 template <
typename ValueType>
208 inline complex<ValueType>
operator+(
const complex<ValueType>& rhs);
209 template <
typename ValueType>
211 inline complex<ValueType>
operator-(
const complex<ValueType>& rhs);
215 template <
typename ValueType>
217 complex<ValueType>
cos(
const complex<ValueType>& z);
219 template <
typename ValueType>
221 complex<ValueType>
cosh(
const complex<ValueType>& z);
223 template <
typename ValueType>
225 complex<ValueType>
exp(
const complex<ValueType>& z);
227 template <
typename ValueType>
229 complex<ValueType>
log(
const complex<ValueType>& z);
231 template <
typename ValueType>
233 complex<ValueType>
log10(
const complex<ValueType>& z);
235 template <
typename ValueType>
237 complex<ValueType>
pow(
const complex<ValueType>& z,
const int& n);
239 template <
typename ValueType>
241 complex<ValueType>
pow(
const complex<ValueType>&z,
const ValueType&x);
243 template <
typename ValueType>
245 complex<ValueType>
pow(
const complex<ValueType>&z,
const complex<ValueType>&z2);
247 template <
typename ValueType>
249 complex<ValueType>
pow(
const ValueType& x,
const complex<ValueType>& z);
251 template <
typename ValueType>
253 complex<ValueType>
sin(
const complex<ValueType>&z);
255 template <
typename ValueType>
257 complex<ValueType>
sinh(
const complex<ValueType>&z);
259 template <
typename ValueType>
261 complex<ValueType>
sqrt(
const complex<ValueType>&z);
263 template <
typename ValueType>
265 complex<ValueType>
tan(
const complex<ValueType>&z);
267 template <
typename ValueType>
269 complex<ValueType>
tanh(
const complex<ValueType>&z);
274 template <
typename ValueType>
276 complex<ValueType>
acos(
const complex<ValueType>& z);
278 template <
typename ValueType>
280 complex<ValueType>
asin(
const complex<ValueType>& z);
282 template <
typename ValueType>
284 complex<ValueType>
atan(
const complex<ValueType>& z);
286 template <
typename ValueType>
288 complex<ValueType>
acosh(
const complex<ValueType>& z);
290 template <
typename ValueType>
292 complex<ValueType>
asinh(
const complex<ValueType>& z);
294 template <
typename ValueType>
296 complex<ValueType>
atanh(
const complex<ValueType>& z);
301 template<
typename ValueType,
class charT,
class traits>
302 std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os,
const complex<ValueType>& z);
303 template<
typename ValueType,
typename charT,
class traits>
304 std::basic_istream<charT, traits>&
305 operator>>(std::basic_istream<charT, traits>& is, complex<ValueType>& z);
309 template<
typename ValueType,
class charT,
class traits>
310 std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os,
const complex<ValueType>& z)
312 os <<
'(' << z.real() <<
',' << z.imag() <<
')';
316 template<
typename ValueType,
typename charT,
class traits>
317 std::basic_istream<charT, traits>&
318 operator>>(std::basic_istream<charT, traits>& is, complex<ValueType>& z)
333 z = complex<ValueType>(re, im);
337 is.setstate(std::ios_base::failbit);
346 is.setstate(std::ios_base::failbit);
358 template <
typename T>
362 template <
typename T>
367 template <
typename ValueType>
375 inline complex<ValueType>(
const ValueType & re = ValueType(),
const ValueType& im = ValueType())
383 inline complex<ValueType>(
const complex<X> & z)
391 inline complex<ValueType>(
const std::complex<X> & z)
397 template <
typename T>
399 inline complex<ValueType>&
operator=(
const complex<T> z)
407 inline complex<ValueType>&
operator+=(
const complex<ValueType> z)
409 real(real()+z.real());
410 imag(imag()+z.imag());
415 inline complex<ValueType>&
operator-=(
const complex<ValueType> z)
417 real(real()-z.real());
418 imag(imag()-z.imag());
423 inline complex<ValueType>&
operator*=(
const complex<ValueType> z)
430 inline complex<ValueType>&
operator/=(
const complex<ValueType> z)
444 __host__ __device__
inline ValueType real()
const volatile;
445 __host__ __device__
inline ValueType imag()
const volatile;
446 __host__ __device__
inline ValueType real()
const;
447 __host__ __device__
inline ValueType imag()
const;
448 __host__ __device__
inline void real(ValueType)
volatile;
449 __host__ __device__
inline void imag(ValueType)
volatile;
450 __host__ __device__
inline void real(ValueType);
451 __host__ __device__
inline void imag(ValueType);
458 struct complex <float> :
public float2
489 template <
typename T>
498 template <
typename T>
510 real(real()+z.
real());
511 imag(imag()+z.
imag());
518 real(real()-z.
real());
519 imag(imag()-z.
imag());
552 __host__ __device__
inline float real()
const volatile{
return x; }
553 __host__ __device__
inline float imag()
const volatile{
return y; }
554 __host__ __device__
inline float real()
const{
return x; }
555 __host__ __device__
inline float imag()
const{
return y; }
556 __host__ __device__
inline void real(
float re)
volatile{ x = re; }
557 __host__ __device__
inline void imag(
float im)
volatile{ y = im; }
558 __host__ __device__
inline void real(
float re){ x = re; }
559 __host__ __device__
inline void imag(
float im){ y = im; }
562 inline operator std::complex<float>()
const {
return std::complex<float>(real(),imag()); }
563 template <
typename T>
564 inline __host__ __device__
operator complex<T>()
const {
return complex<T>(
static_cast<T
>(real()),static_cast<T>(imag())); }
566 template<
typename otherFloat,
typename storeFloat>
569 template<
typename otherFloat,
typename storeFloat>
572 template<
typename otherFloat,
typename storeFloat>
575 template<
typename otherFloat,
typename storeFloat>
580 struct complex <double> :
public double2
611 template <
typename T>
620 template <
typename T>
632 real(real()+z.
real());
633 imag(imag()+z.
imag());
640 real(real()+z.
real());
641 imag(imag()+z.
imag());
648 real(real()-z.
real());
649 imag(imag()-z.
imag());
682 __host__ __device__
inline double real()
const volatile {
return x; }
683 __host__ __device__
inline double imag()
const volatile {
return y; }
684 __host__ __device__
inline double real()
const {
return x; }
685 __host__ __device__
inline double imag()
const {
return y; }
686 __host__ __device__
inline void real(
double re)
volatile{ x = re; }
687 __host__ __device__
inline void imag(
double im)
volatile{ y = im; }
688 __host__ __device__
inline void real(
double re){ x = re; }
689 __host__ __device__
inline void imag(
double im){ y = im; }
692 inline operator std::complex<double>()
const {
return std::complex<double>(real(),imag()); }
693 template <
typename T>
694 inline __host__ __device__
operator complex<T>()
const {
return complex<T>(
static_cast<T
>(real()),static_cast<T>(imag())); }
696 template<
typename otherFloat,
typename storeFloat>
699 template<
typename otherFloat,
typename storeFloat>
702 template<
typename otherFloat,
typename storeFloat>
705 template<
typename otherFloat,
typename storeFloat>
710 struct complex <char> :
public char2
717 __host__ __device__
inline complex<char>(
const char & re,
const char& im = float())
727 real(real()+z.
real());
728 imag(imag()+z.
imag());
734 real(real()-z.
real());
735 imag(imag()-z.
imag());
739 __host__ __device__
inline char real()
const volatile{
return x; }
740 __host__ __device__
inline char imag()
const volatile{
return y; }
741 __host__ __device__
inline char real()
const{
return x; }
742 __host__ __device__
inline char imag()
const{
return y; }
743 __host__ __device__
inline void real(
char re)
volatile{ x = re; }
744 __host__ __device__
inline void imag(
char im)
volatile{ y = im; }
745 __host__ __device__
inline void real(
char re){ x = re; }
746 __host__ __device__
inline void imag(
char im){ y = im; }
749 inline operator std::complex<char>()
const {
return std::complex<char>(real(),imag()); }
750 template <
typename T>
751 inline __host__ __device__
operator complex<T>()
const {
return complex<T>(
static_cast<T
>(real()),static_cast<T>(imag())); }
757 struct complex <short> :
public short2
764 __host__ __device__
inline complex<short>(
const short & re,
const short& im = float())
774 real(real()+z.
real());
775 imag(imag()+z.
imag());
781 real(real()-z.
real());
782 imag(imag()-z.
imag());
786 __host__ __device__
inline short real()
const volatile{
return x; }
787 __host__ __device__
inline short imag()
const volatile{
return y; }
788 __host__ __device__
inline short real()
const{
return x; }
789 __host__ __device__
inline short imag()
const{
return y; }
790 __host__ __device__
inline void real(
short re)
volatile{ x = re; }
791 __host__ __device__
inline void imag(
short im)
volatile{ y = im; }
792 __host__ __device__
inline void real(
short re){ x = re; }
793 __host__ __device__
inline void imag(
short im){ y = im; }
796 inline operator std::complex<short>()
const {
return std::complex<short>(real(),imag()); }
797 template <
typename T>
798 inline __host__ __device__
operator complex<T>()
const {
return complex<T>(
static_cast<T
>(real()),static_cast<T>(imag())); }
803 struct complex <int> :
public int2
810 __host__ __device__
inline complex<int>(
const int& re,
const int& im = float())
820 real(real()+z.
real());
821 imag(imag()+z.
imag());
827 real(real()-z.
real());
828 imag(imag()-z.
imag());
832 __host__ __device__
inline int real()
const volatile{
return x; }
833 __host__ __device__
inline int imag()
const volatile{
return y; }
834 __host__ __device__
inline int real()
const{
return x; }
835 __host__ __device__
inline int imag()
const{
return y; }
836 __host__ __device__
inline void real(
int re)
volatile{ x = re; }
837 __host__ __device__
inline void imag(
int im)
volatile{ y = im; }
838 __host__ __device__
inline void real(
int re){ x = re; }
839 __host__ __device__
inline void imag(
int im){ y = im; }
842 inline operator std::complex<int>()
const {
return std::complex<int>(real(),imag()); }
843 template <
typename T>
844 inline __host__ __device__
operator complex<T>()
const {
return complex<T>(
static_cast<T
>(real()),static_cast<T>(imag())); }
852 template<
typename ValueType>
854 inline complex<ValueType>
operator+(
const complex<ValueType>& lhs,
855 const complex<ValueType>& rhs){
856 return complex<ValueType>(lhs.real()+rhs.real(),lhs.imag()+rhs.imag());
860 template<
typename ValueType>
862 inline complex<ValueType>
operator+(
const volatile complex<ValueType>& lhs,
863 const volatile complex<ValueType>& rhs){
864 return complex<ValueType>(lhs.real()+rhs.real(),lhs.imag()+rhs.imag());
868 template <
typename ValueType>
870 inline complex<ValueType>
operator+(
const complex<ValueType>& lhs,
const ValueType & rhs){
871 return complex<ValueType>(lhs.real()+rhs,lhs.imag());
874 template <
typename ValueType>
876 inline complex<ValueType>
operator+(
const ValueType& lhs,
const complex<ValueType>& rhs){
877 return complex<ValueType>(rhs.real()+lhs,rhs.imag());
881 template <
typename ValueType>
883 inline complex<ValueType>
operator-(
const complex<ValueType>& lhs,
const complex<ValueType>& rhs){
884 return complex<ValueType>(lhs.real()-rhs.real(),lhs.imag()-rhs.imag());
887 template <
typename ValueType>
889 inline complex<ValueType>
operator-(
const complex<ValueType>& lhs,
const ValueType & rhs){
890 return complex<ValueType>(lhs.real()-rhs,lhs.imag());
893 template <
typename ValueType>
895 inline complex<ValueType>
operator-(
const ValueType& lhs,
const complex<ValueType>& rhs){
896 return complex<ValueType>(lhs-rhs.real(),-rhs.imag());
900 template <
typename ValueType>
902 inline complex<ValueType>
operator*(
const complex<ValueType>& lhs,
903 const complex<ValueType>& rhs){
904 return complex<ValueType>(lhs.real()*rhs.real()-lhs.imag()*rhs.imag(),
905 lhs.real()*rhs.imag()+lhs.imag()*rhs.real());
909 template <
typename ValueType>
911 inline complex<ValueType>
operator*(
const complex<ValueType>& lhs,
const ValueType & rhs){
912 return complex<ValueType>(lhs.real()*rhs,lhs.imag()*rhs);
916 template <
typename ValueType>
918 inline complex<ValueType>
operator*(
const ValueType& lhs,
const complex<ValueType>& rhs){
919 return complex<ValueType>(rhs.real()*lhs,rhs.imag()*lhs);
924 template <
typename ValueType>
926 inline complex<ValueType>
operator/(
const complex<ValueType>& lhs,
const complex<ValueType>& rhs){
927 const ValueType cross_norm = lhs.real() * rhs.real() + lhs.imag() * rhs.imag();
928 const ValueType rhs_norm =
norm(rhs);
929 return complex<ValueType>(cross_norm/rhs_norm,
930 (lhs.imag() * rhs.real() - lhs.real() * rhs.imag()) / rhs_norm);
935 inline complex<float>
operator/(
const complex<float>& lhs,
const complex<float>& rhs){
938 float s = fabsf(rhs.
real()) + fabsf(rhs.
imag());
939 float oos = 1.0f /
s;
940 float ars = lhs.
real() * oos;
941 float ais = lhs.
imag() * oos;
942 float brs = rhs.
real() * oos;
943 float bis = rhs.
imag() * oos;
944 s = (brs * brs) + (bis * bis);
946 return complex<float>(((ars * brs) + (ais * bis)) * oos,
947 ((ais * brs) - (ars * bis)) * oos);
952 inline complex<double>
operator/(
const complex<double>& lhs,
const complex<double>& rhs){
954 complex<double> quot;
955 double s = fabs(rhs.
real()) + fabs(rhs.
imag());
956 double oos = 1.0 /
s;
957 double ars = lhs.
real() * oos;
958 double ais = lhs.
imag() * oos;
959 double brs = rhs.
real() * oos;
960 double bis = rhs.
imag() * oos;
961 s = (brs * brs) + (bis * bis);
963 return complex<double>(((ars * brs) + (ais * bis)) * oos,
964 ((ais * brs) - (ars * bis)) * oos);
967 template <
typename ValueType>
969 inline complex<ValueType>
operator/(
const complex<ValueType>& lhs,
const ValueType & rhs){
970 return complex<ValueType>(lhs.real()/rhs,lhs.imag()/rhs);
974 template <
typename ValueType>
976 inline complex<ValueType>
operator/(
const ValueType& lhs,
const complex<ValueType>& rhs){
977 const ValueType cross_norm = lhs * rhs.real();
978 const ValueType rhs_norm =
norm(rhs);
979 return complex<ValueType>(cross_norm/rhs_norm,(-lhs.real() * rhs.imag()) / rhs_norm);
984 inline complex<float>
operator/(
const float& lhs,
const complex<float>& rhs){
985 return complex<float>(lhs) / rhs;
989 inline complex<double>
operator/(
const double& lhs,
const complex<double>& rhs){
990 return complex<double>(lhs) / rhs;
994 template <
typename ValueType>
996 inline complex<ValueType>
operator+(
const complex<ValueType>& rhs){
999 template <
typename ValueType>
1001 inline complex<ValueType>
operator-(
const complex<ValueType>& rhs){
1002 return rhs*-ValueType(1);
1006 template <
typename ValueType>
1008 inline bool operator==(
const complex<ValueType>& lhs,
const complex<ValueType>& rhs){
1009 if(lhs.real() == rhs.real() && lhs.imag() == rhs.imag()){
1015 template <
typename ValueType>
1017 inline bool operator==(
const ValueType & lhs,
const complex<ValueType>& rhs){
1018 if(lhs == rhs.real() && rhs.imag() == 0){
1023 template <
typename ValueType>
1025 inline bool operator==(
const complex<ValueType> & lhs,
const ValueType& rhs){
1026 if(lhs.real() == rhs && lhs.imag() == 0){
1033 template <
typename ValueType>
1035 inline bool operator!=(
const complex<ValueType>& lhs,
const complex<ValueType>& rhs){
1036 return !(lhs == rhs);
1039 template <
typename ValueType>
1041 inline bool operator!=(
const ValueType & lhs,
const complex<ValueType>& rhs){
1042 return !(lhs == rhs);
1045 template <
typename ValueType>
1047 inline bool operator!=(
const complex<ValueType> & lhs,
const ValueType& rhs){
1048 return !(lhs == rhs);
1052 template <
typename ValueType>
1054 inline complex<ValueType>
conj(
const complex<ValueType>& z){
1055 return complex<ValueType>(z.real(),-z.imag());
1058 template <
typename ValueType>
1060 inline ValueType
abs(
const complex<ValueType>& z){
1061 return ::hypot(z.real(),z.imag());
1065 inline float abs(
const complex<float>& z){
1066 return ::hypotf(z.
real(),z.
imag());
1070 inline double abs(
const complex<double>& z){
1074 template <
typename ValueType>
1076 inline ValueType
arg(
const complex<ValueType>& z){
1077 return atan2(z.imag(),z.real());
1081 inline float arg(
const complex<float>& z){
1086 inline double arg(
const complex<double>& z){
1090 template <
typename ValueType>
1092 inline ValueType
norm(
const complex<ValueType>& z){
1093 return z.real()*z.real() + z.imag()*z.imag();
1096 template <
typename ValueType>
1098 inline complex<ValueType>
polar(
const ValueType & m,
const ValueType & theta){
1099 return complex<ValueType>(m *
::cos(theta),m *
::sin(theta));
1104 inline complex<float>
polar(
const float & magnitude,
const float & angle){
1105 return complex<float>(magnitude * ::cosf(angle),magnitude * ::sinf(angle));
1110 inline complex<double>
polar(
const double & magnitude,
const double & angle){
1111 return complex<double>(magnitude *
::cos(angle),magnitude *
::sin(angle));
1115 template <
typename ValueType>
1117 inline complex<ValueType>
cos(
const complex<ValueType>& z){
1118 const ValueType re = z.real();
1119 const ValueType im = z.imag();
1125 inline complex<float>
cos(
const complex<float>& z){
1126 const float re = z.
real();
1127 const float im = z.
imag();
1128 return complex<float>(cosf(re) * coshf(im), -sinf(re) * sinhf(im));
1131 template <
typename ValueType>
1133 inline complex<ValueType>
cosh(
const complex<ValueType>& z){
1134 const ValueType re = z.real();
1135 const ValueType im = z.imag();
1141 inline complex<float>
cosh(
const complex<float>& z){
1142 const float re = z.
real();
1143 const float im = z.
imag();
1144 return complex<float>(::coshf(re) * ::cosf(im), ::sinhf(re) * ::sinf(im));
1148 template <
typename ValueType>
1150 inline complex<ValueType>
exp(
const complex<ValueType>& z){
1151 return polar(::
exp(z.real()),z.imag());
1156 inline complex<float>
exp(
const complex<float>& z){
1160 template <
typename ValueType>
1162 inline complex<ValueType>
log(
const complex<ValueType>& z){
1168 inline complex<float>
log(
const complex<float>& z){
1169 return complex<float>(::logf(
abs(z)),
arg(z));
1173 template <
typename ValueType>
1175 inline complex<ValueType>
log10(
const complex<ValueType>& z){
1178 return log(z)/ValueType(2.30258509299404568402);
1182 template <
typename ValueType>
1184 inline complex<ValueType>
pow(
const complex<ValueType>& z,
const ValueType & exponent){
1185 return exp(
log(z)*exponent);
1188 template <
typename ValueType>
1190 inline complex<ValueType>
pow(
const complex<ValueType>& z,
const complex<ValueType> & exponent){
1191 return exp(
log(z)*exponent);
1194 template <
typename ValueType>
1196 inline complex<ValueType>
pow(
const ValueType & x,
const complex<ValueType> & exponent){
1197 return exp(::
log(x)*exponent);
1202 inline complex<float>
pow(
const float & x,
const complex<float> & exponent){
1203 return exp(::logf(x)*exponent);
1206 template <
typename ValueType>
1208 inline complex<ValueType>
pow(
const complex<ValueType>& z,
const int & exponent){
1209 return exp(
log(z)*ValueType(exponent));
1212 template <
typename ValueType>
1214 inline complex<ValueType>
sin(
const complex<ValueType>& z){
1215 const ValueType re = z.real();
1216 const ValueType im = z.imag();
1222 inline complex<float>
sin(
const complex<float>& z){
1223 const float re = z.
real();
1224 const float im = z.
imag();
1225 return complex<float>(::sinf(re) * ::coshf(im), ::cosf(re) * ::sinhf(im));
1228 template <
typename ValueType>
1230 inline complex<ValueType>
sinh(
const complex<ValueType>& z){
1231 const ValueType re = z.real();
1232 const ValueType im = z.imag();
1238 inline complex<float>
sinh(
const complex<float>& z){
1239 const float re = z.
real();
1240 const float im = z.
imag();
1241 return complex<float>(::sinhf(re) * ::cosf(im), ::coshf(re) * ::sinf(im));
1244 template <
typename ValueType>
1246 inline complex<ValueType>
sqrt(
const complex<ValueType>& z){
1252 inline complex<float>
sqrt(
const complex<float>& z){
1256 template <
typename ValueType>
1258 inline complex<ValueType>
tan(
const complex<ValueType>& z){
1262 template <
typename ValueType>
1264 inline complex<ValueType>
tanh(
const complex<ValueType>& z){
1266 return (
exp(ValueType(2)*z)-ValueType(1))/(
exp(ValueType(2)*z)+ValueType(1));
1272 template <
typename ValueType>
1274 inline complex<ValueType>
acos(
const complex<ValueType>& z){
1275 const complex<ValueType> ret =
asin(z);
1276 return complex<ValueType>(ValueType(M_PI/2.0) - ret.real(),-ret.imag());
1279 template <
typename ValueType>
1281 inline complex<ValueType>
asin(
const complex<ValueType>& z){
1282 const complex<ValueType> i(0,1);
1283 return -i*
asinh(i*z);
1286 template <
typename ValueType>
1288 inline complex<ValueType>
atan(
const complex<ValueType>& z){
1289 const complex<ValueType> i(0,1);
1290 return -i*
atanh(i*z);
1293 template <
typename ValueType>
1295 inline complex<ValueType>
acosh(
const complex<ValueType>& z){
1296 quda::complex<ValueType> ret((z.real() - z.imag()) * (z.real() + z.imag()) - ValueType(1.0),
1297 ValueType(2.0) * z.real() * z.imag());
1299 if (z.real() < ValueType(0.0)){
1304 if (ret.real() < ValueType(0.0)){
1318 template <
typename ValueType>
1320 inline complex<ValueType>
asinh(
const complex<ValueType>& z){
1321 return log(
sqrt(z*z+ValueType(1))+z);
1324 template <
typename ValueType>
1326 inline complex<ValueType>
atanh(
const complex<ValueType>& z){
1327 ValueType imag2 = z.imag() * z.imag();
1328 ValueType n = ValueType(1.0) + z.real();
1331 ValueType d = ValueType(1.0) - z.real();
1333 complex<ValueType> ret(ValueType(0.25) * (::
log(n) - ::
log(d)),0);
1335 d = ValueType(1.0) - z.real() * z.real() - imag2;
1337 ret.imag(ValueType(0.5) * ::
atan2(ValueType(2.0) * z.imag(), d));
1342 template <
typename ValueType>
1344 inline complex<float>
atanh(
const complex<float>& z){
1346 float n = float(1.0) + z.
real();
1349 float d = float(1.0) - z.
real();
1351 complex<float> ret(
float(0.25) * (::logf(n) - ::logf(d)),0);
1353 d = float(1.0) - z.
real() * z.
real() - imag2;
1355 ret.
imag(
float(0.5) * ::atan2f(
float(2.0) * z.
imag(), d));
1361 template <
typename real> __host__ __device__
inline complex<real>
cmul(
const complex<real> &x,
const complex<real> &y)
1364 w.x = x.real() * y.real();
1365 w.x -= x.imag() * y.imag();
1366 w.y = x.imag() * y.real();
1367 w.y += x.real() * y.imag();
1371 template <
typename real>
1372 __host__ __device__
inline complex<real>
cmac(
const complex<real> &x,
const complex<real> &y,
const complex<real> &z)
1374 complex<real> w = z;
1375 w.x += x.real() * y.real();
1376 w.x -= x.imag() * y.imag();
1377 w.y += x.imag() * y.real();
1378 w.y += x.real() * y.imag();
__host__ __device__ complex< float > sinh(const complex< float > &z)
__host__ __device__ ValueType tanh(ValueType x)
__host__ __device__ void real(short re) volatile
__host__ __device__ ValueType sinh(ValueType x)
__host__ __device__ void real(char re) volatile
__host__ __device__ void real(int re) volatile
__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__ void imag(short im)
__host__ __device__ complex< double > & operator+=(const complex< float > z)
__host__ __device__ ValueType atan(ValueType x)
fieldorder_wrapper is an internal class that is used to wrap instances of FieldOrder accessors...
__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__ complex< char > & operator-=(const complex< char > z)
__host__ __device__ ValueType cosh(ValueType x)
__host__ __device__ void real(double re) volatile
__host__ __device__ ValueType sqrt(ValueType x)
__host__ __device__ complex< real > cmac(const complex< real > &x, const complex< real > &y, const complex< real > &z)
__host__ __device__ complex< float > cosh(const complex< float > &z)
__host__ __device__ void real(float re)
__host__ __device__ void imag(short im) volatile
__host__ __device__ void real(short re)
__host__ __device__ char real() const volatile
__host__ __device__ complex< ValueType > tanh(const complex< ValueType > &z)
__host__ __device__ void imag(float im)
__host__ __device__ int real() const
std::basic_istream< charT, traits > & operator>>(std::basic_istream< charT, traits > &is, complex< ValueType > &z)
__host__ __device__ double imag() const
__host__ __device__ complex< int > & operator+=(const complex< int > z)
__host__ __device__ ValueType tan(ValueType x)
__host__ __device__ void imag(double im) volatile
__host__ __device__ char real() const
fieldorder_wrapper is an internal class that is used to wrap instances of FieldOrder accessors...
__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__ 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__ char imag() const
__host__ __device__ complex< ValueType > acos(const complex< ValueType > &z)
__host__ __device__ complex< float > sin(const complex< float > &z)
__host__ __device__ int imag() const volatile
__host__ __device__ int real() const volatile
__host__ __device__ void real(double re)
__host__ __device__ ValueType atan2(ValueType x, ValueType y)
__host__ __device__ short imag() const volatile
__host__ __device__ void real(char re)
__host__ __device__ void real(int re)
__device__ __host__ ColorSpinor< Float, Nc, Ns > operator-(const ColorSpinor< Float, Nc, Ns > &x, const ColorSpinor< Float, Nc, Ns > &y)
ColorSpinor subtraction operator.
__host__ __device__ complex< float > cos(const complex< float > &z)
__host__ __device__ complex< int > & operator-=(const complex< int > z)
__host__ __device__ ValueType pow(ValueType x, ExponentType e)
__host__ __device__ void imag(double im)
__host__ __device__ float imag() const volatile
__host__ __device__ void imag(int im)
__host__ __device__ complex< float > & operator/=(const complex< float > z)
__host__ __device__ float real() const
__host__ __device__ short real() const volatile
__host__ __device__ complex< float > exp(const complex< float > &z)
__host__ __device__ complex< float > log(const complex< float > &z)
__host__ __device__ short real() const
__host__ __device__ complex< double > & operator/=(const complex< double > z)
__device__ __host__ complex< Float > operator*(const Float &a, const fieldorder_wrapper< Float, storeFloat > &b)
__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< char > & operator+=(const complex< char > z)
__host__ __device__ complex< ValueType > & operator*=(const ValueType z)
__host__ __device__ complex< real > cmul(const complex< real > &x, const complex< real > &y)
__host__ __device__ complex< ValueType > & operator=(const complex< T > z)
__host__ __device__ ValueType log(ValueType x)
__host__ __device__ double imag() const volatile
__host__ __device__ complex< float > & operator*=(const float z)
__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__ char imag() const volatile
__host__ __device__ short imag() const
__host__ __device__ double abs(const complex< double > &z)
__host__ __device__ complex< float > sqrt(const complex< float > &z)
__host__ __device__ void imag(char im)
__host__ __device__ complex< double > & operator*=(const double z)
__host__ __device__ complex< ValueType > atan(const complex< ValueType > &z)
__host__ __device__ complex< short > & operator+=(const complex< short > z)
__host__ __device__ ValueType arg(const complex< ValueType > &z)
Returns the phase angle of z.
__host__ __device__ double real() const
__host__ __device__ void imag(int im) volatile
__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__ int imag() const
__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< double > & operator*=(const complex< double > z)
__device__ __host__ complex< Float > operator+(const fieldorder_wrapper< Float, storeFloat > &a, const complex< Float > &b)
__host__ __device__ bool operator!=(const complex< ValueType > &lhs, const complex< ValueType > &rhs)
__host__ __device__ complex< ValueType > atanh(const complex< ValueType > &z)
__host__ __device__ float imag() const
__host__ __device__ complex< float > & operator+=(const complex< float > z)
__host__ __device__ complex< short > & operator-=(const complex< short > z)
__host__ __device__ volatile complex< double > & operator=(const complex< T > z) volatile
__host__ __device__ double real() const volatile
__host__ __device__ void imag(char im) 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)