Intial Commit
This commit is contained in:
4
nodered/rootfs/data/node_modules/complex.js/.travis.yml
generated
vendored
Normal file
4
nodered/rootfs/data/node_modules/complex.js/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "stable"
|
||||
script: npm test
|
||||
250
nodered/rootfs/data/node_modules/complex.js/README.md
generated
vendored
Normal file
250
nodered/rootfs/data/node_modules/complex.js/README.md
generated
vendored
Normal file
@@ -0,0 +1,250 @@
|
||||
# Complex.js - ℂ in JavaSript
|
||||
|
||||
[](https://npmjs.org/package/complex.js "View this project on npm")
|
||||
[](https://travis-ci.org/infusion/Complex.js)
|
||||
[](http://opensource.org/licenses/MIT)
|
||||
|
||||
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) and [Math.js](https://github.com/josdejong/mathjs).
|
||||
|
||||
|
||||
Example
|
||||
===
|
||||
|
||||
```js
|
||||
var Complex = require('complex.js');
|
||||
|
||||
var c = new Complex("99.3+8i");
|
||||
c.mul({re: 3, im: 9}).div(4.9).sub(3, 2);
|
||||
```
|
||||
|
||||
Parser
|
||||
===
|
||||
|
||||
Any function (see below) as well as the constructor of the *Complex* class parses its input like this.
|
||||
|
||||
You can pass either Objects, Doubles or Strings.
|
||||
|
||||
Objects
|
||||
---
|
||||
```javascript
|
||||
new Complex({re: real, im: imaginary});
|
||||
new Complex({arg: angle, abs: radius});
|
||||
new Complex({phi: angle, r: radius});
|
||||
```
|
||||
|
||||
Doubles
|
||||
---
|
||||
```javascript
|
||||
new Complex(55.4);
|
||||
```
|
||||
|
||||
Strings
|
||||
---
|
||||
```javascript
|
||||
new Complex("123.45");
|
||||
new Complex("15+3i");
|
||||
new Complex("i");
|
||||
```
|
||||
|
||||
Two arguments
|
||||
---
|
||||
```javascript
|
||||
new Complex(3, 2); // 3+2i
|
||||
```
|
||||
|
||||
Functions
|
||||
===
|
||||
|
||||
Complex sign()
|
||||
---
|
||||
Returns the complex sign, defined as the complex number normalized by it's absolute value
|
||||
|
||||
Complex add(n)
|
||||
---
|
||||
Adds another complex number
|
||||
|
||||
Complex sub(n)
|
||||
---
|
||||
Subtracts another complex number
|
||||
|
||||
Complex mul(n)
|
||||
---
|
||||
Multiplies the number with another complex number
|
||||
|
||||
Complex div(n)
|
||||
---
|
||||
Divides the number by another complex number
|
||||
|
||||
Complex pow(exp)
|
||||
---
|
||||
Returns the number raised to the complex exponent
|
||||
|
||||
Complex sqrt()
|
||||
---
|
||||
Returns the complex square root of the number
|
||||
|
||||
Complex exp(n)
|
||||
---
|
||||
Returns `e^n` with complex exponent `n`.
|
||||
|
||||
Complex log()
|
||||
---
|
||||
Returns the natural logarithm (base `E`) of the actual complex number
|
||||
|
||||
double abs()
|
||||
---
|
||||
Calculates the magnitude of the complex number
|
||||
|
||||
double arg()
|
||||
---
|
||||
Calculates the angle of the complex number
|
||||
|
||||
Complex inverse()
|
||||
---
|
||||
Calculates the multiplicative inverse of the complex number (1 / z)
|
||||
|
||||
Complex conjugate()
|
||||
---
|
||||
Calculates the conjugate of the complex number (multiplies the imaginary part with -1)
|
||||
|
||||
Complex neg()
|
||||
---
|
||||
Negates the number (multiplies both the real and imaginary part with -1) in order to get the additive inverse
|
||||
|
||||
Complex floor([places=0])
|
||||
---
|
||||
Floors the complex number parts towards zero
|
||||
|
||||
Complex ceil([places=0])
|
||||
---
|
||||
Ceils the complex number parts off zero
|
||||
|
||||
Complex round([places=0])
|
||||
---
|
||||
Rounds the complex number parts
|
||||
|
||||
boolean equals(n)
|
||||
---
|
||||
Checks if both numbers are exactly the same
|
||||
|
||||
boolean isNaN()
|
||||
---
|
||||
Checks if the given number is not a number
|
||||
|
||||
Complex clone()
|
||||
---
|
||||
Returns a new Complex instance with the same real and imaginary properties
|
||||
|
||||
Array toVector()
|
||||
---
|
||||
Returns a Vector of the actual complex number with two components
|
||||
|
||||
String toString()
|
||||
---
|
||||
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(0, 1).toString(); // i
|
||||
new Complex(9, 0).toString(); // 9
|
||||
new Complex(1, 1).toString(); // 1 + i
|
||||
```
|
||||
|
||||
double valueOf()
|
||||
---
|
||||
Returns the real part of the number if imaginary part is zero. Otherwise `null`
|
||||
|
||||
|
||||
Trigonometric functions
|
||||
===
|
||||
The following trigonometric functions are defined on Complex.js:
|
||||
|
||||
| Trig | Arcus | Hyperbolic | Arcus-Hyperbolic |
|
||||
|------|-------|------------|------------------|
|
||||
| sin() | asin() | sinh() | asinh() |
|
||||
| cos() | acos() | cosh() | acosh() |
|
||||
| tan() | atan() | tanh() | atanh() |
|
||||
| cot() | acot() | coth() | acoth() |
|
||||
| sec() | asec() | sech() | asech() |
|
||||
| csc() | acsc() | csch() | acsch() |
|
||||
|
||||
|
||||
|
||||
Constants
|
||||
===
|
||||
|
||||
Complex.ZERO
|
||||
---
|
||||
A complex zero instance
|
||||
|
||||
Complex.ONE
|
||||
---
|
||||
A complex one instance
|
||||
|
||||
Complex.I
|
||||
---
|
||||
An imaginary number i instance
|
||||
|
||||
Complex.PI
|
||||
---
|
||||
A complex PI instance
|
||||
|
||||
Complex.E
|
||||
---
|
||||
A complex euler number instance
|
||||
|
||||
Complex.EPSILON
|
||||
---
|
||||
A small epsilon value used for `equal()` comparison in order to circumvent double inprecision.
|
||||
|
||||
|
||||
Installation
|
||||
===
|
||||
Installing complex.js is as easy as cloning this repo or use one of the following commands:
|
||||
|
||||
```
|
||||
bower install complex.js
|
||||
```
|
||||
or
|
||||
|
||||
```
|
||||
npm install complex.js
|
||||
```
|
||||
|
||||
Using Complex.js with the browser
|
||||
===
|
||||
<script src="complex.js"></script>
|
||||
<script>
|
||||
console.log(Complex("4+3i"));
|
||||
</script>
|
||||
|
||||
|
||||
Using Complex.js with require.js
|
||||
===
|
||||
<script src="require.js"></script>
|
||||
<script>
|
||||
requirejs(['complex.js'],
|
||||
function(Complex) {
|
||||
console.log(Complex("4+3i"));
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Coding Style
|
||||
===
|
||||
As every library I publish, complex.js is also built to be as small as possible after compressing it with Google Closure Compiler in advanced mode. Thus the coding style orientates a little on maxing-out the compression rate. Please make sure you keep this style if you plan to extend the library.
|
||||
|
||||
|
||||
Testing
|
||||
===
|
||||
If you plan to enhance the library, make sure you add test cases and all the previous tests are passing. You can test the library with
|
||||
|
||||
```
|
||||
npm test
|
||||
```
|
||||
|
||||
|
||||
Copyright and licensing
|
||||
===
|
||||
Copyright (c) 2015, Robert Eisele (robert@xarg.org)
|
||||
Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
26
nodered/rootfs/data/node_modules/complex.js/bower.json
generated
vendored
Normal file
26
nodered/rootfs/data/node_modules/complex.js/bower.json
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "complex.js",
|
||||
"main": "complex.js",
|
||||
"version": "2.0.1",
|
||||
"homepage": "https://github.com/infusion/Complex.js",
|
||||
"description": "A complex number library",
|
||||
"keywords": [
|
||||
"math", "complex", "number", "calculus", "parser"
|
||||
],
|
||||
"authors": [
|
||||
"Robert Eisele <robert@xarg.org> (http://www.xarg.org/)"
|
||||
],
|
||||
"license": [
|
||||
"MIT",
|
||||
"GPL"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/infusion/Complex.js.git"
|
||||
},
|
||||
"ignore": [
|
||||
"tests",
|
||||
".travis.yml",
|
||||
"package.json"
|
||||
]
|
||||
}
|
||||
1183
nodered/rootfs/data/node_modules/complex.js/complex.js
generated
vendored
Normal file
1183
nodered/rootfs/data/node_modules/complex.js/complex.js
generated
vendored
Normal file
@@ -0,0 +1,1183 @@
|
||||
/**
|
||||
* @license Complex.js v2.0.1 11/02/2016
|
||||
*
|
||||
* Copyright (c) 2016, Robert Eisele (robert@xarg.org)
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
**/
|
||||
|
||||
/**
|
||||
*
|
||||
* This class allows the manipilation of complex numbers.
|
||||
* You can pass a complex number in different formats. Either as object, double, string or two integer parameters.
|
||||
*
|
||||
* Object form
|
||||
* { re: <real>, im: <imaginary> }
|
||||
* { arg: <angle>, abs: <radius> }
|
||||
* { phi: <angle>, r: <radius> }
|
||||
*
|
||||
* Double form
|
||||
* 99.3 - Single double value
|
||||
*
|
||||
* String form
|
||||
* "23.1337" - Simple real number
|
||||
* "15+3i" - a simple complex number
|
||||
* "3-i" - a simple complex number
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* var c = new Complex("99.3+8i");
|
||||
* c.mul({r: 3, i: 9}).div(4.9).sub(3, 2);
|
||||
*
|
||||
*/
|
||||
|
||||
(function(root) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var P = {'re': 0, 'im': 0};
|
||||
|
||||
Math.cosh = Math.cosh || function(x) {
|
||||
return (Math.exp(x) + Math.exp(-x)) * 0.5;
|
||||
};
|
||||
|
||||
Math.sinh = Math.sinh || function(x) {
|
||||
return (Math.exp(x) - Math.exp(-x)) * 0.5;
|
||||
};
|
||||
|
||||
var parser_exit = function() {
|
||||
throw SyntaxError("Invalid Param");
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates log(sqrt(a^2+b^2)) in a way to avoid overflows
|
||||
*
|
||||
* @param {number} a
|
||||
* @param {number} b
|
||||
* @returns {number}
|
||||
*/
|
||||
function logHypot(a, b) {
|
||||
|
||||
var _a = Math.abs(a);
|
||||
var _b = Math.abs(b);
|
||||
|
||||
if (a === 0) {
|
||||
return Math.log(_b);
|
||||
}
|
||||
|
||||
if (b === 0) {
|
||||
return Math.log(_a);
|
||||
}
|
||||
|
||||
if (_a < 3000 && _b < 3000) {
|
||||
return Math.log(a * a + b * b) * 0.5;
|
||||
}
|
||||
|
||||
/* I got 4 ideas to compute this property without overflow:
|
||||
*
|
||||
* Testing 1000000 times with random samples for a,b ∈ [1, 1000000000] against a big decimal library to get an error estimate
|
||||
*
|
||||
* 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) {
|
||||
a = Math.abs(a);
|
||||
b = Math.abs(b);
|
||||
var t = Math.min(a, b);
|
||||
a = Math.max(a, b);
|
||||
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)))
|
||||
|
||||
*/
|
||||
|
||||
return Math.log(a / Math.cos(Math.atan2(b, a)));
|
||||
}
|
||||
|
||||
var parse = function(a, b) {
|
||||
|
||||
if (a === undefined || a === null) {
|
||||
P["re"] =
|
||||
P["im"] = 0;
|
||||
} else if (b !== undefined) {
|
||||
P["re"] = a;
|
||||
P["im"] = b;
|
||||
} else switch (typeof a) {
|
||||
|
||||
case "object":
|
||||
|
||||
if ("im" in a && "re" in a) {
|
||||
P["re"] = a["re"];
|
||||
P["im"] = a["im"];
|
||||
} else if ("abs" in a && "arg" in a) {
|
||||
P["re"] = a["abs"] * Math.cos(a["arg"]);
|
||||
P["im"] = a["abs"] * Math.sin(a["arg"]);
|
||||
} else if ("r" in a && "phi" in a) {
|
||||
P["re"] = a["r"] * Math.cos(a["phi"]);
|
||||
P["im"] = a["r"] * Math.sin(a["phi"]);
|
||||
} else {
|
||||
parser_exit();
|
||||
}
|
||||
break;
|
||||
|
||||
case "string":
|
||||
|
||||
P["im"] = /* void */
|
||||
P["re"] = 0;
|
||||
|
||||
var tokens = a.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g);
|
||||
var plus = 1;
|
||||
var minus = 0;
|
||||
|
||||
if (tokens === null) {
|
||||
parser_exit();
|
||||
}
|
||||
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
|
||||
var c = tokens[i];
|
||||
|
||||
if (c === ' ' || c === '\t' || c === '\n') {
|
||||
/* void */
|
||||
} else if (c === '+') {
|
||||
plus++;
|
||||
} else if (c === '-') {
|
||||
minus++;
|
||||
} else if (c === 'i' || c === 'I') {
|
||||
|
||||
if (plus + minus === 0) {
|
||||
parser_exit();
|
||||
}
|
||||
|
||||
if (tokens[i + 1] !== ' ' && !isNaN(tokens[i + 1])) {
|
||||
P["im"]+= parseFloat((minus % 2 ? "-" : "") + tokens[i + 1]);
|
||||
i++;
|
||||
} else {
|
||||
P["im"]+= parseFloat((minus % 2 ? "-" : "") + "1");
|
||||
}
|
||||
plus = minus = 0;
|
||||
|
||||
} else {
|
||||
|
||||
if (plus + minus === 0 || isNaN(c)) {
|
||||
parser_exit();
|
||||
}
|
||||
|
||||
if (tokens[i + 1] === 'i' || tokens[i + 1] === 'I') {
|
||||
P["im"]+= parseFloat((minus % 2 ? "-" : "") + c);
|
||||
i++;
|
||||
} else {
|
||||
P["re"]+= parseFloat((minus % 2 ? "-" : "") + c);
|
||||
}
|
||||
plus = minus = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Still something on the stack
|
||||
if (plus + minus > 0) {
|
||||
parser_exit();
|
||||
}
|
||||
break;
|
||||
|
||||
case "number":
|
||||
P["im"] = 0;
|
||||
P["re"] = a;
|
||||
break;
|
||||
|
||||
default:
|
||||
parser_exit();
|
||||
}
|
||||
|
||||
if (isNaN(P["re"]) || isNaN(P["im"])) {
|
||||
// If a calculation is NaN, we treat it as NaN and don't throw
|
||||
//parser_exit();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @returns {Complex}
|
||||
*/
|
||||
function Complex(a, b) {
|
||||
|
||||
if (!(this instanceof Complex)) {
|
||||
return new Complex(a, b);
|
||||
}
|
||||
|
||||
parse(a, b); // mutates P
|
||||
|
||||
this["re"] = P["re"];
|
||||
this["im"] = P["im"];
|
||||
}
|
||||
|
||||
Complex.prototype = {
|
||||
|
||||
"re": 0,
|
||||
"im": 0,
|
||||
|
||||
/**
|
||||
* Calculates the sign of a complex number
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"sign": function() {
|
||||
|
||||
var abs = this["abs"]();
|
||||
|
||||
return new Complex(
|
||||
this["re"] / abs,
|
||||
this["im"] / abs);
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds two complex numbers
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"add": function(a, b) {
|
||||
|
||||
parse(a, b); // mutates P
|
||||
|
||||
return new Complex(
|
||||
this["re"] + P["re"],
|
||||
this["im"] + P["im"]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Subtracts two complex numbers
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"sub": function(a, b) {
|
||||
|
||||
parse(a, b); // mutates P
|
||||
|
||||
return new Complex(
|
||||
this["re"] - P["re"],
|
||||
this["im"] - P["im"]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Multiplies two complex numbers
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"mul": function(a, b) {
|
||||
|
||||
parse(a, b); // mutates P
|
||||
|
||||
// Besides the addition/subtraction, this helps having a solution for rational Infinity
|
||||
if (P['im'] === 0 && this['im'] === 0) {
|
||||
return new Complex(this['re'] * P['re'], 0);
|
||||
}
|
||||
|
||||
return new Complex(
|
||||
this["re"] * P["re"] - this["im"] * P["im"],
|
||||
this["re"] * P["im"] + this["im"] * P["re"]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Divides two complex numbers
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"div": function(a, b) {
|
||||
|
||||
parse(a, b); // mutates P
|
||||
|
||||
a = this["re"];
|
||||
b = this["im"];
|
||||
|
||||
var c = P["re"];
|
||||
var d = P["im"];
|
||||
var t, x;
|
||||
|
||||
// Divisor is zero
|
||||
if (0 === c && 0 === d) {
|
||||
return new Complex(
|
||||
(a !== 0) ? (a / 0) : 0,
|
||||
(b !== 0) ? (b / 0) : 0);
|
||||
}
|
||||
|
||||
// Divisor is rational
|
||||
if (0 === d) {
|
||||
return new Complex(a / c, b / c);
|
||||
}
|
||||
|
||||
if (Math.abs(c) < Math.abs(d)) {
|
||||
|
||||
x = c / d;
|
||||
t = c * x + d;
|
||||
|
||||
return new Complex(
|
||||
(a * x + b) / t,
|
||||
(b * x - a) / t);
|
||||
|
||||
} else {
|
||||
|
||||
x = d / c;
|
||||
t = d * x + c;
|
||||
|
||||
return new Complex(
|
||||
(a + b * x) / t,
|
||||
(b - a * x) / t);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the power of two complex numbers
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"pow": function(a, b) {
|
||||
|
||||
parse(a, b); // mutates P
|
||||
|
||||
a = this["re"];
|
||||
b = this["im"];
|
||||
|
||||
if (a === 0 && b === 0) {
|
||||
return new Complex(0, 0);
|
||||
}
|
||||
|
||||
var arg = Math.atan2(b, a);
|
||||
var loh = logHypot(a, b);
|
||||
|
||||
if (P["im"] === 0) {
|
||||
|
||||
if (b === 0 && a >= 0) {
|
||||
|
||||
return new Complex(Math.pow(a, P["re"]), 0);
|
||||
|
||||
} else if (a === 0) {
|
||||
|
||||
switch (P["re"] % 4) {
|
||||
case 0:
|
||||
return new Complex(Math.pow(b, P["re"]), 0);
|
||||
case 1:
|
||||
return new Complex(0, Math.pow(b, P["re"]));
|
||||
case 2:
|
||||
return new Complex(-Math.pow(b, P["re"]), 0);
|
||||
case 3:
|
||||
return new Complex(0, -Math.pow(b, P["re"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* I couldn"t find a good formula, so here is a derivation and optimization
|
||||
*
|
||||
* z_1^z_2 = (a + bi)^(c + di)
|
||||
* = exp((c + di) * log(a + bi)
|
||||
* = pow(a^2 + b^2, (c + di) / 2) * exp(i(c + di)atan2(b, a))
|
||||
* =>...
|
||||
* Re = (pow(a^2 + b^2, c / 2) * exp(-d * atan2(b, a))) * cos(d * log(a^2 + b^2) / 2 + c * atan2(b, a))
|
||||
* Im = (pow(a^2 + b^2, c / 2) * exp(-d * atan2(b, a))) * sin(d * log(a^2 + b^2) / 2 + c * atan2(b, a))
|
||||
*
|
||||
* =>...
|
||||
* Re = exp(c * log(sqrt(a^2 + b^2)) - d * atan2(b, a)) * cos(d * log(sqrt(a^2 + b^2)) + c * atan2(b, a))
|
||||
* Im = exp(c * log(sqrt(a^2 + b^2)) - d * atan2(b, a)) * sin(d * log(sqrt(a^2 + b^2)) + c * atan2(b, a))
|
||||
*
|
||||
* =>
|
||||
* Re = exp(c * logsq2 - d * arg(z_1)) * cos(d * logsq2 + c * arg(z_1))
|
||||
* Im = exp(c * logsq2 - d * arg(z_1)) * sin(d * logsq2 + c * arg(z_1))
|
||||
*
|
||||
*/
|
||||
|
||||
a = Math.exp(P["re"] * loh - P["im"] * arg);
|
||||
b = P["im"] * loh + P["re"] * arg;
|
||||
return new Complex(
|
||||
a * Math.cos(b),
|
||||
a * Math.sin(b));
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex square root
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"sqrt": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
var r = this["abs"]();
|
||||
|
||||
var re, im;
|
||||
|
||||
if (a >= 0 && b === 0) {
|
||||
return new Complex(Math.sqrt(a), 0);
|
||||
}
|
||||
|
||||
if (a >= 0) {
|
||||
re = 0.5 * Math.sqrt(2.0 * (r + a));
|
||||
} else {
|
||||
re = Math.abs(b) / Math.sqrt(2 * (r - a));
|
||||
}
|
||||
|
||||
if (a <= 0) {
|
||||
im = 0.5 * Math.sqrt(2.0 * (r - a));
|
||||
} else {
|
||||
im = Math.abs(b) / Math.sqrt(2 * (r + a));
|
||||
}
|
||||
|
||||
return new Complex(re, b >= 0 ? im : -im);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex exponent
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"exp": function() {
|
||||
|
||||
var tmp = Math.exp(this["re"]);
|
||||
|
||||
if (this["im"] === 0) {
|
||||
//return new Complex(tmp, 0);
|
||||
}
|
||||
return new Complex(
|
||||
tmp * Math.cos(this["im"]),
|
||||
tmp * Math.sin(this["im"]));
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the natural log
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"log": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
if (b === 0 && a > 0) {
|
||||
//return new Complex(Math.log(a), 0);
|
||||
}
|
||||
|
||||
return new Complex(
|
||||
logHypot(a, b),
|
||||
Math.atan2(b, a));
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the magniture of the complex number
|
||||
*
|
||||
* @returns {number}
|
||||
*/
|
||||
"abs": function() {
|
||||
|
||||
var a = Math.abs(this["re"]);
|
||||
var b = Math.abs(this["im"]);
|
||||
|
||||
if (a < 3000 && b < 3000) {
|
||||
return Math.sqrt(a * a + b * b);
|
||||
}
|
||||
|
||||
if (a < b) {
|
||||
a = b;
|
||||
b = this["re"] / this["im"];
|
||||
} else {
|
||||
b = this["im"] / this["re"];
|
||||
}
|
||||
return a * Math.sqrt(1 + b * b);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the angle of the complex number
|
||||
*
|
||||
* @returns {number}
|
||||
*/
|
||||
"arg": function() {
|
||||
|
||||
return Math.atan2(this["im"], this["re"]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the sine of the complex number
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"sin": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
return new Complex(
|
||||
Math.sin(a) * Math.cosh(b),
|
||||
Math.cos(a) * Math.sinh(b));
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the cosine
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"cos": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
return new Complex(
|
||||
Math.cos(a) * Math.cosh(b),
|
||||
-Math.sin(a) * Math.sinh(b));
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the tangent
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"tan": function() {
|
||||
|
||||
var a = 2 * this["re"];
|
||||
var b = 2 * this["im"];
|
||||
var d = Math.cos(a) + Math.cosh(b);
|
||||
|
||||
return new Complex(
|
||||
Math.sin(a) / d,
|
||||
Math.sinh(b) / d);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the cotangent
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"cot": function() {
|
||||
|
||||
var a = 2 * this["re"];
|
||||
var b = 2 * this["im"];
|
||||
var d = Math.cos(a) - Math.cosh(b);
|
||||
|
||||
return new Complex(
|
||||
-Math.sin(a) / d,
|
||||
Math.sinh(b) / d);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the secant
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"sec": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
var d = 0.5 * Math.cosh(2 * b) + 0.5 * Math.cos(2 * a);
|
||||
|
||||
return new Complex(
|
||||
Math.cos(a) * Math.cosh(b) / d,
|
||||
Math.sin(a) * Math.sinh(b) / d);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the cosecans
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"csc": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
var d = 0.5 * Math.cosh(2 * b) - 0.5 * Math.cos(2 * a);
|
||||
|
||||
return new Complex(
|
||||
Math.sin(a) * Math.cosh(b) / d,
|
||||
-Math.cos(a) * Math.sinh(b) / d);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex arcus sinus
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"asin": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
var t1 = new Complex(
|
||||
b * b - a * a + 1,
|
||||
-2 * a * b)['sqrt']();
|
||||
|
||||
var t2 = new Complex(
|
||||
t1['re'] - b,
|
||||
t1['im'] + a)['log']();
|
||||
|
||||
return new Complex(t2['im'], -t2['re']);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex arcus cosinus
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"acos": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
var t1 = new Complex(
|
||||
b * b - a * a + 1,
|
||||
-2 * a * b)['sqrt']();
|
||||
|
||||
var t2 = new Complex(
|
||||
t1["re"] - b,
|
||||
t1["im"] + a)['log']();
|
||||
|
||||
return new Complex(Math.PI / 2 - t2["im"], t2["re"]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex arcus tangent
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"atan": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
if (a === 0) {
|
||||
|
||||
if (b === 1) {
|
||||
return new Complex(0, Infinity);
|
||||
}
|
||||
|
||||
if (b === -1) {
|
||||
return new Complex(0, -Infinity);
|
||||
}
|
||||
}
|
||||
|
||||
var d = a * a + (1.0 - b) * (1.0 - b);
|
||||
|
||||
var t1 = new Complex(
|
||||
(1 - b * b - a * a) / d,
|
||||
-2 * a / d).log();
|
||||
|
||||
return new Complex(-0.5 * t1["im"], 0.5 * t1["re"]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex arcus cotangent
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"acot": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
if (b === 0) {
|
||||
return new Complex(Math.atan2(1, a), 0);
|
||||
}
|
||||
|
||||
var d = a * a + b * b;
|
||||
return (d !== 0)
|
||||
? new Complex(
|
||||
a / d,
|
||||
-b / d).atan()
|
||||
: new Complex(
|
||||
(a !== 0) ? a / 0 : 0,
|
||||
(b !== 0) ?-b / 0 : 0).atan();
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex arcus secant
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"asec": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
if (a === 0 && b === 0) {
|
||||
return new Complex(0, Infinity);
|
||||
}
|
||||
|
||||
var d = a * a + b * b;
|
||||
return (d !== 0)
|
||||
? new Complex(
|
||||
a / d,
|
||||
-b / d).acos()
|
||||
: new Complex(
|
||||
(a !== 0) ? a / 0 : 0,
|
||||
(b !== 0) ?-b / 0 : 0).acos();
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex arcus cosecans
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"acsc": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
if (a === 0 && b === 0) {
|
||||
return new Complex(Math.PI / 2, Infinity);
|
||||
}
|
||||
|
||||
var d = a * a + b * b;
|
||||
return (d !== 0)
|
||||
? new Complex(
|
||||
a / d,
|
||||
-b / d).asin()
|
||||
: new Complex(
|
||||
(a !== 0) ? a / 0 : 0,
|
||||
(b !== 0) ?-b / 0 : 0).asin();
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex sinh
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"sinh": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
return new Complex(
|
||||
Math.sinh(a) * Math.cos(b),
|
||||
Math.cosh(a) * Math.sin(b));
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex cosh
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"cosh": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
return new Complex(
|
||||
Math.cosh(a) * Math.cos(b),
|
||||
Math.sinh(a) * Math.sin(b));
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex tanh
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"tanh": function() {
|
||||
|
||||
var a = 2 * this["re"];
|
||||
var b = 2 * this["im"];
|
||||
var d = Math.cosh(a) + Math.cos(b);
|
||||
|
||||
return new Complex(
|
||||
Math.sinh(a) / d,
|
||||
Math.sin(b) / d);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex coth
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"coth": function() {
|
||||
|
||||
var a = 2 * this["re"];
|
||||
var b = 2 * this["im"];
|
||||
var d = Math.cosh(a) - Math.cos(b);
|
||||
|
||||
return new Complex(
|
||||
Math.sinh(a) / d,
|
||||
-Math.sin(b) / d);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex coth
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"csch": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
var d = Math.cos(2 * b) - Math.cosh(2 * a);
|
||||
|
||||
return new Complex(
|
||||
-2 * Math.sinh(a) * Math.cos(b) / d,
|
||||
2 * Math.cosh(a) * Math.sin(b) / d);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex sech
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"sech": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
var d = Math.cos(2 * b) + Math.cosh(2 * a);
|
||||
|
||||
return new Complex(
|
||||
2 * Math.cosh(a) * Math.cos(b) / d,
|
||||
-2 * Math.sinh(a) * Math.sin(b) / d);
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex asinh
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"asinh": function() {
|
||||
|
||||
var tmp = this["im"];
|
||||
this["im"] = -this["re"];
|
||||
this["re"] = tmp;
|
||||
var res = this["asin"]();
|
||||
|
||||
this["re"] = -this["im"];
|
||||
this["im"] = tmp;
|
||||
tmp = res["re"];
|
||||
|
||||
res["re"] = -res["im"];
|
||||
res["im"] = tmp;
|
||||
return res;
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex asinh
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"acosh": function() {
|
||||
|
||||
var tmp;
|
||||
var res = this["acos"]();
|
||||
if (res["im"] <= 0) {
|
||||
tmp = res["re"];
|
||||
res["re"] = -res["im"];
|
||||
res["im"] = tmp;
|
||||
} else {
|
||||
tmp = res["im"];
|
||||
res["im"] = -res["re"];
|
||||
res["re"] = tmp;
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex atanh
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"atanh": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
var noIM = a > 1 && b === 0;
|
||||
var oneMinus = 1 - a;
|
||||
var onePlus = 1 + a;
|
||||
var d = oneMinus * oneMinus + b * b;
|
||||
|
||||
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);
|
||||
|
||||
var temp = x["re"];
|
||||
x["re"] = logHypot(x["re"], x["im"]) / 2;
|
||||
x["im"] = Math.atan2(x["im"], temp) / 2;
|
||||
if (noIM) {
|
||||
x["im"] = -x["im"];
|
||||
}
|
||||
return x;
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex acoth
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"acoth": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
if (a === 0 && b === 0) {
|
||||
|
||||
return new Complex(0, Math.PI / 2);
|
||||
}
|
||||
|
||||
var d = a * a + b * b;
|
||||
return (d !== 0)
|
||||
? new Complex(
|
||||
a / d,
|
||||
-b / d).atanh()
|
||||
: new Complex(
|
||||
(a !== 0) ? a / 0 : 0,
|
||||
(b !== 0) ?-b / 0 : 0).atanh();
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex acsch
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"acsch": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
if (b === 0) {
|
||||
|
||||
return new Complex(
|
||||
(a !== 0)
|
||||
? Math.log(a + Math.sqrt(a * a + 1))
|
||||
: Infinity, 0);
|
||||
}
|
||||
|
||||
var d = a * a + b * b;
|
||||
return (d !== 0)
|
||||
? new Complex(
|
||||
a / d,
|
||||
-b / d).asinh()
|
||||
: new Complex(
|
||||
(a !== 0) ? a / 0 : 0,
|
||||
(b !== 0) ?-b / 0 : 0).asinh();
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex asech
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"asech": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
if (a === 0 && b === 0) {
|
||||
return new Complex(Infinity, 0);
|
||||
}
|
||||
|
||||
var d = a * a + b * b;
|
||||
return (d !== 0)
|
||||
? new Complex(
|
||||
a / d,
|
||||
-b / d).acosh()
|
||||
: new Complex(
|
||||
(a !== 0) ? a / 0 : 0,
|
||||
(b !== 0) ?-b / 0 : 0).acosh();
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate the complex inverse 1/z
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"inverse": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
|
||||
var d = a * a + b * b;
|
||||
|
||||
return new Complex(
|
||||
a !== 0 ? a / d : 0,
|
||||
b !== 0 ?-b / d : 0);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the complex conjugate
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"conjugate": function() {
|
||||
|
||||
return new Complex(this["re"], -this["im"]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the negated complex number
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"neg": function() {
|
||||
|
||||
return new Complex(-this["re"], -this["im"]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Ceils the actual complex number
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"ceil": function(places) {
|
||||
|
||||
places = Math.pow(10, places || 0);
|
||||
|
||||
return new Complex(
|
||||
Math.ceil(this["re"] * places) / places,
|
||||
Math.ceil(this["im"] * places) / places);
|
||||
},
|
||||
|
||||
/**
|
||||
* Floors the actual complex number
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"floor": function(places) {
|
||||
|
||||
places = Math.pow(10, places || 0);
|
||||
|
||||
return new Complex(
|
||||
Math.floor(this["re"] * places) / places,
|
||||
Math.floor(this["im"] * places) / places);
|
||||
},
|
||||
|
||||
/**
|
||||
* Ceils the actual complex number
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"round": function(places) {
|
||||
|
||||
places = Math.pow(10, places || 0);
|
||||
|
||||
return new Complex(
|
||||
Math.round(this["re"] * places) / places,
|
||||
Math.round(this["im"] * places) / places);
|
||||
},
|
||||
|
||||
/**
|
||||
* Compares two complex numbers
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
"equals": function(a, b) {
|
||||
|
||||
parse(a, b); // mutates P
|
||||
|
||||
return Math.abs(P["re"] - this["re"]) <= Complex["EPSILON"] &&
|
||||
Math.abs(P["im"] - this["im"]) <= Complex["EPSILON"];
|
||||
},
|
||||
|
||||
/**
|
||||
* Clones the actual object
|
||||
*
|
||||
* @returns {Complex}
|
||||
*/
|
||||
"clone": function() {
|
||||
|
||||
return new Complex(this["re"], this["im"]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets a string of the actual complex number
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
"toString": function() {
|
||||
|
||||
var a = this["re"];
|
||||
var b = this["im"];
|
||||
var ret = "";
|
||||
|
||||
if (isNaN(a) || isNaN(b)) {
|
||||
return "NaN";
|
||||
}
|
||||
|
||||
if (a !== 0) {
|
||||
ret+= a;
|
||||
}
|
||||
|
||||
if (b !== 0) {
|
||||
|
||||
if (a !== 0) {
|
||||
ret+= b < 0 ? " - " : " + ";
|
||||
} else if (b < 0) {
|
||||
ret+= "-";
|
||||
}
|
||||
|
||||
b = Math.abs(b);
|
||||
|
||||
if (1 !== b) {
|
||||
ret+= b;
|
||||
}
|
||||
ret+= "i";
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
return "0";
|
||||
|
||||
return ret;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the actual number as a vector
|
||||
*
|
||||
* @returns {Array}
|
||||
*/
|
||||
"toVector": function() {
|
||||
|
||||
return [this["re"], this["im"]];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the actual real value of the current object
|
||||
*
|
||||
* @returns {number|null}
|
||||
*/
|
||||
"valueOf": function() {
|
||||
|
||||
if (this["im"] === 0) {
|
||||
return this["re"];
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the given complex number is not a number
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isNaN: function() {
|
||||
return isNaN(this['re']) || isNaN(this['im']);
|
||||
}
|
||||
};
|
||||
|
||||
Complex["ZERO"] = new Complex(0, 0);
|
||||
Complex["ONE"] = new Complex(1, 0);
|
||||
Complex["I"] = new Complex(0, 1);
|
||||
Complex["PI"] = new Complex(Math.PI, 0);
|
||||
Complex["E"] = new Complex(Math.E, 0);
|
||||
Complex['EPSILON'] = 1e-16;
|
||||
|
||||
if (typeof define === "function" && define["amd"]) {
|
||||
define([], function() {
|
||||
return Complex;
|
||||
});
|
||||
} else if (typeof exports === "object") {
|
||||
module["exports"] = Complex;
|
||||
} else {
|
||||
root["Complex"] = Complex;
|
||||
}
|
||||
|
||||
})(this);
|
||||
22
nodered/rootfs/data/node_modules/complex.js/complex.min.js
generated
vendored
Normal file
22
nodered/rootfs/data/node_modules/complex.js/complex.min.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Complex.js v2.0.1 11/02/2016
|
||||
|
||||
Copyright (c) 2016, Robert Eisele (robert@xarg.org)
|
||||
Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
*/
|
||||
(function(p){"use strict";function l(a,b){if(void 0===a||null===a)e.re=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*|\.\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++:("i"===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++)):((0===d+f||isNaN(k))&&m(),"i"===c[g+1]||"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 SyntaxError("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):
|
||||
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);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;if(0<=a&&0===b)return new d(Math.sqrt(a),0);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(3E3>a&&3E3>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=2*this.re,b=2*this.im,c=Math.cos(a)+Math.cosh(b);return new d(Math.sin(a)/c,Math.sinh(b)/c)},cot:function(){var a=2*this.re,b=2*this.im,c=Math.cos(a)-Math.cosh(b);return new d(-Math.sin(a)/c,Math.sinh(b)/c)},sec:function(){var a=this.re,b=this.im,c=.5*Math.cosh(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=.5*Math.cosh(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-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(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=2*this.re,b=2*this.im,
|
||||
c=Math.cosh(a)+Math.cos(b);return new d(Math.sinh(a)/c,Math.sin(b)/c)},coth:function(){var a=2*this.re,b=2*this.im,c=Math.cosh(a)-Math.cos(b);return new d(Math.sinh(a)/c,-Math.sin(b)/c)},csch:function(){var a=this.re,b=this.im,c=Math.cos(2*b)-Math.cosh(2*a);return new d(-2*Math.sinh(a)*Math.cos(b)/c,2*Math.cosh(a)*Math.sin(b)/c)},sech:function(){var a=this.re,b=this.im,c=Math.cos(2*b)+Math.cosh(2*a);return new d(2*Math.cosh(a)*Math.cos(b)/c,-2*Math.sinh(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,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);
|
||||
62
nodered/rootfs/data/node_modules/complex.js/package.json
generated
vendored
Normal file
62
nodered/rootfs/data/node_modules/complex.js/package.json
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"_from": "complex.js@2.0.1",
|
||||
"_id": "complex.js@2.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-6pDHoFrs6vOjdtLA9qeEIXJ9aHk=",
|
||||
"_location": "/complex.js",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "complex.js@2.0.1",
|
||||
"name": "complex.js",
|
||||
"escapedName": "complex.js",
|
||||
"rawSpec": "2.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mathjs"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/complex.js/-/complex.js-2.0.1.tgz",
|
||||
"_shasum": "ea90c7a05aeceaf3a376d2c0f6a78421727d6879",
|
||||
"_spec": "complex.js@2.0.1",
|
||||
"_where": "/data/node_modules/mathjs",
|
||||
"author": {
|
||||
"name": "Robert Eisele",
|
||||
"email": "robert@xarg.org",
|
||||
"url": "http://www.xarg.org/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/infusion/Complex.js/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "A complex number library",
|
||||
"devDependencies": {
|
||||
"mocha": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"homepage": "https://github.com/infusion/Complex.js",
|
||||
"keywords": [
|
||||
"math",
|
||||
"complex",
|
||||
"number",
|
||||
"calculus",
|
||||
"parser"
|
||||
],
|
||||
"license": "MIT OR GPL-2.0",
|
||||
"main": "complex",
|
||||
"name": "complex.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/infusion/Complex.js.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha tests/*.js"
|
||||
},
|
||||
"title": "complex.js",
|
||||
"version": "2.0.1"
|
||||
}
|
||||
631
nodered/rootfs/data/node_modules/complex.js/tests/complex.test.js
generated
vendored
Normal file
631
nodered/rootfs/data/node_modules/complex.js/tests/complex.test.js
generated
vendored
Normal file
@@ -0,0 +1,631 @@
|
||||
var assert = require("assert");
|
||||
|
||||
var Complex = require("../complex");
|
||||
|
||||
var tests = [{
|
||||
set: null,
|
||||
expect: "0"
|
||||
}, {
|
||||
set: undefined,
|
||||
expect: "0"
|
||||
}, {
|
||||
set: "foo",
|
||||
expect: "SyntaxError: Invalid Param"
|
||||
}, {
|
||||
set: {},
|
||||
expect: "SyntaxError: Invalid Param"
|
||||
}, {
|
||||
set: " + i",
|
||||
expect: "i"
|
||||
}, {
|
||||
set: "3",
|
||||
expect: "3"
|
||||
}, {
|
||||
set: "2.3",
|
||||
expect: "2.3"
|
||||
}, {
|
||||
set: {re: -Infinity, im: 0},
|
||||
expect: "-Infinity"
|
||||
}, {
|
||||
set: Complex.I,
|
||||
fn: "mul",
|
||||
param: Complex(Math.PI).exp(),
|
||||
expect: "23.140692632779274i"
|
||||
}, {
|
||||
set: 0,
|
||||
expect: "0"
|
||||
}, {
|
||||
set: "4 + 3i",
|
||||
fn: "add",
|
||||
param: "-3 - 2i",
|
||||
expect: "1 + i"
|
||||
}, {
|
||||
set: "3i",
|
||||
fn: "add",
|
||||
param: "-2i",
|
||||
expect: "i"
|
||||
}, {
|
||||
set: "4",
|
||||
fn: "add",
|
||||
param: "-3",
|
||||
expect: "1"
|
||||
}, {
|
||||
set: 9,
|
||||
fn: "sqrt",
|
||||
expect: "3"
|
||||
}, {
|
||||
set: -9,
|
||||
fn: "sqrt",
|
||||
expect: "3i"
|
||||
}, {
|
||||
set: "-36",
|
||||
fn: "sqrt",
|
||||
expect: "6i"
|
||||
}, {
|
||||
set: "36i",
|
||||
fn: "sqrt",
|
||||
expect: "4.242640687119285 + 4.242640687119285i"
|
||||
}, {
|
||||
set: Infinity,
|
||||
fn: "mul",
|
||||
param: "i",
|
||||
expect: "NaN"
|
||||
}, {
|
||||
set: "-36i",
|
||||
fn: "sqrt",
|
||||
expect: "4.242640687119285 - 4.242640687119285i"
|
||||
}, {
|
||||
set: "4 + 2i",
|
||||
fn: "div",
|
||||
param: "0",
|
||||
expect: "Infinity + Infinityi"
|
||||
}, {
|
||||
set: "4 + 2i",
|
||||
fn: "div",
|
||||
param: "1 + i",
|
||||
expect: "3 - i"
|
||||
}, {
|
||||
set: "25",
|
||||
fn: "div",
|
||||
param: "3 - 4i",
|
||||
expect: "3 + 4i"
|
||||
}, {
|
||||
set: "3 - 2i",
|
||||
fn: "div",
|
||||
param: "i",
|
||||
expect: "-2 - 3i"
|
||||
}, {
|
||||
set: "4i",
|
||||
fn: "mul",
|
||||
param: "-5i",
|
||||
expect: "20"
|
||||
}, {
|
||||
set: "3 - 6i",
|
||||
fn: "mul",
|
||||
param: "i",
|
||||
expect: "6 + 3i"
|
||||
}, {
|
||||
set: "3 + 4i",
|
||||
fn: "add",
|
||||
param: "5 - 7i",
|
||||
expect: "8 - 3i"
|
||||
}, {
|
||||
set: "6i",
|
||||
fn: "div",
|
||||
param: "3 - 12i",
|
||||
expect: "-0.47058823529411764 + 0.11764705882352941i"
|
||||
}, {
|
||||
set: "36 + 36i",
|
||||
fn: "sqrt",
|
||||
expect: "6.59210468080686 + 2.730539163373364i"
|
||||
}, {
|
||||
set: "36 - 36i",
|
||||
fn: "sqrt",
|
||||
expect: "6.59210468080686 - 2.730539163373364i"
|
||||
}, {
|
||||
set: "-36 + 36i",
|
||||
fn: "sqrt",
|
||||
expect: "2.730539163373364 + 6.59210468080686i"
|
||||
}, {
|
||||
set: "-36 - 36i",
|
||||
fn: "sqrt",
|
||||
expect: "2.730539163373364 - 6.59210468080686i"
|
||||
}, {
|
||||
set: "0",
|
||||
fn: "sqrt",
|
||||
expect: "0"
|
||||
}, {
|
||||
set: Math.E,
|
||||
fn: "log",
|
||||
expect: "1"
|
||||
}, {
|
||||
set: 0,
|
||||
fn: "log",
|
||||
expect: "-Infinity"
|
||||
}, {
|
||||
set: Infinity,
|
||||
fn: "mul",
|
||||
param: 3,
|
||||
expect: "Infinity"
|
||||
}, {
|
||||
set: "-1",
|
||||
fn: "log",
|
||||
expect: Math.PI + "i"
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "log",
|
||||
expect: (Math.PI / 2) + "i"
|
||||
}, {
|
||||
set: "3 + 2i",
|
||||
fn: "log",
|
||||
expect: Math.log(13) / 2 + " + " + Math.atan2(2, 3) + "i"
|
||||
}, {
|
||||
set: "3 - 2i",
|
||||
fn: "log",
|
||||
expect: Math.log(13) / 2 + " - " + Math.atan2(2, 3) + "i"
|
||||
}, {
|
||||
set: 1,
|
||||
fn: "exp",
|
||||
expect: "" + Math.E
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "exp",
|
||||
expect: Math.cos(1) + " + " + Math.sin(1) + "i"
|
||||
}, {
|
||||
set: "3 + 2i",
|
||||
fn: "exp",
|
||||
expect: "-8.358532650935372 + 18.263727040666765i"
|
||||
}, {
|
||||
set: "3 - 2i",
|
||||
fn: "exp",
|
||||
expect: "-8.358532650935372 - 18.263727040666765i"
|
||||
}, {
|
||||
set: "3",
|
||||
fn: "pow",
|
||||
param: "3",
|
||||
expect: "27"
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "pow",
|
||||
param: "0",
|
||||
expect: "1"
|
||||
}, {
|
||||
set: "87",
|
||||
fn: "pow",
|
||||
param: "3",
|
||||
expect: "658503"
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "pow",
|
||||
param: "1",
|
||||
expect: "i"
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "pow",
|
||||
param: "2",
|
||||
expect: "-1"
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "pow",
|
||||
param: "3",
|
||||
expect: "-i"
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "pow",
|
||||
param: "4",
|
||||
expect: "1"
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "pow",
|
||||
param: "5",
|
||||
expect: "i"
|
||||
}, {
|
||||
set: 7,
|
||||
fn: "pow",
|
||||
param: 2,
|
||||
expect: 49
|
||||
}, {
|
||||
set: 0,
|
||||
fn: "pow",
|
||||
param: 2,
|
||||
expect: 0
|
||||
}, {
|
||||
set: "3i",
|
||||
fn: "pow",
|
||||
param: "3i",
|
||||
expect: "-0.008876640735623675 - 0.0013801328997494896i"
|
||||
}, {
|
||||
set: {re: 3, im: 4},
|
||||
fn: "abs",
|
||||
expect: "5"
|
||||
}, {
|
||||
set: {re: 10, im: 24},
|
||||
fn: "abs",
|
||||
expect: "26"
|
||||
}, {
|
||||
set: "1 + 4i",
|
||||
fn: "mul",
|
||||
param: "3 + 2i",
|
||||
expect: "-5 + 14i"
|
||||
}, {
|
||||
set: "4 + 16i",
|
||||
fn: "div",
|
||||
param: "4.0000",
|
||||
expect: "1 + 4i"
|
||||
}, {
|
||||
set: {re: -7.1, im: 2.5},
|
||||
fn: "neg",
|
||||
expect: "7.1 - 2.5i"
|
||||
}, {
|
||||
set: {re: 1, im: 1},
|
||||
fn: "arg",
|
||||
expect: "" + Math.PI / 4
|
||||
}, {
|
||||
set: {re: -1, im: -1},
|
||||
fn: "arg",
|
||||
expect: "" + -3 * Math.PI / 4
|
||||
}, {
|
||||
set: {re: 0, im: 1},
|
||||
fn: "arg",
|
||||
expect: "" + Math.PI / 2
|
||||
}, {
|
||||
set: {re: 1, im: 0.5 * Math.sqrt(4 / 3)},
|
||||
fn: "arg",
|
||||
expect: "" + Math.PI / 6
|
||||
}, {
|
||||
set: {re: 99, im: 50},
|
||||
fn: "conjugate",
|
||||
expect: "99 - 50i"
|
||||
}, {
|
||||
set: "2 + 8i",
|
||||
fn: "div",
|
||||
param: new Complex(1, 2),
|
||||
expect: "3.6 + 0.8i"
|
||||
}, {
|
||||
set: -Infinity,
|
||||
fn: "div",
|
||||
param: 3,
|
||||
expect: "-Infinity"
|
||||
}, {
|
||||
set: {re: 1, im: 2},
|
||||
fn: "add",
|
||||
param: "4 + 6i",
|
||||
expect: "5 + 8i"
|
||||
}, {
|
||||
set: {re: 5, im: 8},
|
||||
fn: "sub",
|
||||
param: "4 + 6i",
|
||||
expect: "1 + 2i"
|
||||
}, {
|
||||
set: "1 + 2i",
|
||||
fn: "pow",
|
||||
param: "2",
|
||||
expect: "-2.999999999999999 + 4.000000000000001i"
|
||||
}, {
|
||||
set: "1 + 2i",
|
||||
fn: "pow",
|
||||
param: "1 + 2i",
|
||||
expect: "-0.22251715680177267 + 0.10070913113607541i"
|
||||
}, {
|
||||
set: {re: 1, im: 2},
|
||||
fn: "pow",
|
||||
param: new Complex(3, 4),
|
||||
expect: "0.12900959407446697 + 0.033924092905170025i"
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "pow",
|
||||
param: 7,
|
||||
expect: "-i"
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "pow",
|
||||
param: 4,
|
||||
expect: "1"
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "pow",
|
||||
param: 5,
|
||||
expect: "i"
|
||||
}, {
|
||||
set: "0-0i",
|
||||
fn: "pow",
|
||||
param: 2,
|
||||
expect: "0"
|
||||
}, {
|
||||
set: "0-0i",
|
||||
fn: "pow",
|
||||
param: 0,
|
||||
expect: "0"
|
||||
}, {
|
||||
set: "1 + 4i",
|
||||
fn: "sqrt",
|
||||
expect: "1.600485180440241 + 1.2496210676876531i"
|
||||
}, {
|
||||
set: {re: -3, im: 4},
|
||||
fn: "sqrt",
|
||||
expect: "1 + 2i"
|
||||
}, {
|
||||
set: {re: 3, im: -4},
|
||||
fn: "sqrt",
|
||||
expect: "2 - i"
|
||||
}, {
|
||||
set: {re: -3, im: -4},
|
||||
fn: "sqrt",
|
||||
expect: "1 - 2i"
|
||||
}, {
|
||||
set: -Complex.E.pow(2),
|
||||
fn: "log",
|
||||
expect: "2 + 3.141592653589793i"
|
||||
}, {
|
||||
set: "4 + 3i",
|
||||
fn: "log",
|
||||
expect: "1.6094379124341003 + 0.6435011087932844i"
|
||||
}, {
|
||||
set: "4 + 3i",
|
||||
fn: "exp",
|
||||
expect: "-54.05175886107815 + 7.7048913727311525i"
|
||||
}, {
|
||||
set: "1-2i",
|
||||
fn: "sqrt",
|
||||
expect: "1.272019649514069 - 0.7861513777574233i"
|
||||
}, {
|
||||
set: {re: 1, im: 2},
|
||||
fn: "sin",
|
||||
expect: "3.1657785132161678 + 1.9596010414216063i"
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "cos",
|
||||
expect: "1.5430806348152437"
|
||||
}, {
|
||||
set: "i",
|
||||
fn: "acos",
|
||||
expect: "1.5707963267948966 - 0.8813735870195428i"
|
||||
}, {
|
||||
set: {re: 1, im: 2},
|
||||
fn: "cos",
|
||||
expect: "2.0327230070196656 - 3.0518977991518i"
|
||||
}, {
|
||||
set: {re: 1, im: 2},
|
||||
fn: "tan",
|
||||
expect: "0.0338128260798967 + 1.0147936161466335i"
|
||||
}, {
|
||||
set: {re: 1, im: 3},
|
||||
fn: "sinh",
|
||||
expect: "-1.1634403637032504 + 0.21775955162215221i"
|
||||
}, {
|
||||
set: {re: 1, im: 3},
|
||||
fn: "cosh",
|
||||
expect: "-1.5276382501165433 + 0.1658444019189788i"
|
||||
}, {
|
||||
set: {re: 1, im: 3},
|
||||
fn: "tanh",
|
||||
expect: "0.7680176472869114 - 0.05916853956605073i"
|
||||
}, {
|
||||
set: {re: 1, im: 3},
|
||||
fn: "inverse",
|
||||
expect: "0.1 - 0.3i"
|
||||
}, {
|
||||
set: {re: 0.5, im: -0.5},
|
||||
fn: "inverse",
|
||||
expect: "1 + i"
|
||||
}, {
|
||||
set: "1 + i",
|
||||
fn: "inverse",
|
||||
expect: "0.5 - 0.5i"
|
||||
}, {
|
||||
set: "0",
|
||||
fn: "inverse",
|
||||
expect: "0"
|
||||
}, {
|
||||
set: Complex['EPSILON'],
|
||||
fn: "equals",
|
||||
param: 1e-16,
|
||||
expect: "true"
|
||||
}, {
|
||||
set: 0,
|
||||
fn: "equals",
|
||||
param: "5i",
|
||||
expect: "false"
|
||||
}, {
|
||||
set: 5,
|
||||
fn: "equals",
|
||||
param: "5i",
|
||||
expect: "false"
|
||||
}, {
|
||||
set: 5,
|
||||
fn: "equals",
|
||||
param: 5,
|
||||
expect: "true"
|
||||
}, {
|
||||
set: "10i",
|
||||
fn: "equals",
|
||||
param: "10i",
|
||||
expect: "true"
|
||||
}, {
|
||||
set: "2 + 3i",
|
||||
fn: "equals",
|
||||
param: "2 + 3i",
|
||||
expect: "true"
|
||||
}, {
|
||||
set: "2 + 3i",
|
||||
fn: "equals",
|
||||
param: "5i",
|
||||
expect: "false"
|
||||
}, {
|
||||
set: "2 + 3i",
|
||||
fn: "round",
|
||||
param: "0",
|
||||
expect: "2 + 3i"
|
||||
}, {
|
||||
set: "2.5 + 3.5i",
|
||||
fn: "round",
|
||||
param: "1",
|
||||
expect: "2.5 + 3.5i"
|
||||
}, {
|
||||
set: "2.5 + 3.5i",
|
||||
fn: "sign",
|
||||
param: null,
|
||||
expect: "0.5812381937190965 + 0.813733471206735i"
|
||||
}, {
|
||||
set: "10 + 24i",
|
||||
fn: "sign",
|
||||
param: null,
|
||||
expect: "0.38461538461538464 + 0.9230769230769231i"
|
||||
}, {
|
||||
set: "1e3i",
|
||||
fn: "add",
|
||||
param: "3e-3 + 1e2i",
|
||||
expect: "0.003 + 1100i"
|
||||
}, {
|
||||
set: "3.14-4i",
|
||||
fn: "coth",
|
||||
expect: "0.9994481238383571 + 0.0037048958915019844i"
|
||||
}, {
|
||||
set: "8i-31",
|
||||
fn: "cot",
|
||||
expect: "1.663676829121394e-7 - 1.0000001515864905i"
|
||||
}, {
|
||||
set: " + 7 - i + 3i - + + + + 43 + 2i - i4 + - 33 + 65 - 1 ",
|
||||
expect: "-5"
|
||||
}, {
|
||||
set: " + 7 - i + 3i - + + + + 43 + 2i - i4 + - 33 + 65 - 1 + ",
|
||||
expect: "SyntaxError: Invalid Param"
|
||||
}, {
|
||||
set: "-3x + 4",
|
||||
expect: "SyntaxError: Invalid Param"
|
||||
}, {
|
||||
set: "- + 7",
|
||||
expect: "-7"
|
||||
}, {
|
||||
set: "4 5i",
|
||||
expect: "SyntaxError: Invalid Param"
|
||||
}, {
|
||||
set: "-",
|
||||
expect: "SyntaxError: Invalid Param"
|
||||
}, {
|
||||
set: "2.2e-1-3.2e-1i",
|
||||
expect: "0.22 - 0.32i"
|
||||
}, {
|
||||
set: "2.2.",
|
||||
expect: "SyntaxError: Invalid Param"
|
||||
}, {
|
||||
set: {r: 0, phi: 4},
|
||||
expect: "0"
|
||||
}, {
|
||||
set: {r: 1, phi: 1},
|
||||
expect: "0.5403023058681398 + 0.8414709848078965i"
|
||||
}
|
||||
];
|
||||
|
||||
describe("Complex", function() {
|
||||
|
||||
for (var i = 0; i < tests.length; i++) {
|
||||
|
||||
(function(i) {
|
||||
|
||||
if (tests[i].fn) {
|
||||
|
||||
it((tests[i].fn || "") + " " + tests[i].set + ", " + (tests[i].param || ""), function() {
|
||||
try {
|
||||
assert.equal(tests[i].expect, new Complex(tests[i].set)[tests[i].fn](tests[i].param).toString());
|
||||
} catch (e) {
|
||||
assert.equal(e.toString(), tests[i].expect.toString());
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
it((tests[i].fn || "") + "" + tests[i].set, function() {
|
||||
try {
|
||||
assert.equal(tests[i].expect, new Complex(tests[i].set).toString());
|
||||
} catch (e) {
|
||||
assert.equal(e.toString(), tests[i].expect.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
})(i);
|
||||
}
|
||||
});
|
||||
|
||||
describe("Complex Details", function() {
|
||||
|
||||
it("should work with different params", function() {
|
||||
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("i").toString(), "i");
|
||||
assert.equal(Complex.I.toString(), "i");
|
||||
assert.equal(Complex("3 - 4i").toString(), "3 - 4i");
|
||||
assert.equal(Complex("5").toString(), "5");
|
||||
assert.equal(Complex(0, -2).toString(), "-2i");
|
||||
assert.equal(Complex({re: 0, im: -2}).toString(), "-2i");
|
||||
});
|
||||
|
||||
it("Complex Combinations", function() {
|
||||
|
||||
var zero = Complex(0, 0), one = Complex(1, 1), two = Complex(2, 2);
|
||||
|
||||
assert.equal(zero.toString(), "0");
|
||||
assert.equal(one.toString(), "1 + i");
|
||||
assert(one.neg().equals(Complex(-1, -1)));
|
||||
assert(one.conjugate().equals(Complex(1, -1)));
|
||||
assert.equal(one.abs(), Math.SQRT2);
|
||||
assert.equal(one.arg(), Math.PI / 4);
|
||||
assert.equal(one.add(one).toString(), two.toString());
|
||||
assert.equal(one.sub(one).toString(), zero.toString());
|
||||
assert.equal(one.mul(2).toString(), two.toString());
|
||||
assert.equal(one.mul(one).toString(), Complex(0, 2).toString());
|
||||
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.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.2717525853195118 + 1.0839233273386948i");
|
||||
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")
|
||||
});
|
||||
|
||||
it("should handle inverse trig fns", function() {
|
||||
|
||||
var values = [
|
||||
new Complex(2.3, 1.4),
|
||||
new Complex(-2.3, 1.4),
|
||||
new Complex(-2.3, -1.4),
|
||||
new Complex(2.3, -1.4)];
|
||||
|
||||
var fns = ['sin', 'cos', 'tan'];
|
||||
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
|
||||
for (var j = 0; j < 3; j++) {
|
||||
|
||||
var a = values[i]['a' + fns[j]]()[fns[j]]();
|
||||
|
||||
var res = values[i];
|
||||
|
||||
assert(Math.abs(a.re - res.re) < 1e-12 && Math.abs(a.im - res.im) < 1e-12);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user