The following behaviour (in R 0.62.3) is disturbing:> (0+0i)^2[1] NaN+NaNi Is it deliberate?? Laimonis Kavalieris -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "laimonis" == laimonis kavalieris <laimonis at chance.otago.ac.nz> writes:laimonis> The following behaviour (in R 0.62.3) is disturbing: >> (0+0i)^2 laimonis> [1] NaN+NaNi laimonis> Is it deliberate?? No, it's a clear bug. Even shorter is 0i^2 Patches to complex_pow(.) in src/main/complex.c are welcome, [obvious tests for 0..] but to R-devel, not to R-help ! Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum SOL G1; Sonneggstr.33 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1086 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I am not a "c" programmer but this is very simple and seems to be working (just a check for 0): in src/main/complex.c ... static void complex_pow(complex *r, complex *a, complex *b) { double logr, logi, x, y, mag; if ((mag = hypot(a->r, a->i)) == 0.0) { r->r = r->i = 0.0; } else { logr = log(mag ); logi = atan2(a->i, a->r); x = exp( logr * b->r - logi * b->i ); y = logr * b->i + logi * b->r; r->r = x * cos(y); r->i = x * sin(y); } } .... Osman -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._