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.7 to 2.0.9

2

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

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

/**
* @license Complex.js v2.0.7 11/02/2016
* @license Complex.js v2.0.9 11/02/2016
*

@@ -131,9 +131,9 @@ * Copyright (c) 2016, Robert Eisele (robert@xarg.org)

* 1. Only eliminate the square root: (OVERALL ERROR: 3.9122483030951116e-11)
Math.log(a * a + b * b) / 2
*
*
* 2. Try to use the non-overflowing pythagoras: (OVERALL ERROR: 8.889760039210159e-10)
var fn = function(a, b) {

@@ -145,14 +145,14 @@ a = Math.abs(a);

t = t / a;
return Math.log(a) + Math.log(1 + t * t) / 2;
};
* 3. Abuse the identity cos(atan(y/x) = x / sqrt(x^2+y^2): (OVERALL ERROR: 3.4780178737037204e-10)
Math.log(a / Math.cos(Math.atan2(b, a)))
* 4. Use 3. and apply log rules: (OVERALL ERROR: 1.2014087502620896e-9)
Math.log(a) - Math.log(Math.cos(Math.atan2(b, a)))
*/

@@ -502,2 +502,6 @@

if (a === 0 && b === 0 && z['re'] > 0 && z['im'] >= 0) {
return Complex['ZERO'];
}
var arg = Math.atan2(b, a);

@@ -504,0 +508,0 @@ var loh = logHypot(a, b);

/*
Complex.js v2.0.7 11/02/2016
Complex.js v2.0.9 11/02/2016
Copyright (c) 2016, Robert Eisele (robert@xarg.org)
Dual licensed under the MIT or GPL Version 2 licenses.
Copyright (c) 2016, Robert Eisele (robert@xarg.org)
Dual licensed under the MIT or GPL Version 2 licenses.
*/

@@ -12,13 +12,13 @@ (function(n){function h(){throw SyntaxError("Invalid Param");}function g(a){return.5*(Math.exp(a)-Math.exp(-a))}function e(a){return.5*(Math.exp(a)+Math.exp(-a))}function m(a,b){var c=Math.abs(a),d=Math.abs(b);return 0===a?Math.log(d):0===b?Math.log(c):3E3>c&&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);var c={re:0,im:0};if(void 0===a||null===a)c.re=c.im=0;else if(void 0!==b)c.re=a,c.im=b;else switch(typeof a){case "object":"im"in

this.a()&&c.a())return d.NAN;if(this.a()||c.b())return d.INFINITY;if(this.b()||c.a())return d.ZERO;a=this.re;b=this.im;var f=c.re,e=c.im;if(0===e)return new d(a/f,b/f);if(Math.abs(f)<Math.abs(e))return c=f/e,f=f*c+e,new d((a*c+b)/f,(b*c-a)/f);c=e/f;f=e*c+f;return new d((a+b*c)/f,(b-a*c)/f)},pow:function(a,b){var c=new d(a,b);a=this.re;b=this.im;if(c.b())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))}}var f=Math.atan2(b,a),e=m(a,b);a=Math.exp(c.re*e-c.im*f);b=c.im*e+c.re*f;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 f=.5*Math.sqrt(2*(c+a))}else f=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(f,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;var c=Math.PI/4;b<-c||b>c?c=Math.cos(b)-1:(c=b*b,c*=-.5+c*(1/24+c*(-1/720+c*(1/40320+c*(-1/3628800+c*(1/4790014600+c*(-1/87178291200+1/20922789888E3*c)))))));return new d(Math.expm1(a)*Math.cos(b)+c,Math.exp(a)*Math.sin(b))},log:function(){var a=this.re,b=this.im;return new d(m(a,b),Math.atan2(b,a))},abs:function(){var a=this.re;var b=this.im,c=Math.abs(a),d=Math.abs(b);3E3>c&&3E3>d?a=Math.sqrt(c*c+d*d):
(c<d?(c=d,d=a/b):d=b/a,a=c*Math.sqrt(1+d*d));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)*e(b),Math.cos(a)*g(b))},cos:function(){var a=this.re,b=this.im;return new d(Math.cos(a)*e(b),-Math.sin(a)*g(b))},tan:function(){var a=2*this.re,b=2*this.im,c=Math.cos(a)+e(b);return new d(Math.sin(a)/c,g(b)/c)},cot:function(){var a=2*this.re,b=2*this.im,c=Math.cos(a)-e(b);return new d(-Math.sin(a)/c,g(b)/c)},sec:function(){var a=
this.re,b=this.im,c=.5*e(2*b)+.5*Math.cos(2*a);return new d(Math.cos(a)*e(b)/c,Math.sin(a)*g(b)/c)},csc:function(){var a=this.re,b=this.im,c=.5*e(2*b)-.5*Math.cos(2*a);return new d(Math.sin(a)*e(b)/c,-Math.cos(a)*g(b)/c)},asin: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(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,a),0);var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).atan():(new d(0!==a?a/0:0,0!==b?-b/0:0)).atan()},asec:function(){var a=this.re,b=this.im;if(0===a&&0===b)return new d(0,Infinity);var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).acos():(new d(0!==
a?a/0:0,0!==b?-b/0:0)).acos()},acsc:function(){var a=this.re,b=this.im;if(0===a&&0===b)return new d(Math.PI/2,Infinity);var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).asin():(new d(0!==a?a/0:0,0!==b?-b/0:0)).asin()},sinh:function(){var a=this.re,b=this.im;return new d(g(a)*Math.cos(b),e(a)*Math.sin(b))},cosh:function(){var a=this.re,b=this.im;return new d(e(a)*Math.cos(b),g(a)*Math.sin(b))},tanh:function(){var a=2*this.re,b=2*this.im,c=e(a)+Math.cos(b);return new d(g(a)/c,Math.sin(b)/c)},coth:function(){var a=
2*this.re,b=2*this.im,c=e(a)-Math.cos(b);return new d(g(a)/c,-Math.sin(b)/c)},csch:function(){var a=this.re,b=this.im,c=Math.cos(2*b)-e(2*a);return new d(-2*g(a)*Math.cos(b)/c,2*e(a)*Math.sin(b)/c)},sech:function(){var a=this.re,b=this.im,c=Math.cos(2*b)+e(2*a);return new d(2*e(a)*Math.cos(b)/c,-2*g(a)*Math.sin(b)/c)},asinh:function(){var a=this.im;this.im=-this.re;this.re=a;var b=this.asin();this.re=-this.im;this.im=a;a=b.re;b.re=-b.im;b.im=a;return b},acosh:function(){var a=this.acos();if(0>=a.im){var b=
a.re;a.re=-a.im;a.im=b}else b=a.im,a.im=-a.re,a.re=b;return a},atanh:function(){var a=this.re,b=this.im,c=1<a&&0===b,e=1-a,g=1+a,h=e*e+b*b;a=0!==h?new d((g*e-b*b)/h,(b*e+g*b)/h):new d(-1!==a?a/0:0,0!==b?b/0:0);b=a.re;a.re=m(a.re,a.im)/2;a.im=Math.atan2(a.im,b)/2;c&&(a.im=-a.im);return a},acoth:function(){var a=this.re,b=this.im;if(0===a&&0===b)return new d(0,Math.PI/2);var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).atanh():(new d(0!==a?a/0:0,0!==b?-b/0:0)).atanh()},acsch:function(){var a=this.re,b=
this.im;if(0===b)return new d(0!==a?Math.log(a+Math.sqrt(a*a+1)):Infinity,0);var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).asinh():(new d(0!==a?a/0:0,0!==b?-b/0:0)).asinh()},asech:function(){var a=this.re,b=this.im;if(this.b())return d.INFINITY;var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).acosh():(new d(0!==a?a/0:0,0!==b?-b/0:0)).acosh()},inverse:function(){if(this.b())return d.INFINITY;if(this.a())return d.ZERO;var a=this.re,b=this.im,c=a*a+b*b;return new d(a/c,-b/c)},conjugate:function(){return new d(this.re,
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 f=Math.atan2(b,a),e=m(a,b);a=Math.exp(c.re*e-c.im*f);b=c.im*e+c.re*f;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 f=.5*Math.sqrt(2*(c+a))}else f=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(f,
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;var c=Math.PI/4;b<-c||b>c?c=Math.cos(b)-1:(c=b*b,c*=-.5+c*(1/24+c*(-1/720+c*(1/40320+c*(-1/3628800+c*(1/4790014600+c*(-1/87178291200+1/20922789888E3*c)))))));return new d(Math.expm1(a)*Math.cos(b)+c,Math.exp(a)*Math.sin(b))},log:function(){var a=this.re,b=this.im;return new d(m(a,b),Math.atan2(b,a))},abs:function(){var a=this.re;var b=this.im,c=Math.abs(a),
d=Math.abs(b);3E3>c&&3E3>d?a=Math.sqrt(c*c+d*d):(c<d?(c=d,d=a/b):d=b/a,a=c*Math.sqrt(1+d*d));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)*e(b),Math.cos(a)*g(b))},cos:function(){var a=this.re,b=this.im;return new d(Math.cos(a)*e(b),-Math.sin(a)*g(b))},tan:function(){var a=2*this.re,b=2*this.im,c=Math.cos(a)+e(b);return new d(Math.sin(a)/c,g(b)/c)},cot:function(){var a=2*this.re,b=2*this.im,c=Math.cos(a)-e(b);return new d(-Math.sin(a)/
c,g(b)/c)},sec:function(){var a=this.re,b=this.im,c=.5*e(2*b)+.5*Math.cos(2*a);return new d(Math.cos(a)*e(b)/c,Math.sin(a)*g(b)/c)},csc:function(){var a=this.re,b=this.im,c=.5*e(2*b)-.5*Math.cos(2*a);return new d(Math.sin(a)*e(b)/c,-Math.cos(a)*g(b)/c)},asin: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(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,a),0);var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).atan():(new d(0!==a?a/0:0,0!==b?-b/0:0)).atan()},asec:function(){var a=this.re,b=this.im;if(0===a&&0===b)return new d(0,Infinity);var c=a*a+b*b;return 0!==
c?(new d(a/c,-b/c)).acos():(new d(0!==a?a/0:0,0!==b?-b/0:0)).acos()},acsc:function(){var a=this.re,b=this.im;if(0===a&&0===b)return new d(Math.PI/2,Infinity);var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).asin():(new d(0!==a?a/0:0,0!==b?-b/0:0)).asin()},sinh:function(){var a=this.re,b=this.im;return new d(g(a)*Math.cos(b),e(a)*Math.sin(b))},cosh:function(){var a=this.re,b=this.im;return new d(e(a)*Math.cos(b),g(a)*Math.sin(b))},tanh:function(){var a=2*this.re,b=2*this.im,c=e(a)+Math.cos(b);return new d(g(a)/
c,Math.sin(b)/c)},coth:function(){var a=2*this.re,b=2*this.im,c=e(a)-Math.cos(b);return new d(g(a)/c,-Math.sin(b)/c)},csch:function(){var a=this.re,b=this.im,c=Math.cos(2*b)-e(2*a);return new d(-2*g(a)*Math.cos(b)/c,2*e(a)*Math.sin(b)/c)},sech:function(){var a=this.re,b=this.im,c=Math.cos(2*b)+e(2*a);return new d(2*e(a)*Math.cos(b)/c,-2*g(a)*Math.sin(b)/c)},asinh:function(){var a=this.im;this.im=-this.re;this.re=a;var b=this.asin();this.re=-this.im;this.im=a;a=b.re;b.re=-b.im;b.im=a;return b},acosh:function(){var a=
this.acos();if(0>=a.im){var b=a.re;a.re=-a.im;a.im=b}else b=a.im,a.im=-a.re,a.re=b;return a},atanh:function(){var a=this.re,b=this.im,c=1<a&&0===b,e=1-a,g=1+a,h=e*e+b*b;a=0!==h?new d((g*e-b*b)/h,(b*e+g*b)/h):new d(-1!==a?a/0:0,0!==b?b/0:0);b=a.re;a.re=m(a.re,a.im)/2;a.im=Math.atan2(a.im,b)/2;c&&(a.im=-a.im);return a},acoth:function(){var a=this.re,b=this.im;if(0===a&&0===b)return new d(0,Math.PI/2);var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).atanh():(new d(0!==a?a/0:0,0!==b?-b/0:0)).atanh()},acsch:function(){var a=
this.re,b=this.im;if(0===b)return new d(0!==a?Math.log(a+Math.sqrt(a*a+1)):Infinity,0);var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).asinh():(new d(0!==a?a/0:0,0!==b?-b/0:0)).asinh()},asech:function(){var a=this.re,b=this.im;if(this.b())return d.INFINITY;var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).acosh():(new d(0!==a?a/0:0,0!==b?-b/0:0)).acosh()},inverse:function(){if(this.b())return d.INFINITY;if(this.a())return d.ZERO;var a=this.re,b=this.im,c=a*a+b*b;return new d(a/c,-b/c)},conjugate:function(){return new d(this.re,
-this.im)},neg:function(){return new d(-this.re,-this.im)},ceil:function(a){a=Math.pow(10,a||0);return new d(Math.ceil(this.re*a)/a,Math.ceil(this.im*a)/a)},floor:function(a){a=Math.pow(10,a||0);return new d(Math.floor(this.re*a)/a,Math.floor(this.im*a)/a)},round:function(a){a=Math.pow(10,a||0);return new d(Math.round(this.re*a)/a,Math.round(this.im*a)/a)},equals:function(a,b){var c=new d(a,b);return Math.abs(c.re-this.re)<=d.EPSILON&&Math.abs(c.im-this.im)<=d.EPSILON},clone:function(){return new d(this.re,
this.im)},toString:function(){var a=this.re,b=this.im,c="";if(this.isNaN())return"NaN";if(this.b())return"0";if(this.a())return"Infinity";0!==a&&(c+=a);0!==b&&(0!==a?c+=0>b?" - ":" + ":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},isNaN:function(){return isNaN(this.re)||isNaN(this.im)},isZero:function(){return(0===this.re||-0===this.re)&&(0===this.im||-0===this.im)},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-16;"function"===typeof define&&define.amd?define([],function(){return d}):"object"===typeof exports?(Object.defineProperty(exports,"__esModule",{value:!0}),d["default"]=d,d.Complex=d,module.exports=d):n.Complex=d})(this);
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-16;"function"===typeof define&&define.amd?define([],function(){return d}):"object"===typeof exports?(Object.defineProperty(exports,"__esModule",{value:!0}),d["default"]=d,d.Complex=d,module.exports=d):n.Complex=d})(this);

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

"title": "complex.js",
"version": "2.0.7",
"version": "2.0.9",
"description": "A complex number library",

@@ -38,3 +38,6 @@ "keywords": [

"mocha": "*"
},
"dependencies": {
"npm": "^6.0.0"
}
}

@@ -226,2 +226,7 @@ var assert = require("assert");

}, {
set: "0",
fn: "pow",
param: "1+i",
expect: "0"
}, {
set: "i",

@@ -228,0 +233,0 @@ fn: "pow",

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