vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
555 stars 92 forks source link

Complex exponentiation in pair.h #274

Closed justonlyasy closed 2 years ago

justonlyasy commented 2 years ago

In pair.h, the pow command defined as following

// Complex exponentiation
inline pair pow(const pair& z, const pair& w)
{
  double u=w.getx();
  double v=w.gety();
  if(z == 0.0) return w == 0.0 ? 1.0 : 0.0;
  double logr=0.5*log(z.abs2());
  double th=z.angle();
  return exp(logr*u-th*v)*expi(logr*v+th*u);
}

When I run this code on http://asymptote.ualberta.ca/

pair a=(7,0);
pair b=(0.9,-33);
pair c=sqrt(a); // accepted
pair q=pow(a,b);

I get

pair q=pow(a,b);
       ^
workspace_1.asy: 6.8: no matching variable 'pow'

How to write this command?

johncbowman commented 2 years ago

pair q=a^b;