22 #ifndef Rcpp__sugar__complex_h
23 #define Rcpp__sugar__complex_h
29 template <
bool NA,
typename RESULT_TYPE,
typename T,
typename FunPtr>
31 Rcpp::traits::r_sexptype_traits<RESULT_TYPE>::rtype ,
33 SugarComplex<NA,RESULT_TYPE,T,FunPtr>
44 return Rcpp::traits::get_na< Rcpp::traits::r_sexptype_traits<RESULT_TYPE>::rtype >() ;
65 inline double complex__Arg( Rcomplex x ){ return ::atan2(x.i, x.r); }
69 double expx =
::exp(x.r);
70 y.r = expx * ::cos(x.i);
71 y.i = expx * ::sin(x.i);
76 y.i = ::atan2(x.i, x.r);
84 if( (mag = ::
hypot(z.r, z.i)) == 0.0)
87 r.r =
::sqrt(0.5 * (mag + z.r) );
91 r.i =
::sqrt(0.5 * (mag - z.r) );
100 r.r = ::cos(z.r) * ::cosh(z.i);
101 r.i = - ::sin(z.r) * ::sinh(z.i);
106 r.r = ::cos(-z.i) * ::cosh( z.r);
107 r.i = - ::sin(-z.i) * ::sinh(z.r);
112 r.r = ::sin(z.r) * ::cosh(z.i);
113 r.i = ::cos(z.r) * ::sinh(z.i);
121 den = ::cos(x2) + ::cosh(y2);
125 if (ISNAN(y2) || ::fabs(y2) < 50.0)
126 r.i = ::sinh(y2)/den;
128 r.i = (y2 <0 ? -1.0 : 1.0);
135 double alpha, bet, t1, t2, x, y;
143 r.i =
::log(alpha + ::
sqrt(alpha*alpha - 1));
144 if(y < 0 || (y == 0 && x > 1)) r.i *= -1;
151 r.r = M_PI_2 - Asin.r;
170 r.r = 0.5 * ::atan(2 * x / ( 1 - x * x - y * y));
171 r.i = 0.25 *
::log((x * x + (y + 1) * (y + 1)) /
172 (x * x + (y - 1) * (y - 1)));
175 if(x < 0 || (x == 0 && y < 0)) r.r -= M_PI;
231 #define RCPP_SUGAR_COMPLEX(__NAME__,__OUT__) \
232 template <bool NA, typename T> \
233 inline sugar::SugarComplex<NA,__OUT__,T, __OUT__ (*)(Rcomplex) > \
234 __NAME__(const VectorBase<CPLXSXP,NA,T>& t) { \
235 return sugar::SugarComplex<NA,__OUT__,T, __OUT__ (*)(Rcomplex) >( \
236 internal::complex__##__NAME__, t); \
260 #undef RCPP_SUGAR_COMPLEX
RESULT_TYPE operator[](R_xlen_t i) const
SugarComplex(FunPtr ptr_, const VEC_TYPE &vec_)
Rcpp::VectorBase< CPLXSXP, NA, T > VEC_TYPE
double hypot(double a, double b)
void exp(InputIterator begin, InputIterator end, OutputIterator out)
void log(InputIterator begin, InputIterator end, OutputIterator out)
void sqrt(InputIterator begin, InputIterator end, OutputIterator out)
Rcomplex complex__Conj(Rcomplex x)
Rcomplex complex__cosh(Rcomplex z)
Rcomplex complex__exp(Rcomplex x)
Rcomplex complex__atan(Rcomplex z)
double complex__Im(Rcomplex x)
double complex__Re(Rcomplex x)
Rcomplex complex__tan(Rcomplex z)
Rcomplex complex__atanh(Rcomplex z)
Rcomplex complex__cos(Rcomplex z)
Rcomplex complex__asin(Rcomplex z)
Rcomplex complex__tanh(Rcomplex z)
double complex__Mod(Rcomplex x)
Rcomplex complex__acos(Rcomplex z)
Rcomplex complex__sinh(Rcomplex z)
Rcomplex complex__sqrt(Rcomplex z)
Rcomplex complex__acosh(Rcomplex z)
Rcomplex complex__log(Rcomplex x)
Rcomplex complex__asinh(Rcomplex z)
double complex__Arg(Rcomplex x)
Rcomplex complex__sin(Rcomplex z)
bool is_na< CPLXSXP >(Rcomplex x)
#define RCPP_SUGAR_COMPLEX(__NAME__, __OUT__)