ziko 0.53.0 → 0.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ziko.cjs +998 -837
- package/dist/ziko.js +5704 -5449
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +1052 -805
- package/package.json +1 -1
- package/src/math/complex/index.js +96 -82
- package/src/math/functions/arithmetic/index.js +82 -0
- package/src/math/functions/index.js +40 -153
- package/src/math/{mapfun → functions/mapfun}/index.js +15 -1
- package/src/math/functions/{primitives → nested}/index.js +34 -21
- package/src/math/functions/signal/index.js +104 -0
- package/src/math/functions/stats/index.js +49 -0
- package/src/math/functions/utils/index.js +105 -0
- package/src/math/matrix/helpers/det.js +1 -1
- package/src/math/matrix/matrix.js +9 -14
- package/src/math/signal/functions.js +9 -69
- package/src/math/statistics/functions/index.js +32 -32
- package/src/math/statistics/index.js +4 -4
- package/src/math/stats/accum/index.js +39 -0
- package/src/math/stats/average/index.js +75 -0
- package/src/math/stats/index.js +14 -0
- package/src/math/stats/percentile/index.js +18 -0
- package/src/math/stats/rolling/index.js +34 -0
- package/src/math/stats/variability/index.js +37 -0
- package/src/math/utils/arithmetic.js +1 -1
- package/src/math/utils/index.js +39 -39
- package/src/time/animation/index.js +1 -1
- package/types/math/complex/index.d.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziko",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.1",
|
|
4
4
|
"description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"front-end",
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import{
|
|
2
|
-
|
|
3
|
-
sin,
|
|
4
|
-
tan,
|
|
5
|
-
pow,
|
|
6
|
-
floor,
|
|
7
|
-
hypot,
|
|
8
|
-
cosh,
|
|
9
|
-
sinh,
|
|
10
|
-
sqrtn,
|
|
11
|
-
atan2,
|
|
12
|
-
sqrt,
|
|
13
|
-
ln
|
|
14
|
-
}from "../functions/index.js"
|
|
15
|
-
import {sum,prod,deg2rad} from "../utils/index.js";
|
|
1
|
+
// import {sum,prod,deg2rad} from "../utils/index.js";
|
|
2
|
+
// Should avoid CD
|
|
16
3
|
class Complex{
|
|
17
4
|
constructor(a = 0, b = 0) {
|
|
18
5
|
if(a instanceof Complex){
|
|
@@ -21,33 +8,33 @@ class Complex{
|
|
|
21
8
|
}
|
|
22
9
|
else if(typeof(a)==="object"){
|
|
23
10
|
if(("a" in a && "b" in a)){
|
|
24
|
-
this.a=a.a;
|
|
25
|
-
this.b=a.b;
|
|
11
|
+
this.a = a.a;
|
|
12
|
+
this.b = a.b;
|
|
26
13
|
}
|
|
27
14
|
else if(("a" in a && "z" in a)){
|
|
28
|
-
this.a=a.a;
|
|
29
|
-
this.b=sqrt((a.z**2)-(a.a**2));
|
|
15
|
+
this.a = a.a;
|
|
16
|
+
this.b = Math.sqrt((a.z**2)-(a.a**2));
|
|
30
17
|
}
|
|
31
18
|
else if(("a" in a && "phi" in a)){
|
|
32
|
-
this.a=a.a;
|
|
33
|
-
this.b=a.a*tan(a.phi);
|
|
19
|
+
this.a = a.a;
|
|
20
|
+
this.b = a.a * Math.tan(a.phi);
|
|
34
21
|
}
|
|
35
22
|
else if(("b" in a && "z" in a)){
|
|
36
|
-
this.b=a.b;
|
|
37
|
-
this.a=sqrt((a.z**2)-(a.b**2));
|
|
23
|
+
this.b = a.b;
|
|
24
|
+
this.a = Math.sqrt((a.z**2)-(a.b**2));
|
|
38
25
|
}
|
|
39
26
|
else if(("b" in a && "phi" in a)){
|
|
40
|
-
this.b=b;
|
|
41
|
-
this.a=a.b/tan(a.phi);
|
|
27
|
+
this.b = b;
|
|
28
|
+
this.a = a.b / Math.tan(a.phi);
|
|
42
29
|
}
|
|
43
30
|
else if(("z" in a && "phi" in a)){
|
|
44
|
-
this.a = +a.z*cos(a.phi).toFixed(15);
|
|
45
|
-
this.b = +a.z*sin(a.phi).toFixed(15);
|
|
31
|
+
this.a = + a.z * Math.cos(a.phi).toFixed(15);
|
|
32
|
+
this.b = + a.z * Math.sin(a.phi).toFixed(15);
|
|
46
33
|
}
|
|
47
34
|
}
|
|
48
|
-
else if(typeof(a)==="number"&&typeof(b)==="number"){
|
|
49
|
-
this.a = +a.toFixed(32);
|
|
50
|
-
this.b = +b.toFixed(32);
|
|
35
|
+
else if(typeof(a)==="number" && typeof(b)==="number"){
|
|
36
|
+
this.a = + a.toFixed(32);
|
|
37
|
+
this.b = + b.toFixed(32);
|
|
51
38
|
}
|
|
52
39
|
}
|
|
53
40
|
get __mapfun__(){
|
|
@@ -68,15 +55,24 @@ class Complex{
|
|
|
68
55
|
: (str = `-${Math.abs(this.b)}*i`);
|
|
69
56
|
return str;
|
|
70
57
|
}
|
|
71
|
-
|
|
58
|
+
toFixed(n){
|
|
59
|
+
this.a = + this.a.toFixed(n);
|
|
60
|
+
this.b = + this.b.toFixed(n);
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
toPrecision(n){
|
|
64
|
+
this.a = + this.a.toPrecision(n);
|
|
65
|
+
this.b = + this.b.toPrecision(n);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
72
68
|
clone() {
|
|
73
69
|
return new Complex(this.a, this.b);
|
|
74
70
|
}
|
|
75
71
|
get z(){
|
|
76
|
-
return hypot(this.a,this.b);
|
|
72
|
+
return Math.hypot(this.a,this.b);
|
|
77
73
|
}
|
|
78
74
|
get phi(){
|
|
79
|
-
return atan2(this.b , this.a);
|
|
75
|
+
return Math.atan2(this.b , this.a);
|
|
80
76
|
}
|
|
81
77
|
static Zero() {
|
|
82
78
|
return new Complex(0, 0);
|
|
@@ -85,55 +81,66 @@ class Complex{
|
|
|
85
81
|
return new Complex(this.a, -this.b);
|
|
86
82
|
}
|
|
87
83
|
get inv() {
|
|
88
|
-
return new Complex(
|
|
84
|
+
return new Complex(
|
|
85
|
+
this.a / Math.hypot(this.a, this.b),
|
|
86
|
+
-this.b / Math.hypot(this.a, this.b)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
add(...c) {
|
|
90
|
+
for (let i = 0; i < c.length; i++) {
|
|
91
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
92
|
+
this.a += c[i].a;
|
|
93
|
+
this.b += c[i].b;
|
|
94
|
+
}
|
|
95
|
+
return this;
|
|
89
96
|
}
|
|
90
|
-
|
|
91
|
-
for (let i = 0; i <
|
|
92
|
-
if (typeof
|
|
97
|
+
sub(...c) {
|
|
98
|
+
for (let i = 0; i < c.length; i++) {
|
|
99
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
100
|
+
this.a -= c[i].a;
|
|
101
|
+
this.b -= c[i].b;
|
|
93
102
|
}
|
|
94
|
-
let re = z.map((n) => n.a);
|
|
95
|
-
let im = z.map((n) => n.b);
|
|
96
|
-
this.a+=+sum(...re).toFixed(15);
|
|
97
|
-
this.b+=+sum(...im).toFixed(15);
|
|
98
103
|
return this;
|
|
99
104
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
mul(...c){
|
|
106
|
+
let {z, phi} = this;
|
|
107
|
+
for (let i = 0; i < c.length; i++) {
|
|
108
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
109
|
+
z *= c[i].z;
|
|
110
|
+
phi += c[i].phi;
|
|
103
111
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.a-=+sum(...re).toFixed(15);
|
|
107
|
-
this.b-=+sum(...im).toFixed(15);
|
|
112
|
+
this.a = z * Math.cos(phi)
|
|
113
|
+
this.b = z * Math.sin(phi)
|
|
108
114
|
return this;
|
|
109
115
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
div(...c){
|
|
117
|
+
let {z, phi} = this;
|
|
118
|
+
for (let i = 0; i < c.length; i++) {
|
|
119
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
120
|
+
z /= c[i].z;
|
|
121
|
+
phi -= c[i].phi;
|
|
113
122
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this.a=+(Z*cos(phi).toFixed(15)).toFixed(14);
|
|
117
|
-
this.b=+(Z*sin(phi).toFixed(15)).toFixed(14);
|
|
123
|
+
this.a = z*Math.cos(phi)
|
|
124
|
+
this.b = z*Math.sin(phi)
|
|
118
125
|
return this;
|
|
119
126
|
}
|
|
120
|
-
|
|
121
|
-
for (let i = 0; i <
|
|
122
|
-
if (typeof
|
|
127
|
+
modulo(...c) {
|
|
128
|
+
for (let i = 0; i < c.length; i++) {
|
|
129
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
130
|
+
this.a %= c[i].a;
|
|
131
|
+
this.b %= c[i].b;
|
|
123
132
|
}
|
|
124
|
-
let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
|
|
125
|
-
let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
|
|
126
|
-
this.a=+(Z*cos(phi).toFixed(15)).toFixed(15);
|
|
127
|
-
this.b=+(Z*sin(phi).toFixed(15)).toFixed(15);
|
|
128
133
|
return this;
|
|
129
134
|
}
|
|
130
|
-
pow(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
pow(...c){
|
|
136
|
+
let {z, phi} = this;
|
|
137
|
+
for (let i = 0; i < c.length; i++) {
|
|
138
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
139
|
+
z *= Math.exp(c[i].a * Math.log(z) - c[i].b * phi);
|
|
140
|
+
phi += c[i].b * Math.log(z) + c[i].a * phi;
|
|
136
141
|
}
|
|
142
|
+
this.a = z * Math.cos(phi)
|
|
143
|
+
this.b = z * Math.sin(phi)
|
|
137
144
|
return this;
|
|
138
145
|
}
|
|
139
146
|
static fromExpo(z, phi) {
|
|
@@ -157,30 +164,37 @@ class Complex{
|
|
|
157
164
|
static div(c,...z) {
|
|
158
165
|
return c.clone().div(...z);
|
|
159
166
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
static xpowZ(x){
|
|
164
|
-
return complex((x**this.a)*cos(this.b*ln(x)),(x**this.a)*sin(this.b*ln(x)));
|
|
165
|
-
}
|
|
166
|
-
sqrtn(n=2){
|
|
167
|
-
return complex(sqrtn(this.z,n)*cos(this.phi/n),sqrtn(this.z,n)*sin(this.phi/n));
|
|
167
|
+
|
|
168
|
+
nthr(n=2){
|
|
169
|
+
return complex({z: this.z ** (1/n), phi: this.phi / n});
|
|
168
170
|
}
|
|
169
171
|
get sqrt(){
|
|
170
|
-
return this.
|
|
172
|
+
return this.nrth(2);
|
|
173
|
+
}
|
|
174
|
+
get cbrt(){
|
|
175
|
+
return this.nrth(3);
|
|
171
176
|
}
|
|
172
177
|
get log(){
|
|
173
|
-
return complex(this.z,this.phi);
|
|
178
|
+
return complex(this.z, this.phi);
|
|
174
179
|
}
|
|
175
180
|
get cos(){
|
|
176
|
-
return complex(
|
|
181
|
+
return complex(
|
|
182
|
+
Math.cos(this.a) * Math.cosh(this.b),
|
|
183
|
+
Math.sin(this.a) * Math.sinh(this.b)
|
|
184
|
+
)
|
|
177
185
|
}
|
|
178
186
|
get sin(){
|
|
179
|
-
return complex(
|
|
187
|
+
return complex(
|
|
188
|
+
Math.sin(this.a) * Math.cosh(this.b),
|
|
189
|
+
Math.cos(this.a) * Math.sinh(this.b)
|
|
190
|
+
)
|
|
180
191
|
}
|
|
181
192
|
get tan(){
|
|
182
|
-
const
|
|
183
|
-
return complex(
|
|
193
|
+
const D=cos(this.a*2)+cosh(this.b*2);
|
|
194
|
+
return complex(
|
|
195
|
+
Math.sin(2 * this.a) / D,
|
|
196
|
+
Math.sinh(2 * this.b) / D
|
|
197
|
+
);
|
|
184
198
|
}
|
|
185
199
|
}
|
|
186
200
|
const complex=(a,b)=>{
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const _add = (x, y) =>{
|
|
2
|
+
if(typeof x === 'number'){
|
|
3
|
+
if(typeof y === 'number') return x + y;
|
|
4
|
+
if(y.isComplex?.()) {
|
|
5
|
+
return y.clone().add(x);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
if(x.isComplex?.()){
|
|
9
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().add(y);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const _sub = (x, y) =>{
|
|
14
|
+
if(typeof x === 'number'){
|
|
15
|
+
if(typeof y === 'number') return x - y;
|
|
16
|
+
if(y.isComplex?.()) return new y.constructor(x - y.a, y.b);
|
|
17
|
+
}
|
|
18
|
+
if(x.isComplex?.()){
|
|
19
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().sub(y);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const _mul = (x, y) =>{
|
|
24
|
+
if(typeof x === 'number'){
|
|
25
|
+
if(typeof y === 'number') return x * y;
|
|
26
|
+
if(y.isComplex?.()) return y.clone().mul(x);
|
|
27
|
+
}
|
|
28
|
+
if(x.isComplex?.()){
|
|
29
|
+
if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const _div = (x, y) =>{
|
|
34
|
+
if(typeof x === 'number'){
|
|
35
|
+
if(typeof y === 'number') return x / y;
|
|
36
|
+
if(y.isComplex?.()) return new y.constructor(x, 0).div(y)
|
|
37
|
+
}
|
|
38
|
+
if(x.isComplex?.()){
|
|
39
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().mul(y);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const _modulo = (x, y) =>{
|
|
44
|
+
if(typeof x === 'number'){
|
|
45
|
+
if(typeof y === 'number') return x % y;
|
|
46
|
+
if(y.isComplex?.()) return new y.constructor(x, 0).modulo(y)
|
|
47
|
+
}
|
|
48
|
+
if(x.isComplex?.()){
|
|
49
|
+
if(typeof y === 'number' || y.isComplex?.()) return new x.clone().modulo(y);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const add=(a,...b)=>{
|
|
54
|
+
let res = a;
|
|
55
|
+
for(let i=0; i<b.length; i++)
|
|
56
|
+
res = _add(res, b[i])
|
|
57
|
+
return res;
|
|
58
|
+
}
|
|
59
|
+
export const sub=(a,...b)=>{
|
|
60
|
+
let res = a;
|
|
61
|
+
for(let i=0; i<b.length; i++)
|
|
62
|
+
res = _sub(res, b[i])
|
|
63
|
+
return res;
|
|
64
|
+
}
|
|
65
|
+
export const mul=(a,...b)=>{
|
|
66
|
+
let res = a;
|
|
67
|
+
for(let i=0; i<b.length; i++)
|
|
68
|
+
res = _mul(res, b[i])
|
|
69
|
+
return res;
|
|
70
|
+
}
|
|
71
|
+
export const div=(a,...b)=>{
|
|
72
|
+
let res = a;
|
|
73
|
+
for(let i=0; i<b.length; i++)
|
|
74
|
+
res = _div(res, b[i])
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
77
|
+
export const modulo=(a,...b)=>{
|
|
78
|
+
let res = a;
|
|
79
|
+
for(let i=0; i<b.length; i++)
|
|
80
|
+
res = _modulo(res, b[i])
|
|
81
|
+
return res;
|
|
82
|
+
}
|
|
@@ -1,155 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export * from './mapfun/index.js'
|
|
2
|
+
export * from './nested/index.js'
|
|
3
|
+
export * from './arithmetic/index.js'
|
|
4
|
+
export * from './utils/index.js'
|
|
5
|
+
export * from './stats/index.js'
|
|
6
|
+
// export const atan2=(x,y,rad=true)=>{
|
|
7
|
+
// if(typeof x === "number"){
|
|
8
|
+
// if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
|
|
9
|
+
// else return mapfun(a=>atan2(x,a,rad),...y);
|
|
10
|
+
// }
|
|
11
|
+
// // else if(x.isComplex?.()){
|
|
12
|
+
// // if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
|
|
13
|
+
// // else return mapfun(a=>pow(x,a),...n);
|
|
14
|
+
// // }
|
|
15
|
+
// else if(x instanceof Array){
|
|
16
|
+
// if(typeof y === "number") return mapfun(a=>atan2(a,y,rad),...x);
|
|
17
|
+
// else if(y instanceof Array){
|
|
18
|
+
// const Y=[];
|
|
19
|
+
// for(let i=0;i<x.length;i++){
|
|
20
|
+
// Y.push(mapfun(a=>pow(x[i],a,rad),...y))
|
|
21
|
+
// }
|
|
22
|
+
// return Y;
|
|
23
|
+
// }
|
|
24
|
+
// }
|
|
25
|
+
// }
|
|
26
|
+
// export const fact=(...x)=>mapfun(n=> {
|
|
27
|
+
// let i,
|
|
28
|
+
// y = 1;
|
|
29
|
+
// if (n == 0) y = 1;
|
|
30
|
+
// else if (n > 0) for (i = 1; i <= n; i++) y *= i;
|
|
31
|
+
// else y = NaN;
|
|
32
|
+
// return y;
|
|
33
|
+
// },...x);
|
|
8
34
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
else if(x.isComplex?.()){
|
|
18
|
-
if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
|
|
19
|
-
else if(n.isComplex?.())return x.constructor.fromExpo(
|
|
20
|
-
x.z**n.a*e(-x.phi*n.b),
|
|
21
|
-
ln(x.z)*n.b+n.a*x.phi
|
|
22
|
-
)
|
|
23
|
-
else return mapfun(a=>pow(x,a),...n);
|
|
24
|
-
}
|
|
25
|
-
else if(x instanceof Array){
|
|
26
|
-
if(typeof n === "number") return mapfun(a=>pow(a,n),...x);
|
|
27
|
-
else if(n instanceof Array){
|
|
28
|
-
const Y=[];
|
|
29
|
-
for(let i=0;i<x.length;i++){
|
|
30
|
-
Y.push(mapfun(a=>pow(x[i],a),...n))
|
|
31
|
-
}
|
|
32
|
-
return Y;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const sqrtn=(x,n)=>{
|
|
37
|
-
if(typeof x === "number"){
|
|
38
|
-
if(typeof n === "number")return Math.pow(x,1/n);
|
|
39
|
-
else return mapfun(a=>sqrtn(x,a),...n);
|
|
40
|
-
}
|
|
41
|
-
else if(x.isComplex?.()){
|
|
42
|
-
if(typeof n === "number")return x.constructor.fromExpo(sqrtn(x.z,n),x.phi/n);
|
|
43
|
-
else return mapfun(a=>sqrtn(x,a),...n);
|
|
44
|
-
}
|
|
45
|
-
else if(x instanceof Array){
|
|
46
|
-
if(typeof n === "number") return mapfun(a=>sqrtn(a,n),...x);
|
|
47
|
-
else if(n instanceof Array){
|
|
48
|
-
const Y=[];
|
|
49
|
-
for(let i=0;i<x.length;i++){
|
|
50
|
-
Y.push(mapfun(a=>sqrtn(x[i],a),...n))
|
|
51
|
-
}
|
|
52
|
-
return Y;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const e=(...x) => mapfun(Math.exp,...x);
|
|
57
|
-
const ln=(...x) => mapfun(Math.log,...x);
|
|
58
|
-
const cos=(...x) => mapfun(Fixed.cos,...x);
|
|
59
|
-
const sin=(...x) => mapfun(Fixed.sin,...x);
|
|
60
|
-
const tan=(...x) => mapfun(Fixed.tan,...x);
|
|
61
|
-
const sec=(...x) => mapfun(Fixed.sec,...x);
|
|
62
|
-
const sinc=(...x) => mapfun(Fixed.sinc,...x)
|
|
63
|
-
const csc=(...x) => mapfun(Fixed.csc,...x);
|
|
64
|
-
const cot=(...x) => mapfun(Fixed.cot,...x);
|
|
65
|
-
const acos=(...x) => mapfun(Fixed.acos,...x);
|
|
66
|
-
const asin=(...x) => mapfun(Fixed.asin,...x);
|
|
67
|
-
const atan=(...x) => mapfun(Fixed.atan,...x);
|
|
68
|
-
const acot=(...x) => mapfun(Fixed.acot,...x);
|
|
69
|
-
const cosh=(...x) => mapfun(Fixed.cosh,...x);
|
|
70
|
-
const sinh=(...x) => mapfun(Fixed.sinh,...x);
|
|
71
|
-
const tanh=(...x) => mapfun(Fixed.tanh,...x);
|
|
72
|
-
const coth=(...x) => mapfun(Fixed.coth,...x);
|
|
73
|
-
const acosh=(...x) => mapfun(Fixed.acosh,...x);
|
|
74
|
-
const asinh=(...x) => mapfun(Fixed.asinh,...x);
|
|
75
|
-
const atanh=(...x) => mapfun(Fixed.atanh,...x);
|
|
76
|
-
const ceil=(...x) => mapfun(Math.ceil,...x);
|
|
77
|
-
const floor=(...x) => mapfun(Math.floor,...x);
|
|
78
|
-
const round=(...x) => mapfun(Math.round,...x);
|
|
79
|
-
const atan2=(x,y,rad=true)=>{
|
|
80
|
-
if(typeof x === "number"){
|
|
81
|
-
if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
|
|
82
|
-
else return mapfun(a=>atan2(x,a,rad),...y);
|
|
83
|
-
}
|
|
84
|
-
// else if(x.isComplex?.()){
|
|
85
|
-
// if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
|
|
86
|
-
// else return mapfun(a=>pow(x,a),...n);
|
|
87
|
-
// }
|
|
88
|
-
else if(x instanceof Array){
|
|
89
|
-
if(typeof y === "number") return mapfun(a=>atan2(a,y,rad),...x);
|
|
90
|
-
else if(y instanceof Array){
|
|
91
|
-
const Y=[];
|
|
92
|
-
for(let i=0;i<x.length;i++){
|
|
93
|
-
Y.push(mapfun(a=>pow(x[i],a,rad),...y))
|
|
94
|
-
}
|
|
95
|
-
return Y;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const fact=(...x)=>mapfun(n=> {
|
|
100
|
-
let i,
|
|
101
|
-
y = 1;
|
|
102
|
-
if (n == 0) y = 1;
|
|
103
|
-
else if (n > 0) for (i = 1; i <= n; i++) y *= i;
|
|
104
|
-
else y = NaN;
|
|
105
|
-
return y;
|
|
106
|
-
},...x);
|
|
107
|
-
const sign=(...x)=>mapfun(Math.sign,...x);
|
|
35
|
+
// export const hypot=(...x)=>{
|
|
36
|
+
// if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
|
|
37
|
+
// if(x.every(n=>n instanceof Array))return mapfun(
|
|
38
|
+
// Math.hypot,
|
|
39
|
+
// ...x
|
|
40
|
+
// )
|
|
41
|
+
// }
|
|
108
42
|
|
|
109
|
-
const sig=(...x)=>mapfun(n=>1/(1+e(-n)),...x);
|
|
110
|
-
|
|
111
|
-
const hypot=(...x)=>{
|
|
112
|
-
if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
|
|
113
|
-
if(x.every(n=>n instanceof Array))return mapfun(
|
|
114
|
-
Math.hypot,
|
|
115
|
-
...x
|
|
116
|
-
)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export{
|
|
120
|
-
cos,
|
|
121
|
-
sin,
|
|
122
|
-
tan,
|
|
123
|
-
sinc,
|
|
124
|
-
cot,
|
|
125
|
-
sec,
|
|
126
|
-
csc,
|
|
127
|
-
abs,
|
|
128
|
-
sqrt,
|
|
129
|
-
pow,
|
|
130
|
-
sqrtn,
|
|
131
|
-
e,
|
|
132
|
-
ln,
|
|
133
|
-
acos,
|
|
134
|
-
asin,
|
|
135
|
-
atan,
|
|
136
|
-
acot,
|
|
137
|
-
cosh,
|
|
138
|
-
sinh,
|
|
139
|
-
tanh,
|
|
140
|
-
coth,
|
|
141
|
-
acosh,
|
|
142
|
-
asinh,
|
|
143
|
-
atanh,
|
|
144
|
-
min,
|
|
145
|
-
max,
|
|
146
|
-
sign,
|
|
147
|
-
floor,
|
|
148
|
-
ceil,
|
|
149
|
-
round,
|
|
150
|
-
fact,
|
|
151
|
-
hypot,
|
|
152
|
-
sig,
|
|
153
|
-
atan2
|
|
154
|
-
};
|
|
155
|
-
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { is_primitive } from "
|
|
1
|
+
import { is_primitive } from "../../../helpers/checkers/index.js";
|
|
2
2
|
export const mapfun=(fun,...X)=>{
|
|
3
3
|
const Y=X.map(x=>{
|
|
4
4
|
if(is_primitive(x) || x?.__mapfun__) return fun(x)
|
|
@@ -17,3 +17,17 @@ export const mapfun=(fun,...X)=>{
|
|
|
17
17
|
});
|
|
18
18
|
return Y.length==1? Y[0]: Y;
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
export const apply_fun = (x, fn) => {
|
|
22
|
+
if (x.isComplex?.()) return new x.constructor(
|
|
23
|
+
fn(x.a),
|
|
24
|
+
fn(x.b)
|
|
25
|
+
)
|
|
26
|
+
if (x.isMatrix?.()) return new x.constructor(
|
|
27
|
+
x.rows,
|
|
28
|
+
x.cols,
|
|
29
|
+
x.arr.flat(1).map(fn)
|
|
30
|
+
)
|
|
31
|
+
if (x instanceof Array) mapfun(fn, ...x)
|
|
32
|
+
return fn(x)
|
|
33
|
+
}
|