Socket
Socket
Sign inDemoInstall

complex.js

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

complex.js - npm Package Compare versions

Comparing version 2.0.13 to 2.0.14

complex.d.ts

2

bower.json
{
"name": "complex.js",
"main": "complex.js",
"version": "2.0.13",
"version": "2.0.14",
"homepage": "https://github.com/infusion/Complex.js",

@@ -6,0 +6,0 @@ "description": "A complex number library",

/**
* @license Complex.js v2.0.13 12/05/2020
* @license Complex.js v2.0.14 12/05/2020
*

@@ -49,3 +49,3 @@ * Copyright (c) 2020, Robert Eisele (robert@xarg.org)

/**
* Calculates cos(x) - 1 using Taylor series if x is small.
* Calculates cos(x) - 1 using Taylor series if x is small (-¼π ≤ x ≤ ¼π).
*

@@ -55,26 +55,37 @@ * @param {number} x

*/
var cosm1 = function(x) {
var cosm1 = function(x) {
var limit = Math.PI/4;
if (x < -limit || x > limit) {
return (Math.cos(x) - 1.0);
var b = Math.PI / 4;
if (-b > x || x > b) {
return Math.cos(x) - 1.0;
}
/* Calculate horner form of polynomial of taylor series in Q
var fac = 1, alt = 1, pol = {};
for (var i = 0; i <= 16; i++) {
fac*= i || 1;
if (i % 2 == 0) {
pol[i] = new Fraction(1, alt * fac);
alt = -alt;
}
}
console.log(new Polynomial(pol).toHorner()); // (((((((1/20922789888000x^2-1/87178291200)x^2+1/479001600)x^2-1/3628800)x^2+1/40320)x^2-1/720)x^2+1/24)x^2-1/2)x^2+1
*/
var xx = x * x;
return xx *
(-0.5 + xx *
(1/24 + xx *
(-1/720 + xx *
(1/40320 + xx *
(-1/3628800 + xx *
(1/4790014600 + xx *
(-1/87178291200 + xx *
(1/20922789888000)
)
)
)
)
)
)
)
return xx * (
xx * (
xx * (
xx * (
xx * (
xx * (
xx * (
xx / 20922789888000
- 1 / 87178291200)
+ 1 / 479001600)
- 1 / 3628800)
+ 1 / 40320)
- 1 / 720)
+ 1 / 24)
- 1 / 2);
};

@@ -165,7 +176,7 @@

var z = {'re': 0, 'im': 0};
var z = { 're': 0, 'im': 0 };
if (a === undefined || a === null) {
z['re'] =
z['im'] = 0;
z['im'] = 0;
} else if (b !== undefined) {

@@ -205,3 +216,3 @@ z['re'] = a;

z['im'] = /* void */
z['re'] = 0;
z['re'] = 0;

@@ -310,4 +321,4 @@ var tokens = a.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g);

return new Complex(
this['re'] / abs,
this['im'] / abs);
this['re'] / abs,
this['im'] / abs);
},

@@ -335,4 +346,4 @@

return new Complex(
this['re'] + z['re'],
this['im'] + z['im']);
this['re'] + z['re'],
this['im'] + z['im']);
},

@@ -360,4 +371,4 @@

return new Complex(
this['re'] - z['re'],
this['im'] - z['im']);
this['re'] - z['re'],
this['im'] - z['im']);
},

@@ -390,4 +401,4 @@

return new Complex(
this['re'] * z['re'] - this['im'] * z['im'],
this['re'] * z['im'] + this['im'] * z['re']);
this['re'] * z['re'] - this['im'] * z['im'],
this['re'] * z['im'] + this['im'] * z['re']);
},

@@ -437,4 +448,4 @@

return new Complex(
(a * x + b) / t,
(b * x - a) / t);
(a * x + b) / t,
(b * x - a) / t);

@@ -447,4 +458,4 @@ } else {

return new Complex(
(a + b * x) / t,
(b - a * x) / t);
(a + b * x) / t,
(b - a * x) / t);
}

@@ -520,4 +531,4 @@ },

return new Complex(
a * Math.cos(b),
a * Math.sin(b));
a * Math.cos(b),
a * Math.sin(b));
},

@@ -571,4 +582,4 @@

return new Complex(
tmp * Math.cos(this['im']),
tmp * Math.sin(this['im']));
tmp * Math.cos(this['im']),
tmp * Math.sin(this['im']));
},

@@ -596,4 +607,4 @@

return new Complex(
Math.expm1(a) * Math.cos(b) + cosm1(b),
Math.exp(a) * Math.sin(b));
Math.expm1(a) * Math.cos(b) + cosm1(b),
Math.exp(a) * Math.sin(b));
},

@@ -616,4 +627,4 @@

return new Complex(
logHypot(a, b),
Math.atan2(b, a));
logHypot(a, b),
Math.atan2(b, a));
},

@@ -654,4 +665,4 @@

return new Complex(
Math.sin(a) * cosh(b),
Math.cos(a) * sinh(b));
Math.sin(a) * cosh(b),
Math.cos(a) * sinh(b));
},

@@ -672,4 +683,4 @@

return new Complex(
Math.cos(a) * cosh(b),
-Math.sin(a) * sinh(b));
Math.cos(a) * cosh(b),
-Math.sin(a) * sinh(b));
},

@@ -691,4 +702,4 @@

return new Complex(
Math.sin(a) / d,
sinh(b) / d);
Math.sin(a) / d,
sinh(b) / d);
},

@@ -710,4 +721,4 @@

return new Complex(
-Math.sin(a) / d,
sinh(b) / d);
-Math.sin(a) / d,
sinh(b) / d);
},

@@ -729,4 +740,4 @@

return new Complex(
Math.cos(a) * cosh(b) / d,
Math.sin(a) * sinh(b) / d);
Math.cos(a) * cosh(b) / d,
Math.sin(a) * sinh(b) / d);
},

@@ -748,4 +759,4 @@

return new Complex(
Math.sin(a) * cosh(b) / d,
-Math.cos(a) * sinh(b) / d);
Math.sin(a) * cosh(b) / d,
-Math.cos(a) * sinh(b) / d);
},

@@ -766,8 +777,8 @@

var t1 = new Complex(
b * b - a * a + 1,
-2 * a * b)['sqrt']();
b * b - a * a + 1,
-2 * a * b)['sqrt']();
var t2 = new Complex(
t1['re'] - b,
t1['im'] + a)['log']();
t1['re'] - b,
t1['im'] + a)['log']();

@@ -790,8 +801,8 @@ return new Complex(t2['im'], -t2['re']);

var t1 = new Complex(
b * b - a * a + 1,
-2 * a * b)['sqrt']();
b * b - a * a + 1,
-2 * a * b)['sqrt']();
var t2 = new Complex(
t1['re'] - b,
t1['im'] + a)['log']();
t1['re'] - b,
t1['im'] + a)['log']();

@@ -827,4 +838,4 @@ return new Complex(Math.PI / 2 - t2['im'], t2['re']);

var t1 = new Complex(
(1 - b * b - a * a) / d,
-2 * a / d).log();
(1 - b * b - a * a) / d,
-2 * a / d).log();

@@ -852,8 +863,8 @@ return new Complex(-0.5 * t1['im'], 0.5 * t1['re']);

return (d !== 0)
? new Complex(
a / d,
-b / d).atan()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).atan();
? new Complex(
a / d,
-b / d).atan()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).atan();
},

@@ -879,8 +890,8 @@

return (d !== 0)
? new Complex(
a / d,
-b / d).acos()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).acos();
? new Complex(
a / d,
-b / d).acos()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).acos();
},

@@ -906,8 +917,8 @@

return (d !== 0)
? new Complex(
a / d,
-b / d).asin()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).asin();
? new Complex(
a / d,
-b / d).asin()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).asin();
},

@@ -928,4 +939,4 @@

return new Complex(
sinh(a) * Math.cos(b),
cosh(a) * Math.sin(b));
sinh(a) * Math.cos(b),
cosh(a) * Math.sin(b));
},

@@ -946,4 +957,4 @@

return new Complex(
cosh(a) * Math.cos(b),
sinh(a) * Math.sin(b));
cosh(a) * Math.cos(b),
sinh(a) * Math.sin(b));
},

@@ -965,4 +976,4 @@

return new Complex(
sinh(a) / d,
Math.sin(b) / d);
sinh(a) / d,
Math.sin(b) / d);
},

@@ -984,4 +995,4 @@

return new Complex(
sinh(a) / d,
-Math.sin(b) / d);
sinh(a) / d,
-Math.sin(b) / d);
},

@@ -1003,4 +1014,4 @@

return new Complex(
-2 * sinh(a) * Math.cos(b) / d,
2 * cosh(a) * Math.sin(b) / d);
-2 * sinh(a) * Math.cos(b) / d,
2 * cosh(a) * Math.sin(b) / d);
},

@@ -1022,4 +1033,4 @@

return new Complex(
2 * cosh(a) * Math.cos(b) / d,
-2 * sinh(a) * Math.sin(b) / d);
2 * cosh(a) * Math.cos(b) / d,
-2 * sinh(a) * Math.sin(b) / d);
},

@@ -1090,8 +1101,8 @@

var x = (d !== 0)
? new Complex(
(onePlus * oneMinus - b * b) / d,
(b * oneMinus + onePlus * b) / d)
: new Complex(
(a !== -1) ? (a / 0) : 0,
(b !== 0) ? (b / 0) : 0);
? new Complex(
(onePlus * oneMinus - b * b) / d,
(b * oneMinus + onePlus * b) / d)
: new Complex(
(a !== -1) ? (a / 0) : 0,
(b !== 0) ? (b / 0) : 0);

@@ -1125,8 +1136,8 @@ var temp = x['re'];

return (d !== 0)
? new Complex(
a / d,
-b / d).atanh()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).atanh();
? new Complex(
a / d,
-b / d).atanh()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).atanh();
},

@@ -1149,5 +1160,5 @@

return new Complex(
(a !== 0)
? Math.log(a + Math.sqrt(a * a + 1))
: Infinity, 0);
(a !== 0)
? Math.log(a + Math.sqrt(a * a + 1))
: Infinity, 0);
}

@@ -1157,8 +1168,8 @@

return (d !== 0)
? new Complex(
a / d,
-b / d).asinh()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).asinh();
? new Complex(
a / d,
-b / d).asinh()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).asinh();
},

@@ -1184,8 +1195,8 @@

return (d !== 0)
? new Complex(
a / d,
-b / d).acosh()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).acosh();
? new Complex(
a / d,
-b / d).acosh()
: new Complex(
(a !== 0) ? a / 0 : 0,
(b !== 0) ? -b / 0 : 0).acosh();
},

@@ -1247,4 +1258,4 @@

return new Complex(
Math.ceil(this['re'] * places) / places,
Math.ceil(this['im'] * places) / places);
Math.ceil(this['re'] * places) / places,
Math.ceil(this['im'] * places) / places);
},

@@ -1262,4 +1273,4 @@

return new Complex(
Math.floor(this['re'] * places) / places,
Math.floor(this['im'] * places) / places);
Math.floor(this['re'] * places) / places,
Math.floor(this['im'] * places) / places);
},

@@ -1277,4 +1288,4 @@

return new Complex(
Math.round(this['re'] * places) / places,
Math.round(this['im'] * places) / places);
Math.round(this['re'] * places) / places,
Math.round(this['im'] * places) / places);
},

@@ -1294,3 +1305,3 @@

return Math.abs(z['re'] - this['re']) <= Complex['EPSILON'] &&
Math.abs(z['im'] - this['im']) <= Complex['EPSILON'];
Math.abs(z['im'] - this['im']) <= Complex['EPSILON'];
},

@@ -1341,18 +1352,18 @@

if (a !== 0) {
ret+= a;
ret+= " ";
ret += a;
ret += " ";
if (b < 0) {
b = -b;
ret+= "-";
ret += "-";
} else {
ret+= "+";
ret += "+";
}
ret+= " ";
ret += " ";
} else if (b < 0) {
b = -b;
ret+= "-";
ret += "-";
}
if (1 !== b) { // b is the absolute imaginary part
ret+= b;
ret += b;
}

@@ -1439,3 +1450,3 @@ return ret + "i";

} else if (typeof exports === 'object') {
Object.defineProperty(Complex, "__esModule", {'value': true});
Object.defineProperty(Complex, "__esModule", { 'value': true });
Complex['default'] = Complex;

@@ -1442,0 +1453,0 @@ Complex['Complex'] = Complex;

/*
Complex.js v2.0.13 12/05/2020
Complex.js v2.0.14 12/05/2020

@@ -13,4 +13,4 @@ Copyright (c) 2020, Robert Eisele (robert@xarg.org)

a=this.re;b=this.im;if(c.isZero())return d.ONE;if(0===c.im){if(0===b&&0<a)return new d(Math.pow(a,c.re),0);if(0===a)switch((c.re%4+4)%4){case 0:return new d(Math.pow(b,c.re),0);case 1:return new d(0,Math.pow(b,c.re));case 2:return new d(-Math.pow(b,c.re),0);case 3:return new d(0,-Math.pow(b,c.re))}}if(0===a&&0===b&&0<c.re&&0<=c.im)return d.ZERO;var e=Math.atan2(b,a),f=p(a,b);a=Math.exp(c.re*f-c.im*e);b=c.im*f+c.re*e;return new d(a*Math.cos(b),a*Math.sin(b))},sqrt:function(){var a=this.re,b=this.im,
c=this.abs();if(0<=a){if(0===b)return new d(Math.sqrt(a),0);var e=.5*Math.sqrt(2*(c+a))}else e=Math.abs(b)/Math.sqrt(2*(c-a));a=0>=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))},expm1:function(){var a=this.re,b=this.im,c=Math.expm1(a)*Math.cos(b);var e=Math.PI/4;b<-e||b>e?e=Math.cos(b)-1:(e=b*b,e*=-.5+e*(1/24+e*(-1/720+e*(1/40320+e*(-1/3628800+e*(1/4790014600+e*(-1/87178291200+
1/20922789888E3*e)))))));return new d(c+e,Math.exp(a)*Math.sin(b))},log:function(){var a=this.re,b=this.im;return new d(p(a,b),Math.atan2(b,a))},abs:function(){var a=this.re;var b=this.im,c=Math.abs(a),e=Math.abs(b);3E3>c&&3E3>e?a=Math.sqrt(c*c+e*e):(c<e?(c=e,e=a/b):e=b/a,a=c*Math.sqrt(1+e*e));return a},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){var a=this.re,b=this.im;return new d(Math.sin(a)*g(b),Math.cos(a)*k(b))},cos:function(){var a=this.re,b=this.im;return new d(Math.cos(a)*
c=this.abs();if(0<=a){if(0===b)return new d(Math.sqrt(a),0);var e=.5*Math.sqrt(2*(c+a))}else e=Math.abs(b)/Math.sqrt(2*(c-a));a=0>=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))},expm1:function(){var a=this.re,b=this.im,c=Math.expm1(a)*Math.cos(b);var e=Math.PI/4;-e>b||b>e?e=Math.cos(b)-1:(e=b*b,e*=e*(e*(e*(e*(e*(e*(e/20922789888E3-1/87178291200)+1/479001600)-1/3628800)+1/
40320)-1/720)+1/24)-.5);return new d(c+e,Math.exp(a)*Math.sin(b))},log:function(){var a=this.re,b=this.im;return new d(p(a,b),Math.atan2(b,a))},abs:function(){var a=this.re;var b=this.im,c=Math.abs(a),e=Math.abs(b);3E3>c&&3E3>e?a=Math.sqrt(c*c+e*e):(c<e?(c=e,e=a/b):e=b/a,a=c*Math.sqrt(1+e*e));return a},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){var a=this.re,b=this.im;return new d(Math.sin(a)*g(b),Math.cos(a)*k(b))},cos:function(){var a=this.re,b=this.im;return new d(Math.cos(a)*
g(b),-Math.sin(a)*k(b))},tan:function(){var a=2*this.re,b=2*this.im,c=Math.cos(a)+g(b);return new d(Math.sin(a)/c,k(b)/c)},cot:function(){var a=2*this.re,b=2*this.im,c=Math.cos(a)-g(b);return new d(-Math.sin(a)/c,k(b)/c)},sec:function(){var a=this.re,b=this.im,c=.5*g(2*b)+.5*Math.cos(2*a);return new d(Math.cos(a)*g(b)/c,Math.sin(a)*k(b)/c)},csc:function(){var a=this.re,b=this.im,c=.5*g(2*b)-.5*Math.cos(2*a);return new d(Math.sin(a)*g(b)/c,-Math.cos(a)*k(b)/c)},asin:function(){var a=this.re,b=this.im,

@@ -25,2 +25,2 @@ c=(new d(b*b-a*a+1,-2*a*b)).sqrt();a=(new d(c.re-b,c.im+a)).log();return new d(a.im,-a.re)},acos:function(){var a=this.re,b=this.im,c=(new d(b*b-a*a+1,-2*a*b)).sqrt();a=(new d(c.re-b,c.im+a)).log();return new d(Math.PI/2-a.im,a.re)},atan:function(){var a=this.re,b=this.im;if(0===a){if(1===b)return new d(0,Infinity);if(-1===b)return new d(0,-Infinity)}var c=a*a+(1-b)*(1-b);a=(new d((1-b*b-a*a)/c,-2*a/c)).log();return new d(-.5*a.im,.5*a.re)},acot:function(){var a=this.re,b=this.im;if(0===b)return new d(Math.atan2(1,

" ",0>b?(b=-b,c+="-"):c+="+",c+=" "):0>b&&(b=-b,c+="-");1!==b&&(c+=b);return c+"i"},toVector:function(){return[this.re,this.im]},valueOf:function(){return 0===this.im?this.re:null},isNaN:function(){return isNaN(this.re)||isNaN(this.im)},isZero:function(){return 0===this.im&&0===this.re},isFinite:function(){return isFinite(this.re)&&isFinite(this.im)},isInfinite:function(){return!(this.isNaN()||this.isFinite())}};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.INFINITY=new d(Infinity,Infinity);d.NAN=new d(NaN,NaN);d.EPSILON=1E-15;"function"===typeof define&&define.amd?define([],function(){return d}):"object"===typeof exports?(Object.defineProperty(d,"__esModule",{value:!0}),d["default"]=d,d.Complex=d,module.exports=d):q.Complex=d})(this);
0);d.INFINITY=new d(Infinity,Infinity);d.NAN=new d(NaN,NaN);d.EPSILON=1E-15;"function"===typeof define&&define.amd?define([],function(){return d}):"object"===typeof exports?(Object.defineProperty(d,"__esModule",{value:!0}),d["default"]=d,d.Complex=d,module.exports=d):q.Complex=d})(this);

@@ -6,3 +6,3 @@ {

"title": "complex.js",
"version": "2.0.13",
"version": "2.0.14",
"description": "A complex number library",

@@ -20,2 +20,3 @@ "keywords": [

"main": "complex",
"types": "complex.d.ts",
"private": false,

@@ -26,3 +27,3 @@ "directories": {

"readmeFilename": "README.md",
"license": "MIT OR GPL-2.0-or-later",
"license": "MIT",
"repository": {

@@ -32,2 +33,6 @@ "type": "git",

},
"funding": {
"type": "patreon",
"url": "https://www.patreon.com/infusion"
},
"engines": {

@@ -34,0 +39,0 @@ "node": "*"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc