22 #ifndef RCPP__complex_H
23 #define RCPP__complex_H
25 inline Rcomplex
operator*(
const Rcomplex& lhs,
const Rcomplex& rhs) {
27 y.r = lhs.r * rhs.r - lhs.i * rhs.i ;
28 y.i = lhs.r * rhs.i + rhs.r * lhs.i ;
32 inline Rcomplex
operator+(
const Rcomplex& lhs,
const Rcomplex& rhs) {
39 inline Rcomplex
operator-(
const Rcomplex& lhs,
const Rcomplex& rhs) {
46 inline Rcomplex
operator/(
const Rcomplex& a,
const Rcomplex& b) {
51 if( (abr = b.r) < 0) abr = - abr;
52 if( (abi = b.i) < 0) abi = - abi;
55 den = b.i * (1 + ratio*ratio);
56 c.r = (a.r*ratio + a.i) / den;
57 c.i = (a.i*ratio - a.r) / den;
60 den = b.r * (1 + ratio*ratio);
61 c.r = (a.r + a.i*ratio) / den;
62 c.i = (a.i - a.r*ratio) / den;
68 inline bool operator==(
const Rcomplex& a,
const Rcomplex& b) {
69 return a.r == b.r && a.i == b.i ;
74 #define dplyr_tools_complex_H
76 inline std::ostream &
operator<<(std::ostream &os,
const Rcomplex& cplx) {
77 return os << cplx.r <<
"+" << cplx.i <<
"i" ;
Rcomplex operator-(const Rcomplex &lhs, const Rcomplex &rhs)
Rcomplex operator+(const Rcomplex &lhs, const Rcomplex &rhs)
std::ostream & operator<<(std::ostream &os, const Rcomplex &cplx)
Rcomplex operator*(const Rcomplex &lhs, const Rcomplex &rhs)
Rcomplex operator/(const Rcomplex &a, const Rcomplex &b)
bool operator==(const Rcomplex &a, const Rcomplex &b)