[R] Multiplying complex numbers from R in C

Oleksandr Dyklevych diklevich at gmail.com
Thu Dec 16 23:20:33 CET 2010

I'm trying to do some operations on complex numbers in C with returning  
results to R, but it seems that arithmetic operators do not overloaded for  
complex numbers. I mean, I try a very simple code, like

#include <R.h>
#include <Rinternals.h>
#include <Rmath.h>

int main(){
     Rcomplex e, z, s;
     e.r = M_PI; e.i = 0;
     z.r = 0; z.i = -2;
     s = e * z; //here I get an error - invalid operands to binary * (have  
'Rcomplex' and 'Rcomplex')
     return 0;

So, should I overload operators for R-complex numbers by myself or there  
is a way to use some operators already?
Because I'll even need operations like raising to a power or something...

Best regards,

More information about the R-help mailing list