MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / complex__sqrt

Function complex__sqrt

inst/include/Rcpp/sugar/functions/complex.h:80–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78 return y ;
79}
80inline Rcomplex complex__sqrt(Rcomplex z){
81 Rcomplex r ;
82 double mag;
83
84 if( (mag = ::hypot(z.r, z.i)) == 0.0)
85 r.r = r.i = 0.0;
86 else if(z.r > 0) {
87 r.r = ::sqrt(0.5 * (mag + z.r) );
88 r.i = z.i / r.r / 2;
89 }
90 else {
91 r.i = ::sqrt(0.5 * (mag - z.r) );
92 if(z.i < 0)
93 r.i = - r.i;
94 r.r = z.i / r.i / 2;
95 }
96 return r ;
97}
98inline Rcomplex complex__cos(Rcomplex z){
99 Rcomplex r ;
100 r.r = ::cos(z.r) * ::cosh(z.i);

Callers

nothing calls this directly

Calls 2

hypotFunction · 0.85
sqrtFunction · 0.50

Tested by

no test coverage detected