complex.js
Advanced tools
Comparing version 1.9.1 to 1.9.2
{ | ||
"name": "complex.js", | ||
"main": "complex.js", | ||
"version": "1.9.1", | ||
"version": "1.9.2", | ||
"homepage": "https://github.com/infusion/Complex.js", | ||
@@ -6,0 +6,0 @@ "description": "A complex number library", |
/** | ||
* @license Complex.js v1.9.1 13/07/2015 | ||
* @license Complex.js v1.9.2 13/07/2015 | ||
* | ||
@@ -47,4 +47,4 @@ * Copyright (c) 2015, Robert Eisele (robert@xarg.org) | ||
var parser_exit = function(a,b) { | ||
throw "Invalid Param" ; | ||
var parser_exit = function() { | ||
throw "Invalid Param"; | ||
}; | ||
@@ -133,3 +133,3 @@ | ||
} else { | ||
parser_exit(a,b); | ||
parser_exit(); | ||
} | ||
@@ -146,2 +146,6 @@ break; | ||
var minus = 0; | ||
if (match === null) { | ||
parser_exit(); | ||
} | ||
@@ -161,3 +165,3 @@ for (var i = 0; i < match.length; i++) { | ||
if (plus + minus === 0) { | ||
parser_exit(a,b); | ||
parser_exit(); | ||
} | ||
@@ -175,3 +179,3 @@ | ||
if (plus + minus === 0) { | ||
parser_exit(a,b); | ||
parser_exit(); | ||
} | ||
@@ -187,3 +191,3 @@ | ||
} else { | ||
parser_exit(a,b); | ||
parser_exit(); | ||
} | ||
@@ -194,3 +198,3 @@ } | ||
if (plus + minus > 0) { | ||
parser_exit(a,b); | ||
parser_exit(); | ||
} | ||
@@ -205,7 +209,8 @@ break; | ||
default: | ||
parser_exit(a,b); | ||
parser_exit(); | ||
} | ||
if (isNaN(P["re"]) || isNaN(P["im"])) { | ||
parser_exit(a,b); | ||
// If a calculation is NaN, we treat it as NaN and don't throw | ||
//parser_exit(); | ||
} | ||
@@ -212,0 +217,0 @@ }; |
/* | ||
Complex.js v1.9.1 13/07/2015 | ||
Complex.js v1.9.2 13/07/2015 | ||
@@ -7,8 +7,8 @@ Copyright (c) 2015, Robert Eisele (robert@xarg.org) | ||
*/ | ||
(function(p){"use strict";function l(a,b){if(null===a||void 0===a)e.re=0,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;for(var c=a.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|./g),d=1,f=0,g=0;g<c.length;g++){var k=c[g];" "!==k&&"\t"!==k&&"\n"!==k&&("+"===k?d++:"-"=== | ||
k?f++:isNaN(k)?"i"===k?(0===d+f&&m()," "===c[g+1]||isNaN(c[g+1])?e.im+=parseFloat((f%2?"-":"+")+"1"):(e.im+=parseFloat((f%2?"-":"+")+c[g+1]),g++),d=f=0):m():(0===d+f&&m(),"i"===c[g+1]?(e.im+=parseFloat((f%2?"-":"+")+k),g++):e.re+=parseFloat((f%2?"-":"+")+k),d=f=0))}0<d+f&&m();break;case "number":e.im=0;e.re=a;break;default:m()}(isNaN(e.re)||isNaN(e.im))&&m()}function m(){throw"Invalid Param";}function n(a,b){var c=Math.abs(a),d=Math.abs(b);return 0===a?Math.log(d):0===b?Math.log(c):1E3>c&&1E3>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)<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 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)* | ||
(function(p){"use strict";function l(a,b){if(null===a||void 0===a)e.re=0,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*|./g),d=1,f=0;null===c&&m();for(var g=0;g<c.length;g++){var k=c[g];" "!==k&&"\t"!==k&&"\n"!==k&&("+"=== | ||
k?d++:"-"===k?f++:isNaN(k)?"i"===k?(0===d+f&&m()," "===c[g+1]||isNaN(c[g+1])?e.im+=parseFloat((f%2?"-":"+")+"1"):(e.im+=parseFloat((f%2?"-":"+")+c[g+1]),g++),d=f=0):m():(0===d+f&&m(),"i"===c[g+1]?(e.im+=parseFloat((f%2?"-":"+")+k),g++):e.re+=parseFloat((f%2?"-":"+")+k),d=f=0))}0<d+f&&m();break;case "number":e.im=0;e.re=a;break;default:m()}}function m(){throw"Invalid Param";}function n(a,b){var c=Math.abs(a),d=Math.abs(b);return 0===a?Math.log(d):0===b?Math.log(c):1E3>c&&1E3>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)<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 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= | ||
@@ -15,0 +15,0 @@ .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.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- |
@@ -6,3 +6,3 @@ { | ||
"title": "complex.js", | ||
"version": "1.9.1", | ||
"version": "1.9.2", | ||
"description": "A complex number library", | ||
@@ -9,0 +9,0 @@ "keywords": ["math", "complex", "number", "calculus", "parser"], |
@@ -7,3 +7,3 @@ # Complex.js - ℂ in JavaSript | ||
Complex.js is a JavaScript library to work with complex number arithmetic in JavaScript. It implements every elementary complex number manipulation function and the API is intentionally similar to [Fraction.js](https://github.com/infusion/Fraction.js). Furthermore, it's the basis of [Polynomial.js](https://github.com/infusion/Polynomial.js). | ||
Complex.js is a well tested JavaScript library to work with complex number arithmetic in JavaScript. It implements every elementary complex number manipulation function and the API is intentionally similar to [Fraction.js](https://github.com/infusion/Fraction.js). Furthermore, it's the basis of [Polynomial.js](https://github.com/infusion/Polynomial.js). | ||
@@ -10,0 +10,0 @@ |
@@ -68,2 +68,7 @@ var assert = require("assert"); | ||
expect: "4.242640687119285 + 4.242640687119285i" | ||
},{ | ||
set: Infinity, | ||
fn: "mul", | ||
param: "i", | ||
expect: "NaN" | ||
}, { | ||
@@ -70,0 +75,0 @@ set: "-36i", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53917
1611