Skip to content

Instantly share code, notes, and snippets.

@ten-A
Last active June 17, 2016 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ten-A/4bf20c54e6c52ffc4230d2a40ab8c9a5 to your computer and use it in GitHub Desktop.
Save ten-A/4bf20c54e6c52ffc4230d2a40ab8c9a5 to your computer and use it in GitHub Desktop.
Complex Field Computing Library for Extendscript
// complex numbers Constructer
function C(r,i){
this.r = r; //real
this.i = i; //imaginary
}
//compute complex value
function Cconj(c){ //conjunction
return new C(c.r, -c.i);
}
function Cadd(c,d){ //add
return new C(c.r+d.r, c.i+d.i);
}
function Csub(c,d){ //sub
return new C(c.r-d.r, c.i-d.i);
}
function Cmul(c,d){ //multi
return new C(c.r*d.r-c.i*d.i, c.r*d.i+c.i*d.r);
}
function Cdiv(c,d){ //division
return new C(
(c.r*d.r+c.i*d.i)/(d.r*d.r+d.i*d.i),
(c.r*d.i-c.i*d.r)/(d.r*d.r+d.i*d.i)
);
}
function Csqrt(c){ //square root
return new C(
Math.sqrt(Math.sqrt(c.r*c.r+c.i*c.i))*Math.cos(Math.atan2(c.i,c.r)/2),
Math.sqrt(Math.sqrt(c.r*c.r+c.i*c.i))*Math.sin(Math.atan2(c.i,c.r)/2)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment