numz 0.8.0 → 0.10.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "numz",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "scientific computing with zikojs",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,9 +26,9 @@
26
26
  "@rollup/plugin-node-resolve": "^16.0.3",
27
27
  "@rollup/plugin-terser": "^1.0.0",
28
28
  "cross-env": "^10.1.0",
29
- "rollup": "^4.63.0"
29
+ "rollup": "^4.63.1"
30
30
  },
31
31
  "dependencies": {
32
- "ziko": "^1.10.0"
32
+ "ziko": "^2.0.0-alpha.0"
33
33
  }
34
34
  }
@@ -0,0 +1,34 @@
1
+
2
+
3
+ export const bitmasks = (n) => {
4
+ const res = [];
5
+ for (let i = 0; i < 1 << n; i++) {
6
+ const mask = [];
7
+ for (let j = 0; j < n; j++) mask.push((i >> j) & 1);
8
+ res.push(mask);
9
+ }
10
+ return res;
11
+ };
12
+ export const subsets_by_mask = (arr) => {
13
+ const n = arr.length,
14
+ res = [];
15
+ for (let i = 0; i < 1 << n; i++) {
16
+ const subset = [];
17
+ for (let j = 0; j < n; j++) if ((i >> j) & 1) subset.push(arr[j]);
18
+ res.push(subset);
19
+ }
20
+ return res;
21
+ };
22
+ export const gray_code = (n) => {
23
+ if (n === 0) return [0];
24
+ const prev = gray_code(n - 1);
25
+ return [...prev, ...prev.map((x) => x | (1 << (n - 1)))];
26
+ };
27
+ export const hamming_weight = (x) => {
28
+ let count = 0;
29
+ while (x) {
30
+ x &= x - 1;
31
+ count++;
32
+ }
33
+ return count;
34
+ };
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Converts a value from one numerical base to another.
3
+ *
4
+ * Supported bases are between 2 and 36.
5
+ *
6
+ * @param value Value to convert.
7
+ * @param fromBase Source base.
8
+ * @param toBase Target base.
9
+ *
10
+ * @example
11
+ * base2base("1010", 2, 10) // "10"
12
+ */
13
+ export declare function base2base(
14
+ value: string | number,
15
+ fromBase: number,
16
+ toBase: number
17
+ ): string;
18
+
19
+ /**
20
+ * Converts binary values to octal.
21
+ */
22
+ export declare function bin2oct(
23
+ ...x: (string | number)[]
24
+ ): string[];
25
+
26
+ /**
27
+ * Converts binary values to decimal.
28
+ */
29
+ export declare function bin2dec(
30
+ ...x: (string | number)[]
31
+ ): string[];
32
+
33
+ /**
34
+ * Converts binary values to hexadecimal.
35
+ */
36
+ export declare function bin2hex(
37
+ ...x: (string | number)[]
38
+ ): string[];
39
+
40
+ /**
41
+ * Converts octal values to binary.
42
+ */
43
+ export declare function oct2bin(
44
+ ...x: (string | number)[]
45
+ ): string[];
46
+
47
+ /**
48
+ * Converts octal values to decimal.
49
+ */
50
+ export declare function oct2dec(
51
+ ...x: (string | number)[]
52
+ ): string[];
53
+
54
+ /**
55
+ * Converts octal values to hexadecimal.
56
+ */
57
+ export declare function oct2hex(
58
+ ...x: (string | number)[]
59
+ ): string[];
60
+
61
+ /**
62
+ * Converts decimal values to binary.
63
+ */
64
+ export declare function dec2bin(
65
+ ...x: (string | number)[]
66
+ ): string[];
67
+
68
+ /**
69
+ * Converts decimal values to octal.
70
+ */
71
+ export declare function dec2oct(
72
+ ...x: (string | number)[]
73
+ ): string[];
74
+
75
+ /**
76
+ * Converts decimal values to hexadecimal.
77
+ */
78
+ export declare function dec2hex(
79
+ ...x: (string | number)[]
80
+ ): string[];
81
+
82
+ /**
83
+ * Converts hexadecimal values to binary.
84
+ */
85
+ export declare function hex2bin(
86
+ ...x: (string | number)[]
87
+ ): string[];
88
+
89
+ /**
90
+ * Converts hexadecimal values to octal.
91
+ */
92
+ export declare function hex2oct(
93
+ ...x: (string | number)[]
94
+ ): string[];
95
+
96
+ /**
97
+ * Converts hexadecimal values to decimal.
98
+ */
99
+ export declare function hex2dec(
100
+ ...x: (string | number)[]
101
+ ): string[];
@@ -0,0 +1,61 @@
1
+ export const base2base = (value, fromBase, toBase) => {
2
+ if (fromBase < 2 || fromBase > 36 || toBase < 2 || toBase > 36)
3
+ throw new TypeError('Base must be between 2 and 36');
4
+
5
+ const dec = parseInt(value, fromBase);
6
+ if (Number.isNaN(dec)) throw new TypeError('Invalid value for the given base');
7
+
8
+ return dec.toString(toBase);
9
+ };
10
+
11
+ export const bin2oct = (...x) => mapfun(
12
+ n => base2base(n, 2, 8),
13
+ ...x
14
+ )
15
+ export const bin2dec = (...x) => mapfun(
16
+ n => base2base(n, 2, 10),
17
+ ...x
18
+ )
19
+ export const bin2hex = (...x) => mapfun(
20
+ n => base2base(n, 2, 16),
21
+ ...x
22
+ )
23
+
24
+ export const oct2bin = (...x) => mapfun(
25
+ n => base2base(n, 8, 2),
26
+ ...x
27
+ )
28
+ export const oct2dec = (...x) => mapfun(
29
+ n => base2base(n, 8, 10),
30
+ ...x
31
+ )
32
+ export const oct2hex = (...x) => mapfun(
33
+ n => base2base(n, 8, 16),
34
+ ...x
35
+ )
36
+
37
+ export const dec2bin = (...x) => mapfun(
38
+ n => base2base(n, 10, 2),
39
+ ...x
40
+ )
41
+ export const dec2oct = (...x) => mapfun(
42
+ n => base2base(n, 10, 8),
43
+ ...x
44
+ )
45
+ export const dec2hex = (...x) => mapfun(
46
+ n => base2base(n, 10, 16),
47
+ ...x
48
+ )
49
+
50
+ export const hex2bin = (...x) => mapfun(
51
+ n => base2base(n, 16, 2),
52
+ ...x
53
+ )
54
+ export const hex2oct = (...x) => mapfun(
55
+ n => base2base(n, 16, 8),
56
+ ...x
57
+ )
58
+ export const hex2dec = (...x) => mapfun(
59
+ n => base2base(n, 16, 10),
60
+ ...x
61
+ )
@@ -1,34 +1,3 @@
1
-
2
-
3
- export const bitmasks = (n) => {
4
- const res = [];
5
- for (let i = 0; i < 1 << n; i++) {
6
- const mask = [];
7
- for (let j = 0; j < n; j++) mask.push((i >> j) & 1);
8
- res.push(mask);
9
- }
10
- return res;
11
- };
12
- export const subsets_by_mask = (arr) => {
13
- const n = arr.length,
14
- res = [];
15
- for (let i = 0; i < 1 << n; i++) {
16
- const subset = [];
17
- for (let j = 0; j < n; j++) if ((i >> j) & 1) subset.push(arr[j]);
18
- res.push(subset);
19
- }
20
- return res;
21
- };
22
- export const gray_code = (n) => {
23
- if (n === 0) return [0];
24
- const prev = gray_code(n - 1);
25
- return [...prev, ...prev.map((x) => x | (1 << (n - 1)))];
26
- };
27
- export const hamming_weight = (x) => {
28
- let count = 0;
29
- while (x) {
30
- x &= x - 1;
31
- count++;
32
- }
33
- return count;
34
- };
1
+ export * from './operations/index.js'
2
+ export * from './conversions/index.js'
3
+ export * from './algorithms/index.js'
@@ -0,0 +1,53 @@
1
+ import type { Complex } from "../../complex/indexxx
2
+ import { Matrix } from '../../matrix/index.jsssss
3
+
4
+ export type LogicValue = 0 | 1 | Complex | Matrix;
5
+
6
+ /**
7
+ * Logical NOT operation.
8
+ */
9
+ export declare const not: (
10
+ x: LogicValue
11
+ ) => LogicValue;
12
+
13
+ /**
14
+ * Logical AND operation.
15
+ */
16
+ export declare const and: (
17
+ ...x: LogicValue[]
18
+ ) => LogicValue;
19
+
20
+ /**
21
+ * Logical OR operation.
22
+ */
23
+ export declare const or: (
24
+ ...x: LogicValue[]
25
+ ) => LogicValue;
26
+
27
+ /**
28
+ * Logical XOR operation.
29
+ */
30
+ export declare const xor: (
31
+ ...x: LogicValue[]
32
+ ) => LogicValue;
33
+
34
+ /**
35
+ * Logical NAND operation.
36
+ */
37
+ export declare const nand: (
38
+ ...x: LogicValue[]
39
+ ) => LogicValue;
40
+
41
+ /**
42
+ * Logical NOR operation.
43
+ */
44
+ export declare const nor: (
45
+ ...x: LogicValue[]
46
+ ) => LogicValue;
47
+
48
+ /**
49
+ * Logical XNOR operation.
50
+ */
51
+ export declare const xnor: (
52
+ ...x: LogicValue[]
53
+ ) => LogicValue;
@@ -0,0 +1,54 @@
1
+ export const not = x => {
2
+ if(x.isComplex?.()) return new x.constructor(not(x.a), not(x.b))
3
+ if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, x.arr.flat(1).map(not))
4
+ return + !x;
5
+ }
6
+ const handle_complex_and_matrix = (x, operation) => {
7
+ if (x.every(n => n.isComplex?.())) {
8
+ const Re = x.map(n => n.a);
9
+ const Im = x.map(n => n.b);
10
+ return new x[0].constructor(
11
+ operation(...Re),
12
+ operation(...Im)
13
+ );
14
+ }
15
+
16
+ if (x.every(n => n.isMatrix?.())) {
17
+ if (!x.every(mat => mat.rows === x[0].rows && mat.cols === x[0].cols)) {
18
+ return TypeError('All matrices must have the same shape');
19
+ }
20
+
21
+ const { rows, cols } = x[0];
22
+ const Y = Array.from({ length: rows }, (_, i) =>
23
+ Array.from({ length: cols }, (_, j) =>
24
+ operation(...x.map(mat => mat.arr[i][j]))
25
+ )
26
+ );
27
+ return new x[0].constructor(Y);
28
+ }
29
+
30
+ return null; // Return null if no Complex or Matrix found
31
+ };
32
+
33
+ export const and = (...x) => {
34
+ const result = handle_complex_and_matrix(x, and);
35
+ if (result !== null) return result;
36
+ return x.reduce((n, m) => (n &= m), 1);
37
+ };
38
+
39
+ export const or = (...x) => {
40
+ const result = handle_complex_and_matrix(x, or);
41
+ if (result !== null) return result;
42
+ return x.reduce((n, m) => (n |= m), 0);
43
+ };
44
+
45
+ export const xor = (...x) => {
46
+ const result = handle_complex_and_matrix(x, xor);
47
+ if (result !== null) return result;
48
+ return x.reduce((n, m) => (n ^= m), 0);
49
+ };
50
+
51
+ export const nand = (...x) => not(and(...x));
52
+ export const nor = (...x) => not(or(...x));
53
+ export const xnor = (...x) => not(xor(...x));
54
+
@@ -1,4 +1,4 @@
1
+ export * from './bitwise/index.js'
1
2
  export * from './combination/index.js'
2
3
  export * from './permutation/index.js'
3
- export * from './sequences'
4
- export * from './bitwise'
4
+ export * from './sequences/index.js'
package/src/index.js CHANGED
@@ -3,6 +3,8 @@ export * from './random/index.js'
3
3
  export * from './complex/index.js'
4
4
  export * from './matrix/index.js'
5
5
  export * from './typed-matrix/index.js'
6
+ export * from './discret/bitwise/index.js'
6
7
  export * from './calculus/index.js'
7
8
  export * from './signal/index.js'
8
9
  export * from './stats/index.js'
10
+
@@ -1,4 +1,4 @@
1
- // import { base2base } from "../../../dep/--from-ziko/functions/conversions/index.js";
1
+ import { base2base } from "../discret/bitwise/conversions/index.js";
2
2
  import { accum_sum } from "../stats";
3
3
 
4
4
  export class Random {
@@ -1,5 +1,6 @@
1
- import { mapfun, nthr, pow } from "ziko/math/functions";
2
- import { Matrix } from 'ziko/math/matrix'
1
+ import { mapfun } from "ziko/math/mapfun";
2
+ import { nthr, pow } from '../../../ufunc/index.js'
3
+ import { Matrix } from '../../../matrix/index.js'
3
4
 
4
5
  export const zeros = (n, m, d) => {
5
6
  if(m) return Matrix.zeros(n, m);
@@ -5,7 +5,7 @@ import {
5
5
  lerp,
6
6
  clamp,
7
7
  norm,
8
- } from 'ziko/math/functions'
8
+ } from 'ziko/math/utils'
9
9
  export class AbstractFloatMatrix extends AbstractIntMatrix{
10
10
  constructor(rows, cols, data, type){
11
11
  super(rows, cols, data, type)
@@ -0,0 +1,96 @@
1
+ import { mapfun, MapFunResult } from 'ziko/math/mapfun'
2
+ import { complex } from '../complex/index'
3
+
4
+ // --- Standard Unary / Multi-Argument Math Functions ---
5
+
6
+ export function abs<T>(x: T): MapFunResult<T, any>;
7
+ export function abs<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
8
+
9
+ export function sqrt<T>(x: T): MapFunResult<T, any>;
10
+ export function sqrt<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
11
+
12
+ export function cbrt<T>(x: T): MapFunResult<T, any>;
13
+ export function cbrt<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
14
+
15
+ export function exp<T>(x: T): MapFunResult<T, any>;
16
+ export function exp<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
17
+
18
+ export function ln<T>(x: T): MapFunResult<T, any>;
19
+ export function ln<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
20
+
21
+ export function sign<T>(x: T): MapFunResult<T, any>;
22
+ export function sign<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
23
+
24
+ export function floor<T>(x: T): MapFunResult<T, any>;
25
+ export function floor<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
26
+
27
+ export function ceil<T>(x: T): MapFunResult<T, any>;
28
+ export function ceil<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
29
+
30
+ export function round<T>(x: T): MapFunResult<T, any>;
31
+ export function round<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
32
+
33
+ export function trunc<T>(x: T): MapFunResult<T, any>;
34
+ export function trunc<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
35
+
36
+ export function fract<T>(x: T): MapFunResult<T, any>;
37
+ export function fract<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
38
+
39
+ export function cos<T>(x: T): MapFunResult<T, any>;
40
+ export function cos<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
41
+
42
+ export function sin<T>(x: T): MapFunResult<T, any>;
43
+ export function sin<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
44
+
45
+ export function tan<T>(x: T): MapFunResult<T, any>;
46
+ export function tan<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
47
+
48
+ export function sec<T>(x: T): MapFunResult<T, any>;
49
+ export function sec<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
50
+
51
+ export function acos<T>(x: T): MapFunResult<T, any>;
52
+ export function acos<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
53
+
54
+ export function asin<T>(x: T): MapFunResult<T, any>;
55
+ export function asin<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
56
+
57
+ export function atan<T>(x: T): MapFunResult<T, any>;
58
+ export function atan<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
59
+
60
+ export function acot<T>(x: T): MapFunResult<T, any>;
61
+ export function acot<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
62
+
63
+ export function cosh<T>(x: T): MapFunResult<T, any>;
64
+ export function cosh<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
65
+
66
+ export function sinh<T>(x: T): MapFunResult<T, any>;
67
+ export function sinh<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
68
+
69
+ export function tanh<T>(x: T): MapFunResult<T, any>;
70
+ export function tanh<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
71
+
72
+ export function coth<T>(x: T): MapFunResult<T, any>;
73
+ export function coth<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
74
+
75
+ export function acosh<T>(x: T): MapFunResult<T, any>;
76
+ export function acosh<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
77
+
78
+ export function asinh<T>(x: T): MapFunResult<T, any>;
79
+ export function asinh<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
80
+
81
+ export function atanh<T>(x: T): MapFunResult<T, any>;
82
+ export function atanh<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
83
+
84
+ export function sig<T>(x: T): MapFunResult<T, any>;
85
+ export function sig<T extends any[]>(...x: T): { [K in keyof T]: MapFunResult<T[K], any> };
86
+
87
+ // --- Functions that pop parameters from the end (pow, nthr, croot) ---
88
+
89
+ export function pow<T, N>(base: T, n: N): MapFunResult<T, any>;
90
+ export function pow<T extends any[], N>(...args: [...T, N]): { [K in keyof T]: MapFunResult<T[K], any> };
91
+
92
+ export function nthr<T, N extends number>(base: T, n: N): MapFunResult<T, any>;
93
+ export function nthr<T extends any[], N extends number>(...args: [...T, N]): { [K in keyof T]: MapFunResult<T[K], any> };
94
+
95
+ export function croot<T, C>(base: T, root: C): MapFunResult<T, any>;
96
+ export function croot<T extends any[], C>(...args: [...T, C]): { [K in keyof T]: MapFunResult<T[K], any> };
@@ -1 +1,372 @@
1
- export * from 'ziko/math/functions'
1
+ import { mapfun } from 'ziko/math/mapfun';
2
+ import { complex } from '../complex/index.js'
3
+
4
+ const PRECESION = 8
5
+
6
+ export const abs = (...x) => mapfun(
7
+ x =>{
8
+ if(x.isComplex?.()) return x.z;
9
+ return Math.abs(x)
10
+ },
11
+ ...x
12
+ )
13
+
14
+ export const pow = (...x) => {
15
+ const n = x.pop();
16
+ return mapfun(
17
+ x => {
18
+ if(x.isComplex?.()) {
19
+ if(n.isComplex?.()) return new x.constructor({
20
+ z: Math.exp(n.a * Math.log(x.z) - n.b * x.phi),
21
+ phi: n.b * Math.log(x.z) + n.a * x.phi
22
+ })
23
+ return new x.constructor({z: x.z ** n, phi: x.phi * n});
24
+ }
25
+ if(n.isComplex?.()) return new x.constructor({
26
+ z: Math.exp(n.a * Math.log(x)),
27
+ phi: n.b * Math.log(x)
28
+ })
29
+ return Math.pow(x, n)
30
+ },
31
+ ...x
32
+ )
33
+ }
34
+
35
+ export const sqrt = (...x) => mapfun(
36
+ x=>{
37
+ if(x.isComplex?.())
38
+ return new x.constructor({z: x.z**(1/2), phi: x.phi/2});
39
+ if(x < 0) return complex(0, Math.sqrt(-x)).toFixed(PRECESION)
40
+ return + Math.sqrt(x).toFixed(PRECESION);
41
+ },
42
+ ...x
43
+ );
44
+
45
+ export const cbrt = (...x) => mapfun(
46
+ x=>{
47
+ if(x.isComplex?.())
48
+ return new x.constructor({z: x.z**(1/3), phi: x.phi/3}).toFixed(PRECESION)
49
+ return + Math.cbrt(x).toFixed(PRECESION);
50
+ },
51
+ ...x
52
+ );
53
+
54
+ export const nthr = (...x) => {
55
+ const n = x.pop();
56
+ if(typeof n !== 'number') throw Error('nthr expects a real number n');
57
+ return mapfun(
58
+ x => {
59
+ if(x.isComplex?.()) return new x.constructor({z: x.z ** (1/n), phi: x.phi / n});
60
+ if(x<0) return n %2 ===2
61
+ ? complex(0, (-x)**(1/n)).toFixed(PRECESION)
62
+ : + (-1 * (-x)**(1/n)).toFixed(PRECESION)
63
+ return + (x**(1/n)).toFixed(PRECESION)
64
+ },
65
+ ...x
66
+ )
67
+ }
68
+
69
+ export const croot = (...x) =>{
70
+ const c = x.pop()
71
+ if(!c.isComplex?.()) throw Error('croot expect Complex number as root')
72
+ return mapfun(
73
+ x => {
74
+ if(typeof x === 'number') x = new c.constructor(x, 0);
75
+ const {a : c_a, b : c_b} = c;
76
+ const {z, phi} = x;
77
+ const D = Math.hypot(c_a, c_b);
78
+ const A = Math.exp((Math.log(z)*c_a + phi*c_b)/D);
79
+ const B = (phi*c_a - Math.log(z)*c_b)/D
80
+ return new c.constructor(
81
+ A * Math.cos(B),
82
+ A * Math.sin(B)
83
+ ).toFixed(PRECESION)
84
+ },
85
+ ...x
86
+ )
87
+ }
88
+
89
+ export const exp = (...x) => mapfun(
90
+ x => {
91
+ if(x.isComplex?.()) return new x.constructor(
92
+ Math.exp(x.a) * Math.cos(x.b),
93
+ Math.exp(x.a) * Math.sin(x.b)
94
+ ).toFixed(PRECESION);
95
+ return + Math.exp(x).toFixed(PRECESION)
96
+ }
97
+ ,...x
98
+ );
99
+
100
+ export const ln = (...x) => mapfun(
101
+ x => {
102
+ if(x.isComplex?.()) return new x.constructor(
103
+ Math.log(x.z),
104
+ x.phi
105
+ ).toFixed(PRECESION);
106
+ return + Math.log(x).toFixed(PRECESION)
107
+ }
108
+ ,...x
109
+ );
110
+
111
+ export const sign = (...x) => mapfun(
112
+ x => {
113
+ if(x.isComplex?.()){
114
+ const {z, phi} = x;
115
+ if(z===0) return new x.constructor(0, 0);
116
+ return new x.constructor({z:1, phi})
117
+ }
118
+ return Math.sign(x)
119
+ }
120
+ ,...x
121
+ );
122
+
123
+ export const floor = (...x) => mapfun(
124
+ x => {
125
+ if(x.isComplex?.()) return new x.constructor(
126
+ Math.floor(x.a),
127
+ Math.floor(x.b)
128
+ )
129
+ return Math.floor(x)
130
+ },
131
+ ...x
132
+ )
133
+ export const ceil = (...x) => mapfun(
134
+ x => {
135
+ if(x.isComplex?.()) return new x.constructor(
136
+ Math.ceil(x.a),
137
+ Math.ceil(x.b)
138
+ )
139
+ return Math.ceil(x)
140
+ },
141
+ ...x
142
+ )
143
+ export const round = (...x) => mapfun(
144
+ x => {
145
+ if(x.isComplex?.()) return new x.constructor(
146
+ Math.round(x.a),
147
+ Math.round(x.b)
148
+ )
149
+ return Math.round(x)
150
+ },
151
+ ...x
152
+ )
153
+
154
+ export const trunc = (...x) => mapfun(
155
+ x => {
156
+ if(x.isComplex?.()) return new x.constructor(
157
+ Math.trunc(x.a),
158
+ Math.trunc(x.b)
159
+ )
160
+ return Math.trunc(x)
161
+ },
162
+ ...x
163
+ )
164
+
165
+ export const fract = (...x) => mapfun(
166
+ x => {
167
+ if(x.isComplex?.()) return new x.constructor(
168
+ x.a - Math.trunc(x.a),
169
+ x.b - Math.trunc(x.b)
170
+ )
171
+ return x - Math.trunc(x)
172
+ },
173
+ ...x
174
+ )
175
+
176
+ export const cos = (...x) => mapfun(
177
+ x => {
178
+ if(x.isComplex?.()) return new x.constructor(
179
+ Math.cos(x.a) * Math.cosh(x.b),
180
+ -Math.sin(x.a) * Math.sinh(x.b)
181
+ ).toFixed(PRECESION);
182
+ return + Math.cos(x).toFixed(PRECESION)
183
+ }
184
+ ,...x
185
+ );
186
+
187
+ export const sin = (...x) => mapfun(
188
+ x =>{
189
+ if(x?.isComplex) return new x.constructor(
190
+ Math.sin(x.a) * Math.cosh(x.b),
191
+ Math.cos(x.a) * Math.sinh(x.b)
192
+ ).toFixed(PRECESION);
193
+ return + Math.sin(x).toFixed(PRECESION)
194
+ }
195
+ , ...x
196
+ );
197
+
198
+ export const tan = (...x) => mapfun(
199
+ x =>{
200
+ if(x?.isComplex){
201
+ const D = Math.cos(2*x.a) + Math.cosh(2*x.b);
202
+ return new x.constructor(
203
+ Math.sin(2*x.a) / D,
204
+ Math.sinh(2*x.b) / D
205
+ ).toFixed(PRECESION);
206
+ }
207
+ return + Math.tan(x).toFixed(PRECESION)
208
+ },
209
+ ...x
210
+ );
211
+
212
+ export const sec = (...x) => mapfun(
213
+ x => {
214
+ if(x.isComplex?.()) {
215
+
216
+ }
217
+ return + (1 / Math.cos(x)).toFixed(PRECESION)
218
+ }
219
+ ,...x
220
+ );
221
+
222
+ export const acos = (...x) => mapfun(
223
+ x =>{
224
+ if(x?.isComplex){
225
+ const { a, b } = x;
226
+ const Rp = Math.hypot(a + 1, b);
227
+ const Rm = Math.hypot(a - 1, b);
228
+ globalThis.Rp = Rp
229
+ globalThis.Rm = Rm
230
+ return new x.constructor(
231
+ Math.acos((Rp - Rm) / 2),
232
+ -Math.acosh((Rp + Rm) / 2),
233
+ ).toFixed(PRECESION)
234
+ }
235
+ return + Math.acos(x).toFixed(PRECESION)
236
+ },
237
+ ...x
238
+ );
239
+
240
+ export const asin = (...x) => mapfun(
241
+ x => {
242
+ if(x?.isComplex){
243
+ const { a, b } = x;
244
+ const Rp = Math.hypot(a + 1, b);
245
+ const Rm = Math.hypot(a - 1, b);
246
+ return new x.constructor(
247
+ Math.asin((Rp - Rm) / 2),
248
+ Math.acosh((Rp + Rm) / 2)
249
+ ).toFixed(PRECESION);
250
+ }
251
+ return + Math.asin(x).toFixed(PRECESION);
252
+ },
253
+ ...x
254
+ );
255
+
256
+ export const atan = (...x) => mapfun(
257
+ x => {
258
+ if(x?.isComplex){
259
+ const { a, b } = x;
260
+ return new x.constructor(
261
+ Math.atan((a*2/(1-a**2-b**2)))/2,
262
+ Math.log((a**2 + (1+b)**2)/(a**2 + (1-b)**2))/4
263
+ ).toFixed(PRECESION)
264
+ }
265
+ return + Math.atan(x).toFixed(PRECESION);
266
+ },
267
+ ...x
268
+ );
269
+
270
+ export const acot = (...x) => mapfun(
271
+ x => {
272
+ if(x?.isComplex){
273
+ const { a, b } = x;
274
+ return new x.constructor(
275
+ Math.atan(2*a/(a**2+(b-1)*(b+1)))/2,
276
+ Math.log((a**2 + (b-1)**2)/(a**2 + (b+1)**2))/4
277
+ ).toFixed(PRECESION)
278
+ }
279
+ return + (Math.PI/2 - Math.atan(x)).toFixed(PRECESION);
280
+ },
281
+ ...x
282
+ );
283
+
284
+
285
+ export const cosh = (...x) => mapfun(
286
+ x =>{
287
+ if(x?.isComplex) return new x.constructor(
288
+ Math.cosh(x.a) * Math.cos(x.b),
289
+ Math.sinh(x.a) * Math.sin(x.b)
290
+ ).toFixed(PRECESION);
291
+ return + Math.cosh(x).toFixed(PRECESION)
292
+ },
293
+ ...x
294
+ )
295
+ export const sinh = (...x) => mapfun(
296
+ x =>{
297
+ if(x?.isComplex) return new x.constructor(
298
+ Math.sinh(x.a) * Math.cos(x.b),
299
+ Math.cosh(x.a) * Math.sin(x.b)
300
+ ).toFixed(PRECESION);
301
+ return + Math.sinh(x).toFixed(PRECESION)
302
+ },
303
+ ...x
304
+ )
305
+ export const tanh = (...x) => mapfun(
306
+ x =>{
307
+ if(x?.isComplex){
308
+ const D = Math.cosh(2*a) + Math.cos(2*b);
309
+ return new x.constructor(
310
+ Math.sinh(2*a) / D,
311
+ Math.sin(2*b) / D
312
+ ).toFixed(PRECESION)
313
+ }
314
+ return + Math.tanh(x).toFixed(PRECESION)
315
+ },
316
+ ...x
317
+ )
318
+
319
+ export const coth = (...x) => mapfun(
320
+ x =>{
321
+ if(x?.isComplex){
322
+ const {a, b} = x
323
+ const D = (Math.sinh(a)**2)*(Math.cos(b)**2) + (Math.cosh(a)**2)*(Math.sin(b)**2)
324
+ return new x.constructor(
325
+ Math.cosh(a) * Math.sinh(a) / D,
326
+ - Math.sin(b) * Math.cos(b) / D
327
+ ).toFixed(PRECESION)
328
+ }
329
+ return + (1 / Math.tanh(x)).toFixed(PRECESION)
330
+ },
331
+ ...x
332
+ )
333
+
334
+ export const acosh = (...x) => mapfun(
335
+ x =>{
336
+ if(x?.isComplex){
337
+ return ln(x.clone().add(sqrt(x.clone().mul(x.clone()).sub(1))))
338
+ }
339
+ return + Math.acosh(x).toFixed(PRECESION)
340
+ },
341
+ ...x
342
+ )
343
+
344
+ export const asinh = (...x) => mapfun(
345
+ x =>{
346
+ if(x?.isComplex){
347
+ return ln(x.clone().add(sqrt(x.clone().mul(x.clone()).add(1))))
348
+ }
349
+ return + Math.asinh(x).toFixed(PRECESION)
350
+ },
351
+ ...x
352
+ )
353
+
354
+ export const atanh = (...x) => mapfun(
355
+ x =>{
356
+ if(x?.isComplex){
357
+
358
+ }
359
+ return + Math.atanh(x).toFixed(PRECESION)
360
+ },
361
+ ...x
362
+ )
363
+
364
+ export const sig = (...x) => mapfun(
365
+ x =>{
366
+ if(x?.isComplex){
367
+
368
+ }
369
+ return + 1/(1 + Math.exp(-x)).toFixed(PRECESION)
370
+ },
371
+ ...x
372
+ )