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 1.8.5 to 1.9.0

2

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

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

/**
* @license Complex.js v1.8.5 13/07/2015
* @license Complex.js v1.9.0 13/07/2015
*

@@ -419,7 +419,3 @@ * Copyright (c) 2015, Robert Eisele (robert@xarg.org)

if (b >= 0) {
return new Complex(re, im);
} else {
return new Complex(re, -im);
}
return new Complex(re, b >= 0 ? im : -im);
},

@@ -1121,8 +1117,11 @@

if (b > 0 && a !== 0)
ret+= "+";
if (a !== 0) {
ret+= b < 0 ? " - " : " + ";
} else if (b < 0) {
ret+= "-";
}
if (b === -1) {
ret+= "-";
} else if (b !== 1) {
b = Math.abs(b);
if (1 !== b) {
ret+= b;

@@ -1129,0 +1128,0 @@ }

/*
Complex.js v1.8.5 13/07/2015
Complex.js v1.9.0 13/07/2015

@@ -11,13 +11,13 @@ Copyright (c) 2015, Robert Eisele (robert@xarg.org)

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)<Math.abs(h))return f=c/h,c=c*f+h,new d((a*f+b)/c,(b*f-a)/c);f=h/c;c=h*f+c;return new d((a+b*f)/c,(b-a*f)/c)},pow:function(a,b){l(a,b);a=this.re;b=this.im;if(0===a&&0===b)return new d(0,0);var c=Math.atan2(b,a),h=n(a,b);if(0===e.im){if(0===b&&0<=a)return new d(Math.pow(a,e.re),0);if(0===a)switch(e.re%4){case 0:return new d(Math.pow(b,
e.re),0);case 1:return new d(0,Math.pow(b,e.re));case 2:return new d(-Math.pow(b,e.re),0);case 3:return new d(0,-Math.pow(b,e.re))}}a=Math.exp(e.re*h-e.im*c);b=e.im*h+e.re*c;return new d(a*Math.cos(b),a*Math.sin(b))},sqrt:function(){var a=this.re,b=this.im,c=this.abs(),e;e=0<=a?.5*Math.sqrt(2*(c+a)):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 0<=b?new d(e,a):new d(e,-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(1E3>a&&1E3>b)return Math.sqrt(a*a+b*b);a<b?(a=b,b=this.re/this.im):b=this.im/this.re;return a*Math.sqrt(1+b*b)},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){var a=this.re,b=this.im;return new d(Math.sin(a)*Math.cosh(b),Math.cos(a)*Math.sinh(b))},cos:function(){var a=this.re,b=this.im;return new d(Math.cos(a)*Math.cosh(b),
-Math.sin(a)*Math.sinh(b))},tan:function(){var a=this.re,b=this.im,c=Math.exp(-4*b)+2*Math.exp(-2*b)*Math.cos(2*a)+1;return new d(2*Math.exp(-2*b)*Math.sin(2*a)/c,(1-Math.exp(-4*b))/c)},cot:function(){var a=this.re,b=this.im,c=Math.exp(-4*b)-2*Math.exp(-2*b)*Math.cos(2*a)+1;return new d(2*Math.exp(-2*b)*Math.sin(2*a)/c,(Math.exp(-4*b)-1)/c)},sec:function(){var a=this.re,b=this.im,c=.25*(Math.exp(-2*b)+Math.exp(2*b))+.5*Math.cos(2*a);return new d(Math.cos(a)*Math.cosh(b)/c,Math.sin(a)*Math.sinh(b)/
c)},csc:function(){var a=this.re,b=this.im,c=.25*(Math.exp(-2*b)+Math.exp(2*b))-.5*Math.cos(2*a);return new d(Math.sin(a)*Math.cosh(b)/c,-Math.cos(a)*Math.sinh(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.b-b,c.a+a)).log();return new d(a.a,-a.b)},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)},atan2:function(a,b){l(a,b);return(new d(this.re/e.re,this.im/e.im)).atan()},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(Math.sinh(a)*Math.cos(b),Math.cosh(a)*Math.sin(b))},cosh:function(){var a=this.re,b=this.im;return new d(Math.cosh(a)*Math.cos(b),Math.sinh(a)*Math.sin(b))},tanh:function(){var a=this.im,b=Math.exp(2*this.re),
c=b*Math.cos(2*a),a=b*Math.sin(2*a),b=(c+1)*(c+1)+a*a;return new d(((c-1)*(c+1)+a*a)/b,2*a/b)},coth:function(){var a=this.im,b=Math.exp(2*this.re),c=b*Math.cos(2*a),a=b*Math.sin(2*a),b=(c-1)*(c-1)+a*a;return new d(((c+1)*(c-1)+a*a)/b,-2*a/b)},csch:function(){var a=this.re,b=this.im,c=Math.exp(a),e=Math.exp(-a),a=Math.cos(b)*(c-e),b=Math.sin(b)*(c+e),c=a*a+b*b;return new d(2*a/c,-2*b/c)},sech:function(){var a=this.re,b=this.im,c=Math.exp(a),e=Math.exp(-a),a=Math.cos(b)*(c+e),b=Math.sin(b)*(c-e),c=
a*a+b*b;return new d(2*a/c,-2*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,b=this.acos();0>=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=1<a&&0===b,e=1-a,f=1+a,g=e*e+b*b,a=0!==g?new d((f*e-b*b)/g,(b*e+f*b)/g):new d(-1!==a?a/0:0,0!==b?b/0:0),b=a.re;a.re=n(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(0===a&&0===b)return new d(Infinity,0);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(){var a=this.re,b=this.im,c=a*a+b*b;return new d(0!==a?a/c:0,0!==b?-b/c:0)},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){l(a,b);return Math.abs(e.re-this.re)<=d.EPSILON&&Math.abs(e.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(isNaN(a)||isNaN(b))return"NaN";0!==a&&(c+=a);0!==b&&(0<b&&0!==a&&(c+="+"),-1===b?c+="-":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);
e.re),0);case 1:return new d(0,Math.pow(b,e.re));case 2:return new d(-Math.pow(b,e.re),0);case 3:return new d(0,-Math.pow(b,e.re))}}a=Math.exp(e.re*h-e.im*c);b=e.im*h+e.re*c;return new d(a*Math.cos(b),a*Math.sin(b))},sqrt:function(){var a=this.re,b=this.im,c=this.abs(),e;e=0<=a?.5*Math.sqrt(2*(c+a)):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))},
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(1E3>a&&1E3>b)return Math.sqrt(a*a+b*b);a<b?(a=b,b=this.re/this.im):b=this.im/this.re;return a*Math.sqrt(1+b*b)},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){var a=this.re,b=this.im;return new d(Math.sin(a)*Math.cosh(b),Math.cos(a)*Math.sinh(b))},cos:function(){var a=this.re,b=this.im;return new d(Math.cos(a)*Math.cosh(b),-Math.sin(a)*Math.sinh(b))},
tan:function(){var a=this.re,b=this.im,c=Math.exp(-4*b)+2*Math.exp(-2*b)*Math.cos(2*a)+1;return new d(2*Math.exp(-2*b)*Math.sin(2*a)/c,(1-Math.exp(-4*b))/c)},cot:function(){var a=this.re,b=this.im,c=Math.exp(-4*b)-2*Math.exp(-2*b)*Math.cos(2*a)+1;return new d(2*Math.exp(-2*b)*Math.sin(2*a)/c,(Math.exp(-4*b)-1)/c)},sec:function(){var a=this.re,b=this.im,c=.25*(Math.exp(-2*b)+Math.exp(2*b))+.5*Math.cos(2*a);return new d(Math.cos(a)*Math.cosh(b)/c,Math.sin(a)*Math.sinh(b)/c)},csc:function(){var a=this.re,
b=this.im,c=.25*(Math.exp(-2*b)+Math.exp(2*b))-.5*Math.cos(2*a);return new d(Math.sin(a)*Math.cosh(b)/c,-Math.cos(a)*Math.sinh(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.b-b,c.a+a)).log();return new d(a.a,-a.b)},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)},atan2:function(a,b){l(a,b);return(new d(this.re/e.re,this.im/e.im)).atan()},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(Math.sinh(a)*Math.cos(b),Math.cosh(a)*Math.sin(b))},cosh:function(){var a=this.re,b=this.im;return new d(Math.cosh(a)*Math.cos(b),Math.sinh(a)*Math.sin(b))},tanh:function(){var a=this.im,b=Math.exp(2*this.re),c=b*Math.cos(2*a),a=b*Math.sin(2*
a),b=(c+1)*(c+1)+a*a;return new d(((c-1)*(c+1)+a*a)/b,2*a/b)},coth:function(){var a=this.im,b=Math.exp(2*this.re),c=b*Math.cos(2*a),a=b*Math.sin(2*a),b=(c-1)*(c-1)+a*a;return new d(((c+1)*(c-1)+a*a)/b,-2*a/b)},csch:function(){var a=this.re,b=this.im,c=Math.exp(a),e=Math.exp(-a),a=Math.cos(b)*(c-e),b=Math.sin(b)*(c+e),c=a*a+b*b;return new d(2*a/c,-2*b/c)},sech:function(){var a=this.re,b=this.im,c=Math.exp(a),e=Math.exp(-a),a=Math.cos(b)*(c+e),b=Math.sin(b)*(c-e),c=a*a+b*b;return new d(2*a/c,-2*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,b=this.acos();0>=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=1<a&&0===b,e=1-a,f=1+a,g=e*e+b*b,a=0!==g?new d((f*e-b*b)/g,(b*e+f*b)/g):new d(-1!==a?a/0:0,0!==b?b/0:0),b=a.re;a.re=n(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(0===a&&0===b)return new d(Infinity,0);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(){var a=this.re,b=this.im,c=a*a+b*b;return new d(0!==a?a/c:0,0!==b?-b/c:0)},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){l(a,b);return Math.abs(e.re-this.re)<=d.EPSILON&&Math.abs(e.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(isNaN(a)||isNaN(b))return"NaN";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}};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);

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

"title": "complex.js",
"version": "1.8.5",
"version": "1.9.0",
"description": "A complex number library",

@@ -9,0 +9,0 @@ "keywords": ["math", "complex", "number", "calculus", "parser"],

@@ -176,9 +176,9 @@ # Complex.js - ℂ in JavaSript

---
Returns a string representation of the actual number
Returns a string representation of the actual number. As of v1.9.0 the output is a bit more human readable
```javascript
new Complex(1, 2).toString(); // 1+2i
new Complex(1, 2).toString(); // 1 + 2i
new Complex(0, 1).toString(); // i
new Complex(9, 0).toString(); // 9
new Complex(1, 1).toString(); // 1+i
new Complex(1, 1).toString(); // 1 + i
```

@@ -185,0 +185,0 @@

@@ -18,3 +18,3 @@ var assert = require("assert");

}, {
set: "+i",
set: " + i",
expect: "i"

@@ -39,6 +39,6 @@ }, {

}, {
set: "4+3i",
set: "4 + 3i",
fn: "add",
param: "-3-2i",
expect: "1+i"
param: "-3 - 2i",
expect: "1 + i"
}, {

@@ -69,27 +69,27 @@ set: "3i",

fn: "sqrt",
expect: "4.242640687119285+4.242640687119285i"
expect: "4.242640687119285 + 4.242640687119285i"
}, {
set: "-36i",
fn: "sqrt",
expect: "4.242640687119285-4.242640687119285i"
expect: "4.242640687119285 - 4.242640687119285i"
}, {
set: "4+2i",
set: "4 + 2i",
fn: "div",
param: "0",
expect: "Infinity+Infinityi"
expect: "Infinity + Infinityi"
}, {
set: "4+2i",
set: "4 + 2i",
fn: "div",
param: "1+i",
expect: "3-i"
param: "1 + i",
expect: "3 - i"
}, {
set: "25",
fn: "div",
param: "3-4i",
expect: "3+4i"
param: "3 - 4i",
expect: "3 + 4i"
}, {
set: "3-2i",
set: "3 - 2i",
fn: "div",
param: "i",
expect: "-2-3i"
expect: "-2 - 3i"
}, {

@@ -101,32 +101,32 @@ set: "4i",

}, {
set: "3-6i",
set: "3 - 6i",
fn: "mul",
param: "i",
expect: "6+3i"
expect: "6 + 3i"
}, {
set: "3+4i",
set: "3 + 4i",
fn: "add",
param: "5-7i",
expect: "8-3i"
param: "5 - 7i",
expect: "8 - 3i"
}, {
set: "6i",
fn: "div",
param: "3-12i",
expect: "-0.47058823529411764+0.11764705882352941i"
param: "3 - 12i",
expect: "-0.47058823529411764 + 0.11764705882352941i"
}, {
set: "36+36i",
set: "36 + 36i",
fn: "sqrt",
expect: "6.59210468080686+2.730539163373364i"
expect: "6.59210468080686 + 2.730539163373364i"
}, {
set: "36-36i",
set: "36 - 36i",
fn: "sqrt",
expect: "6.59210468080686-2.730539163373364i"
expect: "6.59210468080686 - 2.730539163373364i"
}, {
set: "-36+36i",
set: "-36 + 36i",
fn: "sqrt",
expect: "2.730539163373364+6.59210468080686i"
expect: "2.730539163373364 + 6.59210468080686i"
}, {
set: "-36-36i",
set: "-36 - 36i",
fn: "sqrt",
expect: "2.730539163373364-6.59210468080686i"
expect: "2.730539163373364 - 6.59210468080686i"
}, {

@@ -149,9 +149,9 @@ set: "0",

}, {
set: "3+2i",
set: "3 + 2i",
fn: "log",
expect: Math.log(13) / 2 + "+" + Math.atan2(2, 3) + "i"
expect: Math.log(13) / 2 + " + " + Math.atan2(2, 3) + "i"
}, {
set: "3-2i",
set: "3 - 2i",
fn: "log",
expect: Math.log(13) / 2 + "-" + Math.atan2(2, 3) + "i"
expect: Math.log(13) / 2 + " - " + Math.atan2(2, 3) + "i"
}, {

@@ -164,11 +164,11 @@ set: 1,

fn: "exp",
expect: Math.cos(1) + "+" + Math.sin(1) + "i"
expect: Math.cos(1) + " + " + Math.sin(1) + "i"
}, {
set: "3+2i",
set: "3 + 2i",
fn: "exp",
expect: "-8.358532650935372+18.263727040666765i"
expect: "-8.358532650935372 + 18.263727040666765i"
}, {
set: "3-2i",
set: "3 - 2i",
fn: "exp",
expect: "-8.358532650935372-18.263727040666765i"
expect: "-8.358532650935372 - 18.263727040666765i"
}, {

@@ -228,3 +228,3 @@ set: "3",

param: "3i",
expect: "-0.008876640735623675-0.0013801328997494896i"
expect: "-0.008876640735623675 - 0.0013801328997494896i"
}, {

@@ -239,15 +239,15 @@ set: {re: 3, im: 4},

}, {
set: "1+4i",
set: "1 + 4i",
fn: "mul",
param: "3+2i",
expect: "-5+14i"
param: "3 + 2i",
expect: "-5 + 14i"
}, {
set: "4+16i",
set: "4 + 16i",
fn: "div",
param: "4.0000",
expect: "1+4i"
expect: "1 + 4i"
}, {
set: {re: -7.1, im: 2.5},
fn: "neg",
expect: "7.1-2.5i"
expect: "7.1 - 2.5i"
}, {

@@ -272,28 +272,28 @@ set: {re: 1, im: 1},

fn: "conjugate",
expect: "99-50i"
expect: "99 - 50i"
}, {
set: "2+8i",
set: "2 + 8i",
fn: "div",
param: new Complex(1, 2),
expect: "3.6+0.8i"
expect: "3.6 + 0.8i"
}, {
set: {re: 1, im: 2},
fn: "add",
param: "4+6i",
expect: "5+8i"
param: "4 + 6i",
expect: "5 + 8i"
}, {
set: {re: 5, im: 8},
fn: "sub",
param: "4+6i",
expect: "1+2i"
param: "4 + 6i",
expect: "1 + 2i"
}, {
set: "1+2i",
set: "1 + 2i",
fn: "pow",
param: "2",
expect: "-2.999999999999999+4.000000000000001i"
expect: "-2.999999999999999 + 4.000000000000001i"
}, {
set: "1+2i",
set: "1 + 2i",
fn: "pow",
param: "1+2i",
expect: "-0.22251715680177267+0.10070913113607541i"
param: "1 + 2i",
expect: "-0.22251715680177267 + 0.10070913113607541i"
}, {

@@ -303,3 +303,3 @@ set: {re: 1, im: 2},

param: new Complex(3, 4),
expect: "0.12900959407446697+0.033924092905170025i"
expect: "0.12900959407446697 + 0.033924092905170025i"
}, {

@@ -321,29 +321,33 @@ set: "i",

}, {
set: "1+4i",
set: "1 + 4i",
fn: "sqrt",
expect: "1.600485180440241+1.2496210676876531i"
expect: "1.600485180440241 + 1.2496210676876531i"
}, {
set: {re: -3, im: 4},
fn: "sqrt",
expect: "1+2i"
expect: "1 + 2i"
}, {
set: {re: 3, im: -4},
fn: "sqrt",
expect: "2-i"
expect: "2 - i"
}, {
set: {re: -3, im: -4},
fn: "sqrt",
expect: "1-2i"
expect: "1 - 2i"
}, {
set: "4+3i",
set: -Complex.E.pow(2),
fn: "log",
expect: "1.6094379124341003+0.6435011087932844i"
expect: "2 + 3.141592653589793i"
}, {
set: "4+3i",
set: "4 + 3i",
fn: "log",
expect: "1.6094379124341003 + 0.6435011087932844i"
}, {
set: "4 + 3i",
fn: "exp",
expect: "-54.05175886107815+7.7048913727311525i"
expect: "-54.05175886107815 + 7.7048913727311525i"
}, {
set: {re: 1, im: 2},
fn: "sin",
expect: "3.1657785132161678+1.9596010414216063i"
expect: "3.1657785132161678 + 1.9596010414216063i"
}, {

@@ -356,35 +360,35 @@ set: "i",

fn: "acos",
expect: "1.5707963267948966-0.8813735870195428i"
expect: "1.5707963267948966 - 0.8813735870195428i"
}, {
set: {re: 1, im: 2},
fn: "cos",
expect: "2.0327230070196656-3.0518977991518i"
expect: "2.0327230070196656 - 3.0518977991518i"
}, {
set: {re: 1, im: 2},
fn: "tan",
expect: "0.03381282607989669+1.0147936161466335i"
expect: "0.03381282607989669 + 1.0147936161466335i"
}, {
set: {re: 1, im: 3},
fn: "sinh",
expect: "-1.1634403637032504+0.21775955162215221i"
expect: "-1.1634403637032504 + 0.21775955162215221i"
}, {
set: {re: 1, im: 3},
fn: "cosh",
expect: "-1.5276382501165433+0.1658444019189788i"
expect: "-1.5276382501165433 + 0.1658444019189788i"
}, {
set: {re: 1, im: 3},
fn: "tanh",
expect: "0.7680176472869114-0.05916853956605075i"
expect: "0.7680176472869114 - 0.05916853956605075i"
}, {
set: {re: 1, im: 3},
fn: "inverse",
expect: "0.1-0.3i"
expect: "0.1 - 0.3i"
}, {
set: {re: 0.5, im: -0.5},
fn: "inverse",
expect: "1+i"
expect: "1 + i"
}, {
set: "1+i",
set: "1 + i",
fn: "inverse",
expect: "0.5-0.5i"
expect: "0.5 - 0.5i"
}, {

@@ -420,8 +424,8 @@ set: "0",

}, {
set: "2+3i",
set: "2 + 3i",
fn: "equals",
param: "2+3i",
param: "2 + 3i",
expect: "true"
}, {
set: "2+3i",
set: "2 + 3i",
fn: "equals",

@@ -431,37 +435,37 @@ param: "5i",

}, {
set: "2+3i",
set: "2 + 3i",
fn: "round",
param: "0",
expect: "2+3i"
expect: "2 + 3i"
}, {
set: "2.5+3.5i",
set: "2.5 + 3.5i",
fn: "round",
param: "1",
expect: "2.5+3.5i"
expect: "2.5 + 3.5i"
}, {
set: "2.5+3.5i",
set: "2.5 + 3.5i",
fn: "sign",
param: null,
expect: "0.5812381937190965+0.813733471206735i"
expect: "0.5812381937190965 + 0.813733471206735i"
}, {
set: "10+24i",
set: "10 + 24i",
fn: "sign",
param: null,
expect: "0.38461538461538464+0.9230769230769231i"
expect: "0.38461538461538464 + 0.9230769230769231i"
}, {
set: "1e3i",
fn: "add",
param: "3e-3+1e2i",
expect: "0.003+1100i"
param: "3e-3 + 1e2i",
expect: "0.003 + 1100i"
}, {
set: "+7 -i + 3i -++++43 + 2i - i4 +- 33 + 65-1 ",
set: " + 7 - i + 3i - + + + + 43 + 2i - i4 + - 33 + 65 - 1 ",
expect: "-5"
}, {
set: "+7 -i + 3i -++++43 + 2i - i4 +- 33 + 65-1 +",
set: " + 7 - i + 3i - + + + + 43 + 2i - i4 + - 33 + 65 - 1 + ",
expect: "Invalid Param"
}, {
set: "-3x+4",
set: "-3x + 4",
expect: "Invalid Param"
}, {
set: "-+7",
set: "- + 7",
expect: "-7"

@@ -511,9 +515,10 @@ }, {

it("should work with different params", function() {
assert.equal(Complex(1, -1).toString(), "1-i");
assert.equal(Complex(1, -1).toString(), "1 - i");
assert.equal(Complex(0, 0).toString(), "0");
assert.equal(Complex(0, 2).toString(), "2i");
assert.equal(Complex("3+4i").toString(), "3+4i");
assert.equal(Complex("1+i").toString(), "1+i");
assert.equal(Complex("3 + 4i").toString(), "3 + 4i");
assert.equal(Complex("1 + i").toString(), "1 + i");
assert.equal(Complex("i").toString(), "i");
assert.equal(Complex("3-4i").toString(), "3-4i");
assert.equal(Complex.I.toString(), "i");
assert.equal(Complex("3 - 4i").toString(), "3 - 4i");
assert.equal(Complex("5").toString(), "5");

@@ -529,3 +534,3 @@ assert.equal(Complex(0, -2).toString(), "-2i");

assert.equal(zero.toString(), "0");
assert.equal(one.toString(), "1+i");
assert.equal(one.toString(), "1 + i");
assert(one.neg().equals(Complex(-1, -1)));

@@ -539,19 +544,19 @@ assert(one.conjugate().equals(Complex(1, -1)));

assert.equal(one.mul(one).toString(), Complex(0, 2).toString());
assert.equal(one.div(2).toString(), "0.5+0.5i");
assert.equal(one.div(2).toString(), "0.5 + 0.5i");
assert.equal(one.div(one).toString(), "1");
assert.equal(one.div(0).toString(), "Infinity+Infinityi");
assert.equal(one.exp().toString(), "1.4686939399158851+2.2873552871788423i");
assert.equal(one.log().toString(), "0.34657359027997264+0.7853981633974483i");
assert.equal(one.pow(one).toString(), "0.27395725383012104+0.5837007587586146i");
assert.equal(one.div(0).toString(), "Infinity + Infinityi");
assert.equal(one.exp().toString(), "1.4686939399158851 + 2.2873552871788423i");
assert.equal(one.log().toString(), "0.34657359027997264 + 0.7853981633974483i");
assert.equal(one.pow(one).toString(), "0.27395725383012104 + 0.5837007587586146i");
assert.equal(one.pow(zero).toString(), "1");
assert.equal(one.sqrt().toString(), "1.09868411346781+0.45508986056222733i");
assert.equal(one.sin().toString(), "1.2984575814159773+0.6349639147847361i");
assert.equal(one.cos().toString(), "0.8337300251311491-0.9888977057628651i");
assert.equal(one.tan().toString(), "0.27175258531951174+1.0839233273386946i");
assert.equal(one.asin().toString(), "0.6662394324925153+1.0612750619050355i");
assert.equal(one.acos().toString(), "0.9045568943023813-1.0612750619050355i");
assert.equal(one.atan().toString(), "1.0172219678978514+0.40235947810852507i");
assert.equal(one.sqrt().toString(), "1.09868411346781 + 0.45508986056222733i");
assert.equal(one.sin().toString(), "1.2984575814159773 + 0.6349639147847361i");
assert.equal(one.cos().toString(), "0.8337300251311491 - 0.9888977057628651i");
assert.equal(one.tan().toString(), "0.27175258531951174 + 1.0839233273386946i");
assert.equal(one.asin().toString(), "0.6662394324925153 + 1.0612750619050355i");
assert.equal(one.acos().toString(), "0.9045568943023813 - 1.0612750619050355i");
assert.equal(one.atan().toString(), "1.0172219678978514 + 0.40235947810852507i");
assert.equal(Complex("5i+3").log().exp().toString(), "3+5i")
assert.equal(Complex("-2i-1").log().exp().toString(), "-1-2i")
assert.equal(Complex("5i + 3").log().exp().toString(), "3 + 5i")
assert.equal(Complex("-2i - 1").log().exp().toString(), "-1 - 2i")
});

@@ -581,2 +586,11 @@

});
it("should eat it's own dog food", function() {
var a = Complex(1, -5).toString();
var b = Complex(a).toString();
var c = Complex(b).mul(a);
assert.equal(c.toString(), '-24 - 10i');
});
});
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