@obinexusmk2/hypernum 0.1.0 → 0.1.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/LICENSE +21 -21
- package/README.md +355 -256
- package/dist/index.cjs +4 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/types/{config → src/config}/config-loader.d.ts +0 -0
- package/dist/types/src/config/config-loader.d.ts.map +1 -0
- package/dist/types/{config → src/config}/config-parser.d.ts +0 -0
- package/dist/types/src/config/config-parser.d.ts.map +1 -0
- package/dist/types/{config → src/config}/config-resolver.d.ts +0 -0
- package/dist/types/src/config/config-resolver.d.ts.map +1 -0
- package/dist/types/{config → src/config}/config-source.d.ts +0 -0
- package/dist/types/src/config/config-source.d.ts.map +1 -0
- package/dist/types/{config → src/config}/index.d.ts +0 -0
- package/dist/types/src/config/index.d.ts.map +1 -0
- package/dist/types/{core → src/core}/common.d.ts +0 -0
- package/dist/types/src/core/common.d.ts.map +1 -0
- package/dist/types/{core → src/core}/config.d.ts +0 -0
- package/dist/types/src/core/config.d.ts.map +1 -0
- package/dist/types/{core → src/core}/constants.d.ts +0 -0
- package/dist/types/src/core/constants.d.ts.map +1 -0
- package/dist/types/{core → src/core}/errors.d.ts +0 -0
- package/dist/types/src/core/errors.d.ts.map +1 -0
- package/dist/types/{core → src/core}/hypernum.d.ts +0 -0
- package/dist/types/src/core/hypernum.d.ts.map +1 -0
- package/dist/types/{core → src/core}/index.d.ts +0 -0
- package/dist/types/src/core/index.d.ts.map +1 -0
- package/dist/types/{index.d.ts → src/index.d.ts} +1 -1
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/arithmetic.d.ts +0 -0
- package/dist/types/src/operations/arithmetic.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/bitwise.d.ts +0 -0
- package/dist/types/src/operations/bitwise.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/comparison.d.ts +0 -0
- package/dist/types/src/operations/comparison.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/conversion.d.ts +0 -0
- package/dist/types/src/operations/conversion.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/factorial.d.ts +0 -0
- package/dist/types/src/operations/factorial.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/index.d.ts +0 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/{operations → src/operations}/power.d.ts +0 -0
- package/dist/types/src/operations/power.d.ts.map +1 -0
- package/dist/types/{storage → src/storage}/Heap.d.ts +0 -0
- package/dist/types/src/storage/Heap.d.ts.map +1 -0
- package/dist/types/{storage → src/storage}/index.d.ts +0 -0
- package/dist/types/src/storage/index.d.ts.map +1 -0
- package/dist/types/{structures → src/structures}/ackermann.d.ts +0 -0
- package/dist/types/src/structures/ackermann.d.ts.map +1 -0
- package/dist/types/{structures → src/structures}/big-array.d.ts +0 -0
- package/dist/types/src/structures/big-array.d.ts.map +1 -0
- package/dist/types/{structures → src/structures}/index.d.ts +0 -0
- package/dist/types/src/structures/index.d.ts.map +1 -0
- package/dist/types/{structures → src/structures}/number-tree.d.ts +0 -0
- package/dist/types/src/structures/number-tree.d.ts.map +1 -0
- package/dist/types/{structures → src/structures}/power-tower.d.ts +0 -0
- package/dist/types/src/structures/power-tower.d.ts.map +1 -0
- package/dist/types/{utils → src/utils}/formatting.d.ts +0 -0
- package/dist/types/src/utils/formatting.d.ts.map +1 -0
- package/dist/types/{utils → src/utils}/index.d.ts +0 -0
- package/dist/types/src/utils/index.d.ts.map +1 -0
- package/dist/types/{utils → src/utils}/parser.d.ts +0 -0
- package/dist/types/src/utils/parser.d.ts.map +1 -0
- package/dist/types/{utils → src/utils}/precision.d.ts +0 -0
- package/dist/types/src/utils/precision.d.ts.map +1 -0
- package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
- package/dist/types/src/utils/validation.d.ts.map +1 -0
- package/package.json +169 -164
- package/rollup.config.js +163 -161
- package/src/cli/hypernum.js +272 -0
- package/src/config/config-loader.ts +0 -0
- package/src/config/config-parser.ts +160 -160
- package/src/config/config-resolver.ts +0 -0
- package/src/config/config-source.ts +0 -0
- package/src/config/index.ts +0 -0
- package/src/core/common.ts +184 -184
- package/src/core/config.ts +392 -392
- package/src/core/constants.ts +101 -101
- package/src/core/errors.ts +202 -202
- package/src/core/hypernum.ts +240 -240
- package/src/core/index.ts +4 -4
- package/src/index.ts +179 -182
- package/src/operations/arithmetic.ts +332 -332
- package/src/operations/bitwise.ts +366 -366
- package/src/operations/comparison.ts +271 -271
- package/src/operations/conversion.ts +399 -399
- package/src/operations/factorial.ts +278 -278
- package/src/operations/index.ts +4 -4
- package/src/operations/power.ts +315 -315
- package/src/storage/Heap.ts +237 -237
- package/src/storage/index.ts +0 -0
- package/src/structures/ackermann.ts +232 -232
- package/src/structures/big-array.ts +305 -305
- package/src/structures/index.ts +3 -3
- package/src/structures/number-tree.ts +403 -403
- package/src/structures/power-tower.ts +277 -277
- package/src/types/common.d.ts +356 -356
- package/src/types/core.d.ts +160 -160
- package/src/types/index.d.ts +1 -1
- package/src/utils/formatting.ts +245 -245
- package/src/utils/index.ts +4 -4
- package/src/utils/parser.ts +244 -244
- package/src/utils/precision.ts +216 -216
- package/src/utils/validation.ts +182 -182
- package/tsconfig.json +83 -83
- package/dist/types/config/config-loader.d.ts.map +0 -1
- package/dist/types/config/config-parser.d.ts.map +0 -1
- package/dist/types/config/config-resolver.d.ts.map +0 -1
- package/dist/types/config/config-source.d.ts.map +0 -1
- package/dist/types/config/index.d.ts.map +0 -1
- package/dist/types/core/common.d.ts.map +0 -1
- package/dist/types/core/config.d.ts.map +0 -1
- package/dist/types/core/constants.d.ts.map +0 -1
- package/dist/types/core/errors.d.ts.map +0 -1
- package/dist/types/core/hypernum.d.ts.map +0 -1
- package/dist/types/core/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/operations/arithmetic.d.ts.map +0 -1
- package/dist/types/operations/bitwise.d.ts.map +0 -1
- package/dist/types/operations/comparison.d.ts.map +0 -1
- package/dist/types/operations/conversion.d.ts.map +0 -1
- package/dist/types/operations/factorial.d.ts.map +0 -1
- package/dist/types/operations/index.d.ts.map +0 -1
- package/dist/types/operations/power.d.ts.map +0 -1
- package/dist/types/storage/Heap.d.ts.map +0 -1
- package/dist/types/storage/index.d.ts.map +0 -1
- package/dist/types/structures/ackermann.d.ts.map +0 -1
- package/dist/types/structures/big-array.d.ts.map +0 -1
- package/dist/types/structures/index.d.ts.map +0 -1
- package/dist/types/structures/number-tree.d.ts.map +0 -1
- package/dist/types/structures/power-tower.d.ts.map +0 -1
- package/dist/types/utils/formatting.d.ts.map +0 -1
- package/dist/types/utils/index.d.ts.map +0 -1
- package/dist/types/utils/parser.d.ts.map +0 -1
- package/dist/types/utils/precision.d.ts.map +0 -1
- package/dist/types/utils/validation.d.ts.map +0 -1
package/src/core/hypernum.ts
CHANGED
|
@@ -1,241 +1,241 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Main Hypernum class that provides a high-level interface to all library functionality
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
DEFAULT_OPTIONS,
|
|
8
|
-
FEATURES,
|
|
9
|
-
MAX_PRECISION,
|
|
10
|
-
MAX_COMPUTATION_STEPS
|
|
11
|
-
} from './constants';
|
|
12
|
-
import {
|
|
13
|
-
HypernumError,
|
|
14
|
-
ValidationError,
|
|
15
|
-
OverflowError
|
|
16
|
-
} from './errors';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// Import all operations and structures
|
|
20
|
-
import * as arithmetic from '../operations/arithmetic';
|
|
21
|
-
import * as bitwise from '../operations/bitwise';
|
|
22
|
-
import * as power from '../operations/power';
|
|
23
|
-
import { BigArray, NumberTree, AckermannStructure } from '../structures';
|
|
24
|
-
import * as formatting from '../utils/formatting';
|
|
25
|
-
import * as validation from '../utils/validation';
|
|
26
|
-
import * as precision from '../utils/precision';
|
|
27
|
-
import { MinHeap, MaxHeap } from '@/storage';
|
|
28
|
-
/**
|
|
29
|
-
* Configuration options for Hypernum instance
|
|
30
|
-
*/
|
|
31
|
-
export interface HypernumConfig {
|
|
32
|
-
precision?: number;
|
|
33
|
-
roundingMode?: precision.RoundingMode;
|
|
34
|
-
checkOverflow?: boolean;
|
|
35
|
-
maxSteps?: number;
|
|
36
|
-
debug?: boolean;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class Hypernum {
|
|
40
|
-
private readonly config: Required<HypernumConfig>;
|
|
41
|
-
private readonly structures: {
|
|
42
|
-
arrays: Map<string, BigArray<bigint>>;
|
|
43
|
-
trees: Map<string, NumberTree>;
|
|
44
|
-
heaps: Map<string, MinHeap<bigint> | MaxHeap<bigint>>;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
constructor(config: HypernumConfig = {}) {
|
|
48
|
-
this.config = {
|
|
49
|
-
precision: config.precision ?? DEFAULT_OPTIONS.precision,
|
|
50
|
-
roundingMode: config.roundingMode ?? DEFAULT_OPTIONS.roundingMode as precision.RoundingMode,
|
|
51
|
-
checkOverflow: config.checkOverflow ?? DEFAULT_OPTIONS.checkOverflow,
|
|
52
|
-
maxSteps: config.maxSteps ?? DEFAULT_OPTIONS.maxSteps,
|
|
53
|
-
debug: config.debug ?? FEATURES.DEBUG_MODE
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// Validate configuration
|
|
57
|
-
if (this.config.precision < 0 || this.config.precision > MAX_PRECISION) {
|
|
58
|
-
throw new ValidationError(`Precision must be between 0 and ${MAX_PRECISION}`);
|
|
59
|
-
}
|
|
60
|
-
if (this.config.maxSteps < 1 || this.config.maxSteps > MAX_COMPUTATION_STEPS) {
|
|
61
|
-
throw new ValidationError(`Max steps must be between 1 and ${MAX_COMPUTATION_STEPS}`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Initialize data structure storage
|
|
65
|
-
this.structures = {
|
|
66
|
-
arrays: new Map(),
|
|
67
|
-
trees: new Map(),
|
|
68
|
-
heaps: new Map()
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Arithmetic Operations
|
|
73
|
-
public add(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
74
|
-
return arithmetic.add(a, b, this.config);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public subtract(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
78
|
-
return arithmetic.subtract(a, b, this.config);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public multiply(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
82
|
-
return arithmetic.multiply(a, b, this.config);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public divide(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
86
|
-
return arithmetic.divide(a, b, this.config);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public mod(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
90
|
-
return arithmetic.remainder(a, b, this.config);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Power Operations
|
|
94
|
-
public power(base: bigint | string | number, exponent: bigint | string | number): bigint {
|
|
95
|
-
return power.power(base, exponent, this.config);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public sqrt(value: bigint | string | number): bigint {
|
|
99
|
-
return power.sqrt(value, this.config);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public nthRoot(value: bigint | string | number, n: bigint | string | number): bigint {
|
|
103
|
-
return power.nthRoot(value, n, this.config);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Bitwise Operations
|
|
107
|
-
public and(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
108
|
-
return bitwise.and(a, b);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public or(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
112
|
-
return bitwise.or(a, b);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
public xor(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
116
|
-
return bitwise.xor(a, b);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public not(value: bigint | string | number): bigint {
|
|
120
|
-
return bitwise.not(value);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Calculates the greatest common divisor of two numbers
|
|
124
|
-
*/
|
|
125
|
-
public gcd(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
126
|
-
return arithmetic.gcd(a, b);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Calculates the least common multiple of two numbers
|
|
131
|
-
*/
|
|
132
|
-
public lcm(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
133
|
-
return arithmetic.lcm(a, b);
|
|
134
|
-
}
|
|
135
|
-
// Data Structure Management
|
|
136
|
-
public createArray(id: string): BigArray<bigint> {
|
|
137
|
-
if (this.structures.arrays.has(id)) {
|
|
138
|
-
throw new ValidationError(`Array with id '${id}' already exists`);
|
|
139
|
-
}
|
|
140
|
-
const array = new BigArray<bigint>();
|
|
141
|
-
this.structures.arrays.set(id, array);
|
|
142
|
-
return array;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
public getArray(id: string): BigArray<bigint> {
|
|
146
|
-
const array = this.structures.arrays.get(id);
|
|
147
|
-
if (!array) {
|
|
148
|
-
throw new ValidationError(`Array with id '${id}' not found`);
|
|
149
|
-
}
|
|
150
|
-
return array;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
public createTree(id: string): NumberTree {
|
|
154
|
-
if (this.structures.trees.has(id)) {
|
|
155
|
-
throw new ValidationError(`Tree with id '${id}' already exists`);
|
|
156
|
-
}
|
|
157
|
-
const tree = new NumberTree();
|
|
158
|
-
this.structures.trees.set(id, tree);
|
|
159
|
-
return tree;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
public getTree(id: string): NumberTree {
|
|
163
|
-
const tree = this.structures.trees.get(id);
|
|
164
|
-
if (!tree) {
|
|
165
|
-
throw new ValidationError(`Tree with id '${id}' not found`);
|
|
166
|
-
}
|
|
167
|
-
return tree;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
public createHeap(id: string, isMinHeap: boolean = true): MinHeap<bigint> | MaxHeap<bigint> {
|
|
171
|
-
if (this.structures.heaps.has(id)) {
|
|
172
|
-
throw new ValidationError(`Heap with id '${id}' already exists`);
|
|
173
|
-
}
|
|
174
|
-
const heap = isMinHeap ? new MinHeap<bigint>(this.compareValues) : new MaxHeap<bigint>(this.compareValues);
|
|
175
|
-
this.structures.heaps.set(id, heap);
|
|
176
|
-
return heap;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
public getHeap(id: string): MinHeap<bigint> | MaxHeap<bigint> {
|
|
180
|
-
const heap = this.structures.heaps.get(id);
|
|
181
|
-
if (!heap) {
|
|
182
|
-
throw new ValidationError(`Heap with id '${id}' not found`);
|
|
183
|
-
}
|
|
184
|
-
return heap;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Special Functions
|
|
188
|
-
public createAckermannStructure(): AckermannStructure {
|
|
189
|
-
return new AckermannStructure();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Formatting and Validation
|
|
193
|
-
public format(value: bigint | string | number, options?: formatting.FormatOptions): string {
|
|
194
|
-
const bigValue = validation.toBigInt(value);
|
|
195
|
-
return formatting.formatBigInt(bigValue, options);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
public validate(value: unknown): boolean {
|
|
199
|
-
try {
|
|
200
|
-
validation.toBigInt(value);
|
|
201
|
-
return true;
|
|
202
|
-
} catch {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Configuration Management
|
|
208
|
-
public updateConfig(newConfig: Partial<HypernumConfig>): void {
|
|
209
|
-
Object.assign(this.config, newConfig);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
public getConfig(): Readonly<Required<HypernumConfig>> {
|
|
213
|
-
return { ...this.config };
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// Utility Functions
|
|
217
|
-
private compareValues(a: bigint, b: bigint): -1 | 0 | 1 {
|
|
218
|
-
if (a < b) return -1;
|
|
219
|
-
if (a > b) return 1;
|
|
220
|
-
return 0;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Cleanup
|
|
224
|
-
public dispose(): void {
|
|
225
|
-
this.structures.arrays.clear();
|
|
226
|
-
this.structures.trees.clear();
|
|
227
|
-
this.structures.heaps.clear();
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Export additional types and utilities
|
|
232
|
-
export {
|
|
233
|
-
HypernumError,
|
|
234
|
-
ValidationError,
|
|
235
|
-
OverflowError,
|
|
236
|
-
precision,
|
|
237
|
-
formatting,
|
|
238
|
-
validation
|
|
239
|
-
};
|
|
240
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Main Hypernum class that provides a high-level interface to all library functionality
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_OPTIONS,
|
|
8
|
+
FEATURES,
|
|
9
|
+
MAX_PRECISION,
|
|
10
|
+
MAX_COMPUTATION_STEPS
|
|
11
|
+
} from './constants';
|
|
12
|
+
import {
|
|
13
|
+
HypernumError,
|
|
14
|
+
ValidationError,
|
|
15
|
+
OverflowError
|
|
16
|
+
} from './errors';
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
// Import all operations and structures
|
|
20
|
+
import * as arithmetic from '../operations/arithmetic';
|
|
21
|
+
import * as bitwise from '../operations/bitwise';
|
|
22
|
+
import * as power from '../operations/power';
|
|
23
|
+
import { BigArray, NumberTree, AckermannStructure } from '../structures';
|
|
24
|
+
import * as formatting from '../utils/formatting';
|
|
25
|
+
import * as validation from '../utils/validation';
|
|
26
|
+
import * as precision from '../utils/precision';
|
|
27
|
+
import { MinHeap, MaxHeap } from '@/storage';
|
|
28
|
+
/**
|
|
29
|
+
* Configuration options for Hypernum instance
|
|
30
|
+
*/
|
|
31
|
+
export interface HypernumConfig {
|
|
32
|
+
precision?: number;
|
|
33
|
+
roundingMode?: precision.RoundingMode;
|
|
34
|
+
checkOverflow?: boolean;
|
|
35
|
+
maxSteps?: number;
|
|
36
|
+
debug?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class Hypernum {
|
|
40
|
+
private readonly config: Required<HypernumConfig>;
|
|
41
|
+
private readonly structures: {
|
|
42
|
+
arrays: Map<string, BigArray<bigint>>;
|
|
43
|
+
trees: Map<string, NumberTree>;
|
|
44
|
+
heaps: Map<string, MinHeap<bigint> | MaxHeap<bigint>>;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
constructor(config: HypernumConfig = {}) {
|
|
48
|
+
this.config = {
|
|
49
|
+
precision: config.precision ?? DEFAULT_OPTIONS.precision,
|
|
50
|
+
roundingMode: config.roundingMode ?? DEFAULT_OPTIONS.roundingMode as precision.RoundingMode,
|
|
51
|
+
checkOverflow: config.checkOverflow ?? DEFAULT_OPTIONS.checkOverflow,
|
|
52
|
+
maxSteps: config.maxSteps ?? DEFAULT_OPTIONS.maxSteps,
|
|
53
|
+
debug: config.debug ?? FEATURES.DEBUG_MODE
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Validate configuration
|
|
57
|
+
if (this.config.precision < 0 || this.config.precision > MAX_PRECISION) {
|
|
58
|
+
throw new ValidationError(`Precision must be between 0 and ${MAX_PRECISION}`);
|
|
59
|
+
}
|
|
60
|
+
if (this.config.maxSteps < 1 || this.config.maxSteps > MAX_COMPUTATION_STEPS) {
|
|
61
|
+
throw new ValidationError(`Max steps must be between 1 and ${MAX_COMPUTATION_STEPS}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Initialize data structure storage
|
|
65
|
+
this.structures = {
|
|
66
|
+
arrays: new Map(),
|
|
67
|
+
trees: new Map(),
|
|
68
|
+
heaps: new Map()
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Arithmetic Operations
|
|
73
|
+
public add(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
74
|
+
return arithmetic.add(a, b, this.config);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public subtract(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
78
|
+
return arithmetic.subtract(a, b, this.config);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public multiply(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
82
|
+
return arithmetic.multiply(a, b, this.config);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public divide(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
86
|
+
return arithmetic.divide(a, b, this.config);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public mod(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
90
|
+
return arithmetic.remainder(a, b, this.config);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Power Operations
|
|
94
|
+
public power(base: bigint | string | number, exponent: bigint | string | number): bigint {
|
|
95
|
+
return power.power(base, exponent, this.config);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public sqrt(value: bigint | string | number): bigint {
|
|
99
|
+
return power.sqrt(value, this.config);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public nthRoot(value: bigint | string | number, n: bigint | string | number): bigint {
|
|
103
|
+
return power.nthRoot(value, n, this.config);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Bitwise Operations
|
|
107
|
+
public and(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
108
|
+
return bitwise.and(a, b);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public or(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
112
|
+
return bitwise.or(a, b);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public xor(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
116
|
+
return bitwise.xor(a, b);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public not(value: bigint | string | number): bigint {
|
|
120
|
+
return bitwise.not(value);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Calculates the greatest common divisor of two numbers
|
|
124
|
+
*/
|
|
125
|
+
public gcd(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
126
|
+
return arithmetic.gcd(a, b);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Calculates the least common multiple of two numbers
|
|
131
|
+
*/
|
|
132
|
+
public lcm(a: bigint | string | number, b: bigint | string | number): bigint {
|
|
133
|
+
return arithmetic.lcm(a, b);
|
|
134
|
+
}
|
|
135
|
+
// Data Structure Management
|
|
136
|
+
public createArray(id: string): BigArray<bigint> {
|
|
137
|
+
if (this.structures.arrays.has(id)) {
|
|
138
|
+
throw new ValidationError(`Array with id '${id}' already exists`);
|
|
139
|
+
}
|
|
140
|
+
const array = new BigArray<bigint>();
|
|
141
|
+
this.structures.arrays.set(id, array);
|
|
142
|
+
return array;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public getArray(id: string): BigArray<bigint> {
|
|
146
|
+
const array = this.structures.arrays.get(id);
|
|
147
|
+
if (!array) {
|
|
148
|
+
throw new ValidationError(`Array with id '${id}' not found`);
|
|
149
|
+
}
|
|
150
|
+
return array;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public createTree(id: string): NumberTree {
|
|
154
|
+
if (this.structures.trees.has(id)) {
|
|
155
|
+
throw new ValidationError(`Tree with id '${id}' already exists`);
|
|
156
|
+
}
|
|
157
|
+
const tree = new NumberTree();
|
|
158
|
+
this.structures.trees.set(id, tree);
|
|
159
|
+
return tree;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
public getTree(id: string): NumberTree {
|
|
163
|
+
const tree = this.structures.trees.get(id);
|
|
164
|
+
if (!tree) {
|
|
165
|
+
throw new ValidationError(`Tree with id '${id}' not found`);
|
|
166
|
+
}
|
|
167
|
+
return tree;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public createHeap(id: string, isMinHeap: boolean = true): MinHeap<bigint> | MaxHeap<bigint> {
|
|
171
|
+
if (this.structures.heaps.has(id)) {
|
|
172
|
+
throw new ValidationError(`Heap with id '${id}' already exists`);
|
|
173
|
+
}
|
|
174
|
+
const heap = isMinHeap ? new MinHeap<bigint>(this.compareValues) : new MaxHeap<bigint>(this.compareValues);
|
|
175
|
+
this.structures.heaps.set(id, heap);
|
|
176
|
+
return heap;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public getHeap(id: string): MinHeap<bigint> | MaxHeap<bigint> {
|
|
180
|
+
const heap = this.structures.heaps.get(id);
|
|
181
|
+
if (!heap) {
|
|
182
|
+
throw new ValidationError(`Heap with id '${id}' not found`);
|
|
183
|
+
}
|
|
184
|
+
return heap;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Special Functions
|
|
188
|
+
public createAckermannStructure(): AckermannStructure {
|
|
189
|
+
return new AckermannStructure();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Formatting and Validation
|
|
193
|
+
public format(value: bigint | string | number, options?: formatting.FormatOptions): string {
|
|
194
|
+
const bigValue = validation.toBigInt(value);
|
|
195
|
+
return formatting.formatBigInt(bigValue, options);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
public validate(value: unknown): boolean {
|
|
199
|
+
try {
|
|
200
|
+
validation.toBigInt(value);
|
|
201
|
+
return true;
|
|
202
|
+
} catch {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Configuration Management
|
|
208
|
+
public updateConfig(newConfig: Partial<HypernumConfig>): void {
|
|
209
|
+
Object.assign(this.config, newConfig);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
public getConfig(): Readonly<Required<HypernumConfig>> {
|
|
213
|
+
return { ...this.config };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Utility Functions
|
|
217
|
+
private compareValues(a: bigint, b: bigint): -1 | 0 | 1 {
|
|
218
|
+
if (a < b) return -1;
|
|
219
|
+
if (a > b) return 1;
|
|
220
|
+
return 0;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Cleanup
|
|
224
|
+
public dispose(): void {
|
|
225
|
+
this.structures.arrays.clear();
|
|
226
|
+
this.structures.trees.clear();
|
|
227
|
+
this.structures.heaps.clear();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Export additional types and utilities
|
|
232
|
+
export {
|
|
233
|
+
HypernumError,
|
|
234
|
+
ValidationError,
|
|
235
|
+
OverflowError,
|
|
236
|
+
precision,
|
|
237
|
+
formatting,
|
|
238
|
+
validation
|
|
239
|
+
};
|
|
240
|
+
|
|
241
241
|
export default Hypernum;
|
package/src/core/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './config';
|
|
2
|
-
export * from './errors';
|
|
3
|
-
export * from './constants';
|
|
4
|
-
export { Hypernum } from './hypernum';
|
|
1
|
+
export * from './config';
|
|
2
|
+
export * from './errors';
|
|
3
|
+
export * from './constants';
|
|
4
|
+
export { Hypernum } from './hypernum';
|
|
5
5
|
export * from './common';
|