diff --git a/lib/complex.min.js b/lib/complex.min.js index e9a1e40..6b965d8 100644 --- a/lib/complex.min.js +++ b/lib/complex.min.js @@ -1 +1 @@ -/* Copyright (c) 2012 Patrick Roberts */(function(e){"use strict";function w(e){return e>=0?e-e%1:e-(1+e%1)%1}function E(e){return e>=0?e+(1-e%1)%1:e-e%1}function S(e){return w(e+.5)}function x(e){return e-e%1}function T(e){return e%1}function N(e,n,i,s){if(!(this instanceof N)){return new N(e,n,i,s)}if(typeof i==="number"){this.m=t.abs(i)}else{this.m=t.sqrt(e*e+n*n)}if(typeof s==="number"){this.t=i>=0?s:s+r}else{this.t=t.atan2(n,e)}this.t=r-(r*3-(r-(r*3-this.t)%(r*2)))%(r*2);this.r=e;this.i=n}function C(e,t,n){var r;if(d.test(e)){if(v.test(n.slice(t))){return e}return e.charAt(0).replace(u,C)+"*"+e.charAt(1).replace(u,C)}if(h.test(e)){return"("}if(p.test(e)){return")"}r=e.search(m);return e.charAt(r!==-1?r:"*")}function k(e){var t=/[^a-z]+/gi,n="abcdefghijklmnopqrstuvwxyz",r=n.length,i={},s="",o,u,a;e=e.map(function(e){var n=e.replace(t,"");if(e!==n){throw new SyntaxError('"'+e+'" is an invalid variable name.')}return n.toLowerCase()});for(o=0;o=0){a=u%r;u=u-a;s=n.charAt(a)+s;u=u/r-1}i[e[o]]=s;s=""}return i}function L(e,t){var n=1;while(n>0&&t0){throw new SyntaxError('Expected ")".')}return t-1}function A(e,n){var r=0,i,s;for(i=n;i1){return i}}}}return e.length}function O(e,n){var r=0,i,s;for(i=n;i1){return i}}if(e[i]==="*"||e[i]==="/"||e[i]===" "||e[i]==="%"){return i}}}return e.length}function M(e,t,n){switch(e){case"+":case"-":return A(t,n);case"*":case" ":case"/":case"%":case"^":return O(t,n);default:throw new SyntaxError('"'+e+'" is not a valid operator.')}}function _(){Array.apply(this,arguments)}function D(e,t,n){var r="",i=0,s=false,o,u,h,p,d,v;if(e.length===0){throw new SyntaxError('"" is not a valid argument.')}while(i0?"i":"-i":r+" i"}return n+(this.i>0?"+":"")+(t.abs(this.i)===1?this.i>0?"i":"-i":r+" i")}i=this.m.toPrecision().toUpperCase();s=this.t.toPrecision().toUpperCase();if(this.m===0||this.t===0){return i}return i+" e^("+s+" i)"};N.prototype.equals=N.prototype["="]=function(e){var r=this.r,i=this.i,s=this.m,o=this.t,u=e.r,a=e.i,f=e.m,l=e.t,c=t.abs(r-u)<=t.max(t.abs(r),t.abs(u))*n.EPSILON,h=t.abs(i-a)<=t.max(t.abs(i),t.abs(a))*n.EPSILON,p=t.abs(s-f)<=t.max(t.abs(s),t.abs(f))*n.EPSILON,d=t.abs(o-l)<=t.max(t.abs(o),t.abs(l))*n.EPSILON;return c&&h||p&&d};N.prototype.re=N.prototype.real=function(){return this.r};N.prototype.im=N.prototype.imag=function(){return this.i};N.prototype.abs=N.prototype.mag=function(){return this.m};N.prototype.arg=N.prototype.angle=function(){return this.t};N.prototype.rAdd=function(e){return new N(this.r+e,this.i)};N.prototype.add=N.prototype["+"]=function(e){return new N(this.r+e.r,this.i+e.i)};N.prototype.rSub=function(e){return new N(this.r-e,this.i)};N.prototype.sub=N.prototype["-"]=function(e){return new N(this.r-e.r,this.i-e.i)};N.prototype.rMult=function(e){return N.Polar(this.m*e,this.t)};N.prototype.mult=N.prototype["*"]=function(e){return N.Polar(this.m*e.m,this.t+e.t)};N.prototype.rDiv=function(e){return N.Polar(this.m/e,this.t)};N.prototype.div=N.prototype["/"]=function(e){return N.Polar(this.m/e.m,this.t-e.t)};N.prototype.rMod=function(e){return new N(e===0?0:this.r%e,this.i)};N.prototype.mod=N.prototype["%"]=function(e){return new N(e.r===0?0:this.r%e.r,e.i===0?0:this.i%e.i)};N.prototype.rPow=function(e){if(e===2){return N.square(this)}if(e===3){return N.cube(this)}return N.Polar(t.pow(this.m,e),this.t*e)};N.prototype.pow=N.prototype["^"]=function(e){if(e.i===0){return this.rPow(e.r)}return N.Polar(t.pow(this.m,e.r)*t.exp(-e.i*this.t),e.i*t.log(this.m)+e.r*this.t)};N.neg=function(e){return new N(-e.r,-e.i,e.m,e.t+r)};N.re=function(e){return new N(e.r,0,t.abs(e.r),e.r<0?r:0)};N.im=function(e){return new N(e.i,0,t.abs(e.i),e.i<0?r:0)};N.abs=function(e){return new N(e.m,0,e.m,0)};N.arg=function(e){return new N(e.t,0,t.abs(e.t),e.t<0?r:0)};N.conj=function(e){return new N(e.r,-e.i,e.m,(r*2-e.t)%r*2)};N.norm=function(e){return N.Polar(e.m/e.m,e.m===0?0:e.t)};N.floor=function(e){return new N(w(e.r),w(e.i))};N.ceil=function(e){return new N(E(e.r),E(e.i))};N.round=function(e){return new N(S(e.r),S(e.i))};N.iPart=function(e){return new N(x(e.r),x(e.i))};N.fPart=function(e){return new N(T(e.r),T(e.i))};N.square=function(e){return new N(e.r*e.r-e.i*e.i,2*e.r*e.i,e.m*e.m,e.t*2)};N.cube=function(e){return new N(e.r*e.r*e.r-3*e.r*e.i*e.i,3*e.r*e.r*e.i-e.i*e.i*e.i,e.m*e.m*e.m,e.t*3)};N.sqrt=function(e){return e.rPow(.5)};N.cbrt=function(e){return e.rPow(1/3)};N.exp=function(e){return e.i===0?N.E.rPow(e.r):N.Polar(t.exp(e.r),e.i)};N.log=function(e){return new N(t.log(e.m),e.t)};N.gamma=function(e){var t,n,r,u;if(e.r<.5){return N.PI.div(N.sin(N.PI.mult(e)).mult(N.gamma(N.ONE.sub(e))))}t=e.sub(N.ONE);n=o[0];for(r=1;r<9;r++){n=n.add(o[r].div(t.add(s[r])))}u=t.add(new N(7.5,0,7.5,0));return i.mult(u.pow(t.add(new N(.5,0,.5,0)))).mult(N.exp(N.neg(u))).mult(n)};N.fact=function(e){return N.gamma(e.add(N.ONE))};N.cos=function(e){var t=e.mult(N.I);return N.exp(t).add(N.exp(N.neg(t))).div(N.TWO)};N.sin=function(e){var t=e.mult(N.I);return N.exp(t).sub(N.exp(N.neg(t))).div(N.TWO_I)};N.tan=function(e){var t=e.mult(N.I),n=N.exp(t),r=N.exp(N.neg(t));return n.sub(r).div(n.add(r).mult(N.I))};N.sec=function(e){var t=e.mult(N.I);return N.TWO.div(N.exp(t).add(N.exp(N.neg(t))))};N.csc=function(e){var t=e.mult(N.I);return N.TWO_I.div(N.exp(t).sub(N.exp(N.neg(t))))};N.cot=function(e){var t=e.mult(N.I),n=N.exp(t),r=N.exp(N.neg(t));return n.add(r).mult(N.I).div(n.sub(r))};N.arccos=function(e){return N.I.mult(N.log(e.add(N.NEG_I.mult(N.sqrt(N.ONE.sub(e.rPow(2)))))))};N.arcsin=function(e){return N.NEG_I.mult(N.log(e.mult(N.I).add(N.sqrt(N.ONE.sub(e.rPow(2))))))};N.arctan=function(e){var t=N.I;return t.mult(N.log(t.add(e).div(t.sub(e)))).div(N.TWO)};N.arcsec=function(e){return N.NEG_I.mult(N.log(e.rPow(-1).add(N.sqrt(N.ONE.sub(N.I.div(e.rPow(2)))))))};N.arccsc=function(e){return N.NEG_I.mult(N.log(N.I.div(e).add(N.sqrt(N.ONE.sub(e.rPow(-2))))))};N.arccot=function(e){var t=N.I;return t.mult(N.log(e.sub(t).div(e.add(t)))).div(N.TWO)};N.cosh=function(e){return N.exp(e).add(N.exp(N.neg(e))).div(N.TWO)};N.sinh=function(e){return N.exp(e).sub(N.exp(N.neg(e))).div(N.TWO)};N.tanh=function(e){var t=N.exp(e),n=N.exp(N.neg(e));return t.sub(n).div(t.add(n))};N.sech=function(e){return N.TWO.div(N.exp(e).add(N.exp(N.neg(e))))};N.csch=function(e){return N.TWO.div(N.exp(e).sub(N.exp(N.neg(e))))};N.coth=function(e){var t=N.exp(e),n=N.exp(N.neg(e));return t.add(n).div(t.sub(n))};N.arccosh=function(e){return N.log(e.add(N.sqrt(e.rPow(2).sub(N.ONE))))};N.arcsinh=function(e){return N.log(e.add(N.sqrt(e.rPow(2).add(N.ONE))))};N.arctanh=function(e){return N.log(N.ONE.add(e).div(N.ONE.sub(e))).div(N.TWO)};N.arcsech=function(e){return N.log(N.ONE.add(N.sqrt(N.ONE.sub(e.rPow(2)))).div(e))};N.arccsch=function(e){return N.log(N.ONE.add(N.sqrt(N.ONE.add(e.rPow(2)))).div(e))};N.arccoth=function(e){return N.log(e.add(N.ONE).div(e.sub(N.ONE))).div(N.TWO)};N.min=function(){var e=Array.prototype.slice.call(arguments).map(function(e){return e.m}),n=t.min.apply(t,e);return arguments[e.indexOf(n)]};N.max=function(){var e=Array.prototype.slice.call(arguments).map(function(e){return e.m}),n=t.max.apply(t,e);return arguments[e.indexOf(n)]};N.isNaN=function(e){return isNaN(e.r)||isNaN(e.i)||isNaN(e.m)||isNaN(e.t)};N.isFinite=function(e){return isFinite(e.m)};N.formatFunction=function(e){return e.replace(u,C)};_.prototype=[];_.prototype.push=function(){return Array.prototype.push.apply(this,arguments)-1};_.prototype.Complex=N;N.parseFunction=function(e,t,n){if(typeof t==="boolean"){n=t;t=[]}else if(!(typeof t==="object"&&t!==null&&t.constructor===Array)){t=[]}e=e.toLowerCase();if(!n){e=N.formatFunction(e)}var r=k(),i=new _,s=D(e,r,i),o=t.map(function(e){return r[e]}).join(",");return(new Function(o,"var C=this.Complex;return "+s+";")).bind(i)};if(typeof module!=="undefined"&&module!==null&&module.exports){module.exports=N}else{e.Complex=N}})(typeof global==="undefined"?this:global) \ No newline at end of file +/* Copyright (c) 2012 Patrick Roberts */(function(e){"use strict";function w(e){return e>=0?e-e%1:e-(1+e%1)%1}function E(e){return e>=0?e+(1-e%1)%1:e-e%1}function S(e){return w(e+.5)}function x(e){return e-e%1}function T(e){return e%1}function N(e,n,i,s){if(!(this instanceof N)){return new N(e,n,i,s)}if(typeof i==="number"){this.m=t.abs(i)}else{this.m=t.sqrt(e*e+n*n)}if(typeof s==="number"){this.t=i>=0?s:s+r}else{this.t=t.atan2(n,e)}this.t=r-(r*3-(r-(r*3-this.t)%(r*2)))%(r*2);this.r=e;this.i=n}function C(e,t,n){var r;if(d.test(e)){if(v.test(n.slice(t))){return e}return e.charAt(0).replace(u,C)+"*"+e.charAt(1).replace(u,C)}if(h.test(e)){return"("}if(p.test(e)){return")"}r=e.search(m);return e.charAt(r!==-1?r:"*")}function k(e){var t=/[^a-z]+/gi,n="abcdefghijklmnopqrstuvwxyz",r=n.length,i={},s="",o,u,a;e=e.map(function(e){var n=e.replace(t,"");if(e!==n){throw new SyntaxError('"'+e+'" is an invalid variable name.')}return n.toLowerCase()});for(o=0;o=0){a=u%r;u=u-a;s=n.charAt(a)+s;u=u/r-1}i[e[o]]=s;s=""}return i}function L(e,t){var n=1;while(n>0&&t0){throw new SyntaxError('Expected ")".')}return t-1}function A(e,n){var r=0,i,s;for(i=n;i1){return i}}}}return e.length}function O(e,n){var r=0,i,s;for(i=n;i1){return i}}if(e[i]==="*"||e[i]==="/"||e[i]===" "||e[i]==="%"){return i}}}return e.length}function M(e,t,n){switch(e){case"+":case"-":return A(t,n);case"*":case" ":case"/":case"%":case"^":return O(t,n);default:throw new SyntaxError('"'+e+'" is not a valid operator.')}}function _(){Array.apply(this,arguments)}function D(e,t,n){var r="",i=0,s=false,o,u,h,p,d,v;if(e.length===0){throw new SyntaxError('"" is not a valid argument.')}while(i0?"i":"-i":r+" i"}return n+(this.i>0?"+":"")+(t.abs(this.i)===1?this.i>0?"i":"-i":r+" i")}i=this.m.toPrecision().toUpperCase();s=this.t.toPrecision().toUpperCase();if(this.m===0||this.t===0){return i}return i+" e^("+s+" i)"};N.prototype.equals=N.prototype["="]=function(e){var r=this.r,i=this.i,s=this.m,o=this.t,u=e.r,a=e.i,f=e.m,l=e.t,c=t.abs(r-u)<=t.max(t.abs(r),t.abs(u))*n.EPSILON,h=t.abs(i-a)<=t.max(t.abs(i),t.abs(a))*n.EPSILON,p=t.abs(s-f)<=t.max(t.abs(s),t.abs(f))*n.EPSILON,d=t.abs(o-l)<=t.max(t.abs(o),t.abs(l))*n.EPSILON;return c&&h||p&&d};N.prototype.re=N.prototype.real=function(){return this.r};N.prototype.im=N.prototype.imag=function(){return this.i};N.prototype.abs=N.prototype.mag=function(){return this.m};N.prototype.arg=N.prototype.angle=function(){return this.t};N.prototype.rAdd=function(e){return new N(this.r+e,this.i)};N.prototype.add=N.prototype["+"]=function(e){return new N(this.r+e.r,this.i+e.i)};N.prototype.rSub=function(e){return new N(this.r-e,this.i)};N.prototype.sub=N.prototype["-"]=function(e){return new N(this.r-e.r,this.i-e.i)};N.prototype.rMult=function(e){return N.Polar(this.m*e,this.t)};N.prototype.mult=N.prototype["*"]=function(e){return N.Polar(this.m*e.m,this.t+e.t)};N.prototype.rDiv=function(e){return N.Polar(this.m/e,this.t)};N.prototype.div=N.prototype["/"]=function(e){return N.Polar(this.m/e.m,this.t-e.t)};N.prototype.rMod=function(e){return new N(e===0?0:this.r%e,this.i)};N.prototype.mod=N.prototype["%"]=function(e){return new N(e.r===0?0:this.r%e.r,e.i===0?0:this.i%e.i)};N.prototype.rPow=function(e){if(e===2){return N.square(this)}if(e===3){return N.cube(this)}return N.Polar(t.pow(this.m,e),this.t*e)};N.prototype.pow=N.prototype["^"]=function(e){if(e.i===0){return this.rPow(e.r)}return N.Polar(t.pow(this.m,e.r)*t.exp(-e.i*this.t),e.i*t.log(this.m)+e.r*this.t)};N.neg=function(e){return new N(-e.r,-e.i,e.m,e.t+r)};N.re=function(e){return new N(e.r,0,t.abs(e.r),e.r<0?r:0)};N.im=function(e){return new N(e.i,0,t.abs(e.i),e.i<0?r:0)};N.abs=function(e){return new N(e.m,0,e.m,0)};N.arg=function(e){return new N(e.t,0,t.abs(e.t),e.t<0?r:0)};N.conj=function(e){return new N(e.r,-e.i,e.m,(r*2-e.t)%r*2)};N.norm=function(e){return N.Polar(e.m/e.m,e.m===0?0:e.t)};N.floor=function(e){return new N(w(e.r),w(e.i))};N.ceil=function(e){return new N(E(e.r),E(e.i))};N.round=function(e){return new N(S(e.r),S(e.i))};N.iPart=function(e){return new N(x(e.r),x(e.i))};N.fPart=function(e){return new N(T(e.r),T(e.i))};N.square=function(e){return new N(e.r*e.r-e.i*e.i,2*e.r*e.i,e.m*e.m,e.t*2)};N.cube=function(e){return new N(e.r*e.r*e.r-3*e.r*e.i*e.i,3*e.r*e.r*e.i-e.i*e.i*e.i,e.m*e.m*e.m,e.t*3)};N.sqrt=function(e){return e.rPow(.5)};N.cbrt=function(e){return e.rPow(1/3)};N.exp=function(e){return e.i===0?N.E.rPow(e.r):N.Polar(t.exp(e.r),e.i)};N.log=function(e){return new N(t.log(e.m),e.t)};N.gamma=function(e){var t,n,r,u;if(e.r<.5){return N.PI.div(N.sin(N.PI.mult(e)).mult(N.gamma(N.ONE.sub(e))))}t=e.sub(N.ONE);n=o[0];for(r=1;r<9;r++){n=n.add(o[r].div(t.add(s[r])))}u=t.add(new N(7.5,0,7.5,0));return i.mult(u.pow(t.add(new N(.5,0,.5,0)))).mult(N.exp(N.neg(u))).mult(n)};N.fact=function(e){return N.gamma(e.add(N.ONE))};N.cos=function(e){var t=e.mult(N.I);return N.exp(t).add(N.exp(N.neg(t))).div(N.TWO)};N.sin=function(e){var t=e.mult(N.I);return N.exp(t).sub(N.exp(N.neg(t))).div(N.TWO_I)};N.tan=function(e){var t=e.mult(N.I),n=N.exp(t),r=N.exp(N.neg(t));return n.sub(r).div(n.add(r).mult(N.I))};N.sec=function(e){var t=e.mult(N.I);return N.TWO.div(N.exp(t).add(N.exp(N.neg(t))))};N.csc=function(e){var t=e.mult(N.I);return N.TWO_I.div(N.exp(t).sub(N.exp(N.neg(t))))};N.cot=function(e){var t=e.mult(N.I),n=N.exp(t),r=N.exp(N.neg(t));return n.add(r).mult(N.I).div(n.sub(r))};N.arccos=function(e){return N.I.mult(N.log(e.add(N.NEG_I.mult(N.sqrt(N.ONE.sub(e.rPow(2)))))))};N.arcsin=function(e){return N.NEG_I.mult(N.log(e.mult(N.I).add(N.sqrt(N.ONE.sub(e.rPow(2))))))};N.arctan=function(e){var t=N.I;return t.mult(N.log(t.add(e).div(t.sub(e)))).div(N.TWO)};N.arcsec=function(e){return N.NEG_I.mult(N.log(e.rPow(-1).add(N.sqrt(N.ONE.sub(N.I.div(e.rPow(2)))))))};N.arccsc=function(e){return N.NEG_I.mult(N.log(N.I.div(e).add(N.sqrt(N.ONE.sub(e.rPow(-2))))))};N.arccot=function(e){var t=N.I;return t.mult(N.log(e.sub(t).div(e.add(t)))).div(N.TWO)};N.cosh=function(e){return N.exp(e).add(N.exp(N.neg(e))).div(N.TWO)};N.sinh=function(e){return N.exp(e).sub(N.exp(N.neg(e))).div(N.TWO)};N.tanh=function(e){var t=N.exp(e),n=N.exp(N.neg(e));return t.sub(n).div(t.add(n))};N.sech=function(e){return N.TWO.div(N.exp(e).add(N.exp(N.neg(e))))};N.csch=function(e){return N.TWO.div(N.exp(e).sub(N.exp(N.neg(e))))};N.coth=function(e){var t=N.exp(e),n=N.exp(N.neg(e));return t.add(n).div(t.sub(n))};N.arccosh=function(e){return N.log(e.add(N.sqrt(e.rPow(2).sub(N.ONE))))};N.arcsinh=function(e){return N.log(e.add(N.sqrt(e.rPow(2).add(N.ONE))))};N.arctanh=function(e){return N.log(N.ONE.add(e).div(N.ONE.sub(e))).div(N.TWO)};N.arcsech=function(e){return N.log(N.ONE.add(N.sqrt(N.ONE.sub(e.rPow(2)))).div(e))};N.arccsch=function(e){return N.log(N.ONE.add(N.sqrt(N.ONE.add(e.rPow(2)))).div(e))};N.arccoth=function(e){return N.log(e.add(N.ONE).div(e.sub(N.ONE))).div(N.TWO)};N.min=function(){var e=Array.prototype.slice.call(arguments).map(function(e){return e.m}),n=t.min.apply(t,e);return arguments[e.indexOf(n)]};N.max=function(){var e=Array.prototype.slice.call(arguments).map(function(e){return e.m}),n=t.max.apply(t,e);return arguments[e.indexOf(n)]};N.isNaN=function(e){return isNaN(e.r)||isNaN(e.i)||isNaN(e.m)||isNaN(e.t)};N.isFinite=function(e){return isFinite(e.m)};N.formatFunction=function(e){return e.replace(u,C)};_.prototype=[];_.prototype.push=function(){return Array.prototype.push.apply(this,arguments)-1};_.prototype.Complex=N;N.parseFunction=function(e,t,n){if(typeof t==="boolean"){n=t;t=[]}else if(!(typeof t==="object"&&t!==null&&t.constructor===Array)){t=[]}e=e.toLowerCase();if(!n){e=N.formatFunction(e)}var r=k(t),i=new _,s=D(e,r,i),o=t.map(function(e){return r[e]}).join(",");return(new Function(o,"var C=this.Complex;return "+s+";")).bind(i)};if(typeof module!=="undefined"&&module!==null&&module.exports){module.exports=N}else{e.Complex=N}})(typeof global==="undefined"?this:global) \ No newline at end of file