/* Complex.js v2.0.1 11/02/2016 Copyright (c) 2016, Robert Eisele (robert@xarg.org) Dual licensed under the MIT or GPL Version 2 licenses. */ (function(p){"use strict";function l(a,b){if(void 0===a||null===a)e.re=e.im=0;else if(void 0!==b)e.re=a,e.im=b;else switch(typeof a){case "object":"im"in a&&"re"in a?(e.re=a.re,e.im=a.im):"abs"in a&&"arg"in a?(e.re=a.abs*Math.cos(a.arg),e.im=a.abs*Math.sin(a.arg)):"r"in a&&"phi"in a?(e.re=a.r*Math.cos(a.phi),e.im=a.r*Math.sin(a.phi)):m();break;case "string":e.im=e.re=0;var c=a.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g),d=1,f=0;null===c&&m();for(var g=0;gc&&3E3>d?.5*Math.log(a*a+b*b):Math.log(a/Math.cos(Math.atan2(b,a)))}function d(a,b){if(!(this instanceof d))return new d(a,b);l(a,b);this.re=e.re;this.im=e.im}var e={re:0,im:0};Math.cosh=Math.cosh||function(a){return.5*(Math.exp(a)+Math.exp(-a))};Math.sinh=Math.sinh||function(a){return.5*(Math.exp(a)-Math.exp(-a))};d.prototype={re:0,im:0,sign:function(){var a=this.abs();return new d(this.re/a,this.im/a)},add:function(a,b){l(a,b);return new d(this.re+e.re,this.im+e.im)},sub:function(a,b){l(a,b); return new d(this.re-e.re,this.im-e.im)},mul:function(a,b){l(a,b);return 0===e.im&&0===this.im?new d(this.re*e.re,0):new d(this.re*e.re-this.im*e.im,this.re*e.im+this.im*e.re)},div:function(a,b){l(a,b);a=this.re;b=this.im;var c=e.re,h=e.im,f;if(0===c&&0===h)return new d(0!==a?a/0:0,0!==b?b/0:0);if(0===h)return new d(a/c,b/c);if(Math.abs(c)=a?.5*Math.sqrt(2*(c-a)):Math.abs(b)/Math.sqrt(2*(c+a));return new d(e,0<=b?a:-a)},exp:function(){var a=Math.exp(this.re);return new d(a*Math.cos(this.im),a*Math.sin(this.im))},log:function(){var a=this.re,b=this.im;return new d(n(a,b),Math.atan2(b,a))},abs:function(){var a=Math.abs(this.re),b=Math.abs(this.im);if(3E3>a&&3E3>b)return Math.sqrt(a*a+b*b);a=b.im?(a=b.re,b.re=-b.im,b.im=a):(a=b.im,b.im=-b.re,b.re=a);return b},atanh:function(){var a=this.re,b=this.im,c=1b?" - ":" + ":0>b&&(c+="-"),b=Math.abs(b),1!==b&&(c+=b),c+="i");return c?c:"0"},toVector:function(){return[this.re,this.im]},valueOf:function(){return 0===this.im?this.re:null}};d.ZERO=new d(0,0);d.ONE=new d(1,0);d.I=new d(0,1);d.PI=new d(Math.PI,0);d.E=new d(Math.E,0);d.EPSILON=1E-16; "function"===typeof define&&define.amd?define([],function(){return d}):"object"===typeof exports?module.exports=d:p.Complex=d})(this);