added factorial module

This commit is contained in:
szabomarton
2024-10-22 13:12:20 +02:00
parent 7f2ddb3a86
commit e12780f413
2836 changed files with 207364 additions and 0 deletions

21
24_10_22_faktorialis/node_modules/complex.js/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Robert Eisele
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

336
24_10_22_faktorialis/node_modules/complex.js/README.md generated vendored Normal file
View File

@@ -0,0 +1,336 @@
# Complex.js - in JavaScript
[![NPM Package](https://img.shields.io/npm/v/complex.js.svg?style=flat)](https://npmjs.org/package/complex.js "View this project on npm")
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
Complex.js is a well tested JavaScript library to work with [complex number arithmetic](https://raw.org/book/analysis/complex-numbers/) in JavaScript. It implements every elementary complex number manipulation function and the API is intentionally similar to [Fraction.js](https://github.com/rawify/Fraction.js). Furthermore, it's the basis of [Polynomial.js](https://github.com/infusion/Polynomial.js) and [Math.js](https://github.com/josdejong/mathjs).
## Examples
```js
let Complex = require('complex.js');
let c = new Complex("99.3+8i");
c.mul({re: 3, im: 9}).div(4.9).sub(3, 2);
```
A classical use case for complex numbers is solving quadratic equations `ax² + bx + c = 0` for all `a, b, c ∈ `:
```js
function quadraticRoot(a, b, c) {
let sqrt = Complex(b * b - 4 * a * c).sqrt()
let x1 = Complex(-b).add(sqrt).div(2 * a)
let x2 = Complex(-b).sub(sqrt).div(2 * a)
return {x1, x2}
}
// quadraticRoot(1, 4, 5) -> -2 ± i
```
For cubic roots have a look at [RootFinder](https://github.com/rawify/RootFinder.js) which uses Complex.js.
## 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});
new Complex([real, imaginary]); // Vector/Array syntax
```
If there are other attributes on the passed object, they're not getting preserved and have to be merged manually.
### 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
```
## Attributes
Every complex number object exposes its real and imaginary part as attribute `re` and `im`:
```javascript
let c = new Complex(3, 2);
console.log("Real part:", c.re); // 3
console.log("Imaginary part:", c.im); // 2
```
## 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 (Note: `Complex.ZERO.pow(0) = Complex.ONE` by convention)
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
_Note:_ The logarithm to a different base can be calculated with `z.log().div(Math.log(base))`.
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, if both numbers are infinite they
are considered **not** equal.
boolean isNaN()
---
Checks if the given number is not a number
boolean isFinite()
---
Checks if the given number is finite
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 | Area-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() |
## Geometric Equivalence
Complex numbers can also be seen as a vector in the 2D space. Here is a simple overview of basic operations and how to implement them with complex.js:
New vector
---
```js
let v1 = new Complex(1, 0);
let v2 = new Complex(1, 1);
```
Scale vector
---
```js
scale(v1, factor):= v1.mul(factor)
```
Vector norm
---
```js
norm(v):= v.abs()
```
Translate vector
---
```js
translate(v1, v2):= v1.add(v2)
```
Rotate vector around center
---
```js
rotate(v, angle):= v.mul({abs: 1, arg: angle})
```
Rotate vector around a point
---
```js
rotate(v, p, angle):= v.sub(p).mul({abs: 1, arg: angle}).add(p)
```
Distance to another vector
---
```js
distance(v1, v2):= v1.sub(v2).abs()
```
## Constants
Complex.ZERO
---
A complex zero value (south pole on the Riemann Sphere)
Complex.ONE
---
A complex one instance
Complex.INFINITY
---
A complex infinity value (north pole on the Riemann Sphere)
Complex.NAN
---
A complex NaN value (not on the Riemann Sphere)
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 `equals()` comparison in order to circumvent double imprecision.
## Installation
Installing complex.js is as easy as cloning this repo or use one of the following command:
```bash
npm install complex.js
```
## Using Complex.js with the browser
```html
<script src="complex.min.js"></script>
<script>
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.
## Building the library
After cloning the Git repository run:
```
npm install
npm run build
```
## Run a test
Testing the source against the shipped test suite is as easy as
```
npm run test
```
## Copyright and Licensing
Copyright (c) 2024, [Robert Eisele](https://raw.org/)
Licensed under the MIT license.

View File

@@ -0,0 +1,323 @@
type AValue =
| Complex
| { im: number; re: number }
| { abs: number; arg: number }
| { r: number; phi: number }
| [number, number]
| string
| number
| null
| undefined;
type BValue = number | undefined;
export function Complex(a: AValue, b?: BValue): Complex;
export default Complex;
/**
*
* This class allows the manipulation 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> }
*
* Array / Vector form
* [ real, imaginary ]
*
* 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);
*
*/
export class Complex {
re: number;
im: number;
constructor(a: AValue, b?: BValue);
/**
* Calculates the sign of a complex number, which is a normalized complex
*
*/
sign(): Complex;
/**
* Adds two complex numbers
*
*/
add(a: AValue, b?: BValue): Complex;
/**
* Subtracts two complex numbers
*
*/
sub(a: AValue, b?: BValue): Complex;
/**
* Multiplies two complex numbers
*
*/
mul(a: AValue, b?: BValue): Complex;
/**
* Divides two complex numbers
*
*/
div(a: AValue, b?: BValue): Complex;
/**
* Calculate the power of two complex numbers
*
*/
pow(a: AValue, b?: BValue): Complex;
/**
* Calculate the complex square root
*
*/
sqrt(): Complex;
/**
* Calculate the complex exponent
*
*/
exp(): Complex;
/**
* Calculate the complex exponent and subtracts one.
*
* This may be more accurate than `Complex(x).exp().sub(1)` if
* `x` is small.
*
*/
expm1(): Complex;
/**
* Calculate the natural log
*
*/
log(): Complex;
/**
* Calculate the magnitude of the complex number
*
*/
abs(): number;
/**
* Calculate the angle of the complex number
*
*/
arg(): number;
/**
* Calculate the sine of the complex number
*
*/
sin(): Complex;
/**
* Calculate the cosine
*
*/
cos(): Complex;
/**
* Calculate the tangent
*
*/
tan(): Complex;
/**
* Calculate the cotangent
*
*/
cot(): Complex;
/**
* Calculate the secant
*
*/
sec(): Complex;
/**
* Calculate the cosecans
*
*/
csc(): Complex;
/**
* Calculate the complex arcus sinus
*
*/
asin(): Complex;
/**
* Calculate the complex arcus cosinus
*
*/
acos(): Complex;
/**
* Calculate the complex arcus tangent
*
*/
atan(): Complex;
/**
* Calculate the complex arcus cotangent
*
*/
acot(): Complex;
/**
* Calculate the complex arcus secant
*
*/
asec(): Complex;
/**
* Calculate the complex arcus cosecans
*
*/
acsc(): Complex;
/**
* Calculate the complex sinh
*
*/
sinh(): Complex;
/**
* Calculate the complex cosh
*
*/
cosh(): Complex;
/**
* Calculate the complex tanh
*
*/
tanh(): Complex;
/**
* Calculate the complex coth
*
*/
coth(): Complex;
/**
* Calculate the complex coth
*
*/
csch(): Complex;
/**
* Calculate the complex sech
*
*/
sech(): Complex;
/**
* Calculate the complex asinh
*
*/
asinh(): Complex;
/**
* Calculate the complex acosh
*
*/
acosh(): Complex;
/**
* Calculate the complex atanh
*
*/
atanh(): Complex;
/**
* Calculate the complex acoth
*
*/
acoth(): Complex;
/**
* Calculate the complex acsch
*
*/
acsch(): Complex;
/**
* Calculate the complex asech
*
*/
asech(): Complex;
/**
* Calculate the complex inverse 1/z
*
*/
inverse(): Complex;
/**
* Returns the complex conjugate
*
*/
conjugate(): Complex;
/**
* Gets the negated complex number
*
*/
neg(): Complex;
/**
* Ceils the actual complex number
*
*/
ceil(places: number): Complex;
/**
* Floors the actual complex number
*
*/
floor(places: number): Complex;
/**
* Ceils the actual complex number
*
*/
round(places: number): Complex;
/**
* Compares two complex numbers
*
* **Note:** new Complex(Infinity).equals(Infinity) === false
*
*/
equals(a: AValue, b?: BValue): boolean;
/**
* Clones the actual object
*
*/
clone(): Complex;
/**
* Gets a string of the actual complex number
*
*/
toString(): string;
/**
* Returns the actual number as a vector
*
*/
toVector(): number[];
/**
* Returns the actual real value of the current object
*
* @returns {number|null}
*/
valueOf(): number | null;
/**
* Determines whether a complex number is not on the Riemann sphere.
*
*/
isNaN(): boolean;
/**
* Determines whether or not a complex number is at the zero pole of the
* Riemann sphere.
*
*/
isZero(): boolean;
/**
* Determines whether a complex number is not at the infinity pole of the
* Riemann sphere.
*
*/
isFinite(): boolean;
/**
* Determines whether or not a complex number is at the infinity pole of the
* Riemann sphere.
*
*/
isInfinite(): boolean;
static ZERO: Complex;
static ONE: Complex;
static I: Complex;
static PI: Complex;
static E: Complex;
static INFINITY: Complex;
static NAN: Complex;
static EPSILON: number;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
/*
Complex.js v2.3.0 10/10/2024
https://raw.org/article/complex-numbers-in-javascript/
Copyright (c) 2024, Robert Eisele (https://raw.org/)
Licensed under the MIT license.
*/
'use strict';(function(n){function l(){throw SyntaxError("Invalid Param");}function m(a,b){var c=Math.abs(a),e=Math.abs(b);if(0===a)return Math.log(e);if(0===b)return Math.log(c);if(3E3>c&&3E3>e)return.5*Math.log(a*a+b*b);a/=2;b/=2;return.5*Math.log(a*a+b*b)+Math.LN2}function d(a,b){if(!(this instanceof d))return new d(a,b);var c={re:0,im:0};if(void 0===a||null===a)c.re=c.im=0;else if(void 0!==b)c.re=a,c.im=b;else switch(typeof a){case "object":"im"in a&&"re"in a?(c.re=a.re,c.im=a.im):"abs"in a&&
"arg"in a?!Number.isFinite(a.abs)&&Number.isFinite(a.arg)?c=d.INFINITY:(c.re=a.abs*Math.cos(a.arg),c.im=a.abs*Math.sin(a.arg)):"r"in a&&"phi"in a?!Number.isFinite(a.r)&&Number.isFinite(a.phi)?c=d.INFINITY:(c.re=a.r*Math.cos(a.phi),c.im=a.r*Math.sin(a.phi)):2===a.length?(c.re=a[0],c.im=a[1]):l();break;case "string":c.im=c.re=0;a=a.replace(/_/g,"").match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g);b=1;var e=0;null===a&&l();for(var f=0;f<a.length;f++){var h=a[f];" "!==h&&"\t"!==h&&"\n"!==h&&("+"===h?b++:
"-"===h?e++:("i"===h||"I"===h?(0===b+e&&l()," "===a[f+1]||isNaN(a[f+1])?c.im+=parseFloat((e%2?"-":"")+"1"):(c.im+=parseFloat((e%2?"-":"")+a[f+1]),f++)):((0===b+e||isNaN(h))&&l(),"i"===a[f+1]||"I"===a[f+1]?(c.im+=parseFloat((e%2?"-":"")+h),f++):c.re+=parseFloat((e%2?"-":"")+h)),b=e=0))}0<b+e&&l();break;case "number":c.im=0;c.re=a;break;default:l()}this.re=c.re;this.im=c.im}var g=Math.cosh||function(a){return 1E-9>Math.abs(a)?1-a:.5*(Math.exp(a)+Math.exp(-a))},k=Math.sinh||function(a){return 1E-9>Math.abs(a)?
a:.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){a=new d(a,b);return this.isInfinite()&&a.isInfinite()?d.NAN:this.isInfinite()||a.isInfinite()?d.INFINITY:new d(this.re+a.re,this.im+a.im)},sub:function(a,b){a=new d(a,b);return this.isInfinite()&&a.isInfinite()?d.NAN:this.isInfinite()||a.isInfinite()?d.INFINITY:new d(this.re-a.re,this.im-a.im)},mul:function(a,b){a=new d(a,b);return this.isInfinite()&&a.isZero()||
this.isZero()&&a.isInfinite()?d.NAN:this.isInfinite()||a.isInfinite()?d.INFINITY:0===a.im&&0===this.im?new d(this.re*a.re,0):new d(this.re*a.re-this.im*a.im,this.re*a.im+this.im*a.re)},div:function(a,b){var c=new d(a,b);if(this.isZero()&&c.isZero()||this.isInfinite()&&c.isInfinite())return d.NAN;if(this.isInfinite()||c.isZero())return d.INFINITY;if(this.isZero()||c.isInfinite())return d.ZERO;a=this.re;b=this.im;var e=c.re,f=c.im;if(0===f)return new d(a/e,b/e);if(Math.abs(e)<Math.abs(f))return c=e/
f,e=e*c+f,new d((a*c+b)/e,(b*c-a)/e);c=f/e;e=f*c+e;return new d((a+b*c)/e,(b-a*c)/e)},pow:function(a,b){var c=new d(a,b);a=this.re;b=this.im;if(c.isZero())return d.ONE;if(0===c.im){if(0===b&&0<a)return new d(Math.pow(a,c.re),0);if(0===a)switch((c.re%4+4)%4){case 0:return new d(Math.pow(b,c.re),0);case 1:return new d(0,Math.pow(b,c.re));case 2:return new d(-Math.pow(b,c.re),0);case 3:return new d(0,-Math.pow(b,c.re))}}if(0===a&&0===b&&0<c.re&&0<=c.im)return d.ZERO;var e=Math.atan2(b,a);b=m(a,b);a=
Math.exp(c.re*b-c.im*e);b=c.im*b+c.re*e;return new d(a*Math.cos(b),a*Math.sin(b))},sqrt:function(){var a=this.re,b=this.im,c=this.abs();if(0<=a){if(0===b)return new d(Math.sqrt(a),0);var e=.5*Math.sqrt(2*(c+a))}else e=Math.abs(b)/Math.sqrt(2*(c-a));a=0>=a?.5*Math.sqrt(2*(c-a)):Math.abs(b)/Math.sqrt(2*(c+a));return new d(e,0>b?-a:a)},exp:function(){var a=Math.exp(this.re);return new d(a*Math.cos(this.im),a*Math.sin(this.im))},expm1:function(){var a=this.re,b=this.im,c=Math.expm1(a)*Math.cos(b);var e=
Math.PI/4;-e>b||b>e?e=Math.cos(b)-1:(e=b*b,e*=e*(e*(e*(e*(e*(e*(e/20922789888E3-1/87178291200)+1/479001600)-1/3628800)+1/40320)-1/720)+1/24)-.5);return new d(c+e,Math.exp(a)*Math.sin(b))},log:function(){var a=this.re,b=this.im;return new d(m(a,b),Math.atan2(b,a))},abs:function(){var a=this.re;var b=this.im,c=Math.abs(a),e=Math.abs(b);3E3>c&&3E3>e?a=Math.sqrt(c*c+e*e):(c<e?(c=e,e=a/b):e=b/a,a=c*Math.sqrt(1+e*e));return a},arg:function(){return Math.atan2(this.im,this.re)},sin:function(){var a=this.re,
b=this.im;return new d(Math.sin(a)*g(b),Math.cos(a)*k(b))},cos:function(){var a=this.re,b=this.im;return new d(Math.cos(a)*g(b),-Math.sin(a)*k(b))},tan:function(){var a=2*this.re,b=2*this.im,c=Math.cos(a)+g(b);return new d(Math.sin(a)/c,k(b)/c)},cot:function(){var a=2*this.re,b=2*this.im,c=Math.cos(a)-g(b);return new d(-Math.sin(a)/c,k(b)/c)},sec:function(){var a=this.re,b=this.im,c=.5*g(2*b)+.5*Math.cos(2*a);return new d(Math.cos(a)*g(b)/c,Math.sin(a)*k(b)/c)},csc:function(){var a=this.re,b=this.im,
c=.5*g(2*b)-.5*Math.cos(2*a);return new d(Math.sin(a)*g(b)/c,-Math.cos(a)*k(b)/c)},asin:function(){var a=this.re,b=this.im,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(k(a)*Math.cos(b),g(a)*Math.sin(b))},cosh:function(){var a=this.re,b=this.im;return new d(g(a)*Math.cos(b),k(a)*Math.sin(b))},tanh:function(){var a=2*this.re,b=2*this.im,c=g(a)+Math.cos(b);return new d(k(a)/c,Math.sin(b)/c)},coth:function(){var a=2*this.re,b=2*this.im,c=g(a)-Math.cos(b);return new d(k(a)/c,-Math.sin(b)/c)},csch:function(){var a=this.re,b=this.im,
c=Math.cos(2*b)-g(2*a);return new d(-2*k(a)*Math.cos(b)/c,2*g(a)*Math.sin(b)/c)},sech:function(){var a=this.re,b=this.im,c=Math.cos(2*b)+g(2*a);return new d(2*g(a)*Math.cos(b)/c,-2*k(a)*Math.sin(b)/c)},asinh:function(){var a=this.im;this.im=-this.re;this.re=a;var b=this.asin();this.re=-this.im;this.im=a;a=b.re;b.re=-b.im;b.im=a;return b},acosh:function(){var a=this.acos();if(0>=a.im){var b=a.re;a.re=-a.im;a.im=b}else b=a.im,a.im=-a.re,a.re=b;return a},atanh:function(){var a=this.re,b=this.im,c=1<
a&&0===b,e=1-a,f=1+a,h=e*e+b*b;a=0!==h?new d((f*e-b*b)/h,(b*e+f*b)/h):new d(-1!==a?a/0:0,0!==b?b/0:0);b=a.re;a.re=m(a.re,a.im)/2;a.im=Math.atan2(a.im,b)/2;c&&(a.im=-a.im);return a},acoth:function(){var a=this.re,b=this.im;if(0===a&&0===b)return new d(0,Math.PI/2);var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).atanh():(new d(0!==a?a/0:0,0!==b?-b/0:0)).atanh()},acsch:function(){var a=this.re,b=this.im;if(0===b)return new d(0!==a?Math.log(a+Math.sqrt(a*a+1)):Infinity,0);var c=a*a+b*b;return 0!==c?(new d(a/
c,-b/c)).asinh():(new d(0!==a?a/0:0,0!==b?-b/0:0)).asinh()},asech:function(){var a=this.re,b=this.im;if(this.isZero())return d.INFINITY;var c=a*a+b*b;return 0!==c?(new d(a/c,-b/c)).acosh():(new d(0!==a?a/0:0,0!==b?-b/0:0)).acosh()},inverse:function(){if(this.isZero())return d.INFINITY;if(this.isInfinite())return d.ZERO;var a=this.re,b=this.im,c=a*a+b*b;return new d(a/c,-b/c)},conjugate:function(){return new d(this.re,-this.im)},neg:function(){return new d(-this.re,-this.im)},ceil:function(a){a=Math.pow(10,
a||0);return new d(Math.ceil(this.re*a)/a,Math.ceil(this.im*a)/a)},floor:function(a){a=Math.pow(10,a||0);return new d(Math.floor(this.re*a)/a,Math.floor(this.im*a)/a)},round:function(a){a=Math.pow(10,a||0);return new d(Math.round(this.re*a)/a,Math.round(this.im*a)/a)},equals:function(a,b){a=new d(a,b);return Math.abs(a.re-this.re)<=d.EPSILON&&Math.abs(a.im-this.im)<=d.EPSILON},clone:function(){return new d(this.re,this.im)},toString:function(){var a=this.re,b=this.im,c="";if(this.isNaN())return"NaN";
if(this.isInfinite())return"Infinity";Math.abs(a)<d.EPSILON&&(a=0);Math.abs(b)<d.EPSILON&&(b=0);if(0===b)return c+a;0!==a?(c=c+a+" ",0>b?(b=-b,c+="-"):c+="+",c+=" "):0>b&&(b=-b,c+="-");1!==b&&(c+=b);return c+"i"},toVector:function(){return[this.re,this.im]},valueOf:function(){return 0===this.im?this.re:null},isNaN:function(){return isNaN(this.re)||isNaN(this.im)},isZero:function(){return 0===this.im&&0===this.re},isFinite:function(){return isFinite(this.re)&&isFinite(this.im)},isInfinite:function(){return!(this.isNaN()||
this.isFinite())}};d.ZERO=new d(0,0);d.ONE=new d(1,0);d.I=new d(0,1);d.PI=new d(Math.PI,0);d.E=new d(Math.E,0);d.INFINITY=new d(Infinity,Infinity);d.NAN=new d(NaN,NaN);d.EPSILON=1E-15;"function"===typeof define&&define.amd?define([],function(){return d}):"object"===typeof exports?(Object.defineProperty(d,"__esModule",{value:!0}),d["default"]=d,d.Complex=d,module.exports=d):n.Complex=d})(this);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,33 @@
/*
* A gamma function implementation based on Lanczos Approximation
* https://en.wikipedia.org/wiki/Lanczos_approximation
*/
var Complex = require('complex.js');
var P = [
Complex(0.99999999999980993),
Complex(676.5203681218851), Complex(-1259.1392167224028), Complex(771.32342877765313),
Complex(-176.61502916214059), Complex(12.507343278686905), Complex(-0.13857109526572012),
Complex(9.9843695780195716e-6), Complex(1.5056327351493116e-7)
];
var SQRT2PI = Complex(Math.sqrt(2 * Math.PI));
function gamma(z) {
z = z.sub(1);
var x = P[0];
var t = z.add(7.5);
for (var i = 1; i < P.length; i++) {
x = x.add(P[i].div(z.add(i)));
}
return SQRT2PI.mul(t.pow(z.add(0.5))).mul(t.neg().exp()).mul(x);
}
var fac = 1;
for (var i = 1; i <= 10; i++) {
console.log(fac, gamma(Complex(i)));
fac *= i;
}

View File

@@ -0,0 +1,60 @@
{
"name": "complex.js",
"title": "Complex.js",
"version": "2.3.0",
"homepage": "https://raw.org/article/complex-numbers-in-javascript/",
"bugs": "https://github.com/rawify/Complex.js/issues",
"description": "A complex numbers library",
"keywords": [
"complex numbers",
"math",
"complex",
"number",
"calculus",
"parser",
"arithmetic"
],
"private": false,
"main": "./dist/complex.js",
"module": "./dist/complex.mjs",
"types": "./complex.d.ts",
"browser": "./dist/complex.min.js",
"unpkg": "./dist/complex.min.js",
"readmeFilename": "README.md",
"exports": {
".": {
"types": "./complex.d.ts",
"require": "./dist/complex.js",
"import": "./dist/complex.mjs"
}
},
"repository": {
"type": "git",
"url": "git@github.com:rawify/Complex.js.git"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/rawify"
},
"author": {
"name": "Robert Eisele",
"email": "robert@raw.org",
"url": "https://raw.org/"
},
"license": "MIT",
"engines": {
"node": "*"
},
"directories": {
"example": "examples",
"test": "tests"
},
"scripts": {
"build": "crude-build Complex",
"test": "mocha tests/*.js"
},
"devDependencies": {
"crude-build": "^0.1.1",
"mocha": "*"
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff