22#ifndef Rcpp__sugar__complex_h
23#define Rcpp__sugar__complex_h
29template <
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 >() ;
69 double expx = ::exp(x.r);
77 y.r = ::log(::hypot(x.r, x.i));
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) );
128 r.i = (
y2 <0 ? -1.0 : 1.0);
138 t1 = 0.5 * ::hypot(x + 1, y);
139 t2 = 0.5 * ::hypot(x - 1, y);
144 if(y < 0 || (y == 0 && x > 1))
r.i *= -1;
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
Rcomplex complex__Conj(Rcomplex x)
Rcomplex complex__cosh(Rcomplex z)
Rcomplex complex__exp(Rcomplex x)
T as(SEXP x, ::Rcpp::traits::r_type_primitive_tag)
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__)