@obinexusmk2/hypernum 0.1.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/LICENSE +21 -0
- package/README.md +256 -0
- package/dist/index.cjs +3425 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1449 -0
- package/dist/index.js +3284 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +8 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/types/config/config-loader.d.ts +56 -0
- package/dist/types/config/config-loader.d.ts.map +1 -0
- package/dist/types/config/config-parser.d.ts +28 -0
- package/dist/types/config/config-parser.d.ts.map +1 -0
- package/dist/types/config/config-resolver.d.ts +21 -0
- package/dist/types/config/config-resolver.d.ts.map +1 -0
- package/dist/types/config/config-source.d.ts +27 -0
- package/dist/types/config/config-source.d.ts.map +1 -0
- package/dist/types/config/index.d.ts +68 -0
- package/dist/types/config/index.d.ts.map +1 -0
- package/dist/types/core/common.d.ts +169 -0
- package/dist/types/core/common.d.ts.map +1 -0
- package/dist/types/core/config.d.ts +197 -0
- package/dist/types/core/config.d.ts.map +1 -0
- package/dist/types/core/constants.d.ts +88 -0
- package/dist/types/core/constants.d.ts.map +1 -0
- package/dist/types/core/errors.d.ts +97 -0
- package/dist/types/core/errors.d.ts.map +1 -0
- package/dist/types/core/hypernum.d.ts +60 -0
- package/dist/types/core/hypernum.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +6 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +33 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/operations/arithmetic.d.ts +72 -0
- package/dist/types/operations/arithmetic.d.ts.map +1 -0
- package/dist/types/operations/bitwise.d.ts +98 -0
- package/dist/types/operations/bitwise.d.ts.map +1 -0
- package/dist/types/operations/comparison.d.ts +94 -0
- package/dist/types/operations/comparison.d.ts.map +1 -0
- package/dist/types/operations/conversion.d.ts +79 -0
- package/dist/types/operations/conversion.d.ts.map +1 -0
- package/dist/types/operations/factorial.d.ts +58 -0
- package/dist/types/operations/factorial.d.ts.map +1 -0
- package/dist/types/operations/index.d.ts +6 -0
- package/dist/types/operations/index.d.ts.map +1 -0
- package/dist/types/operations/power.d.ts +49 -0
- package/dist/types/operations/power.d.ts.map +1 -0
- package/dist/types/storage/Heap.d.ts +95 -0
- package/dist/types/storage/Heap.d.ts.map +1 -0
- package/dist/types/storage/index.d.ts +2 -0
- package/dist/types/storage/index.d.ts.map +1 -0
- package/dist/types/structures/ackermann.d.ts +74 -0
- package/dist/types/structures/ackermann.d.ts.map +1 -0
- package/dist/types/structures/big-array.d.ts +102 -0
- package/dist/types/structures/big-array.d.ts.map +1 -0
- package/dist/types/structures/index.d.ts +5 -0
- package/dist/types/structures/index.d.ts.map +1 -0
- package/dist/types/structures/number-tree.d.ts +114 -0
- package/dist/types/structures/number-tree.d.ts.map +1 -0
- package/dist/types/structures/power-tower.d.ts +74 -0
- package/dist/types/structures/power-tower.d.ts.map +1 -0
- package/dist/types/utils/formatting.d.ts +45 -0
- package/dist/types/utils/formatting.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +5 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/parser.d.ts +39 -0
- package/dist/types/utils/parser.d.ts.map +1 -0
- package/dist/types/utils/precision.d.ts +57 -0
- package/dist/types/utils/precision.d.ts.map +1 -0
- package/dist/types/utils/validation.d.ts +28 -0
- package/dist/types/utils/validation.d.ts.map +1 -0
- package/package.json +164 -0
- package/rollup.config.js +162 -0
- package/src/config/config-loader.ts +226 -0
- package/src/config/config-parser.ts +161 -0
- package/src/config/config-resolver.ts +52 -0
- package/src/config/config-source.ts +32 -0
- package/src/config/index.ts +159 -0
- package/src/core/common.ts +185 -0
- package/src/core/config.ts +393 -0
- package/src/core/constants.ts +102 -0
- package/src/core/errors.ts +203 -0
- package/src/core/hypernum.ts +241 -0
- package/src/core/index.ts +5 -0
- package/src/index.ts +183 -0
- package/src/operations/arithmetic.ts +333 -0
- package/src/operations/bitwise.ts +367 -0
- package/src/operations/comparison.ts +272 -0
- package/src/operations/conversion.ts +400 -0
- package/src/operations/factorial.ts +279 -0
- package/src/operations/index.ts +5 -0
- package/src/operations/power.ts +316 -0
- package/src/storage/Heap.ts +238 -0
- package/src/storage/index.ts +1 -0
- package/src/structures/ackermann.ts +233 -0
- package/src/structures/big-array.ts +306 -0
- package/src/structures/index.ts +4 -0
- package/src/structures/number-tree.ts +404 -0
- package/src/structures/power-tower.ts +278 -0
- package/src/types/common.d.ts +357 -0
- package/src/types/core.d.ts +161 -0
- package/src/types/index.d.ts +2 -0
- package/src/utils/formatting.ts +246 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/parser.ts +245 -0
- package/src/utils/precision.ts +217 -0
- package/src/utils/validation.ts +183 -0
- package/tsconfig.json +84 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { validateNonNegative, ValidationError, OverflowError } from '../utils/validation';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interface for power tower computation options
|
|
5
|
+
*/
|
|
6
|
+
interface PowerTowerOptions {
|
|
7
|
+
maxHeight?: number;
|
|
8
|
+
maxValue?: bigint;
|
|
9
|
+
checkOverflow?: boolean;
|
|
10
|
+
precision?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Interface for power tower node to track computation state
|
|
15
|
+
*/
|
|
16
|
+
interface PowerTowerNode {
|
|
17
|
+
value: bigint;
|
|
18
|
+
height: number;
|
|
19
|
+
evaluated: boolean;
|
|
20
|
+
previous: PowerTowerNode | null;
|
|
21
|
+
next: PowerTowerNode | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Default options for power tower computations
|
|
26
|
+
*/
|
|
27
|
+
const DEFAULT_OPTIONS: Required<PowerTowerOptions> = {
|
|
28
|
+
maxHeight: 100,
|
|
29
|
+
maxValue: BigInt(Number.MAX_SAFE_INTEGER),
|
|
30
|
+
checkOverflow: true,
|
|
31
|
+
precision: 0
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Class representing a power tower (tetration) computation structure
|
|
36
|
+
* Handles expressions of the form: a↑↑b = a^(a^(a^...)) (b times)
|
|
37
|
+
*/
|
|
38
|
+
export class PowerTower {
|
|
39
|
+
private readonly options: Required<PowerTowerOptions>;
|
|
40
|
+
private head: PowerTowerNode | null;
|
|
41
|
+
private tail: PowerTowerNode | null;
|
|
42
|
+
private size: number;
|
|
43
|
+
|
|
44
|
+
constructor(options: PowerTowerOptions = {}) {
|
|
45
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
46
|
+
this.head = null;
|
|
47
|
+
this.tail = null;
|
|
48
|
+
this.size = 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new power tower node
|
|
53
|
+
*/
|
|
54
|
+
private createNode(value: bigint, height: number): PowerTowerNode {
|
|
55
|
+
return {
|
|
56
|
+
value,
|
|
57
|
+
height,
|
|
58
|
+
evaluated: false,
|
|
59
|
+
previous: null,
|
|
60
|
+
next: null
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Validates power tower height
|
|
66
|
+
*/
|
|
67
|
+
private validateHeight(height: number): void {
|
|
68
|
+
if (height < 0) {
|
|
69
|
+
throw new ValidationError('Height cannot be negative');
|
|
70
|
+
}
|
|
71
|
+
if (height > this.options.maxHeight) {
|
|
72
|
+
throw new ValidationError(`Height exceeds maximum of ${this.options.maxHeight}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Validates value for computation
|
|
78
|
+
*/
|
|
79
|
+
private validateValue(value: bigint): void {
|
|
80
|
+
validateNonNegative(value);
|
|
81
|
+
if (this.options.checkOverflow && value > this.options.maxValue) {
|
|
82
|
+
throw new OverflowError(`Value exceeds maximum of ${this.options.maxValue}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Computes power with overflow checking
|
|
88
|
+
*/
|
|
89
|
+
private computePower(base: bigint, exponent: bigint): bigint {
|
|
90
|
+
if (exponent === BigInt(0)) {
|
|
91
|
+
return BigInt(1);
|
|
92
|
+
}
|
|
93
|
+
if (exponent === BigInt(1)) {
|
|
94
|
+
return base;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let result = base;
|
|
98
|
+
for (let i = BigInt(1); i < exponent; i++) {
|
|
99
|
+
if (this.options.checkOverflow) {
|
|
100
|
+
// Check if next multiplication would overflow
|
|
101
|
+
const next = result * base;
|
|
102
|
+
if (next > this.options.maxValue) {
|
|
103
|
+
throw new OverflowError('Power computation would overflow');
|
|
104
|
+
}
|
|
105
|
+
result = next;
|
|
106
|
+
} else {
|
|
107
|
+
result *= base;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Builds a power tower of specified height with given base
|
|
115
|
+
*/
|
|
116
|
+
public build(base: bigint | number | string, height: number): void {
|
|
117
|
+
this.validateHeight(height);
|
|
118
|
+
const baseValue = typeof base === 'bigint' ? base : BigInt(base);
|
|
119
|
+
this.validateValue(baseValue);
|
|
120
|
+
|
|
121
|
+
this.clear(); // Clear existing tower
|
|
122
|
+
|
|
123
|
+
for (let i = 0; i < height; i++) {
|
|
124
|
+
const node = this.createNode(baseValue, i + 1);
|
|
125
|
+
if (!this.head) {
|
|
126
|
+
this.head = node;
|
|
127
|
+
this.tail = node;
|
|
128
|
+
} else {
|
|
129
|
+
node.previous = this.tail;
|
|
130
|
+
this.tail!.next = node;
|
|
131
|
+
this.tail = node;
|
|
132
|
+
}
|
|
133
|
+
this.size++;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Evaluates the power tower up to specified height
|
|
139
|
+
*/
|
|
140
|
+
public evaluate(height?: number): bigint {
|
|
141
|
+
if (!this.head) {
|
|
142
|
+
return BigInt(1); // Empty tower evaluates to 1
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const targetHeight = height ?? this.size;
|
|
146
|
+
this.validateHeight(targetHeight);
|
|
147
|
+
|
|
148
|
+
let current = this.head;
|
|
149
|
+
let result = current.value;
|
|
150
|
+
let currentHeight = 1;
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
while (current.next && currentHeight < targetHeight) {
|
|
154
|
+
result = this.computePower(current.next.value, result);
|
|
155
|
+
current.evaluated = true;
|
|
156
|
+
current = current.next;
|
|
157
|
+
currentHeight++;
|
|
158
|
+
}
|
|
159
|
+
current.evaluated = true;
|
|
160
|
+
return result;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
if (error instanceof OverflowError) {
|
|
163
|
+
// Mark nodes up to current height as evaluated
|
|
164
|
+
let node = this.head;
|
|
165
|
+
while (node !== current) {
|
|
166
|
+
node.evaluated = true;
|
|
167
|
+
node = node.next!;
|
|
168
|
+
}
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Gets the current height of the power tower
|
|
177
|
+
*/
|
|
178
|
+
public getHeight(): number {
|
|
179
|
+
return this.size;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Checks if the tower can be evaluated to a given height
|
|
184
|
+
*/
|
|
185
|
+
public isComputable(height?: number): boolean {
|
|
186
|
+
try {
|
|
187
|
+
const targetHeight = height ?? this.size;
|
|
188
|
+
this.validateHeight(targetHeight);
|
|
189
|
+
|
|
190
|
+
// Check first few levels without full computation
|
|
191
|
+
let current = this.head;
|
|
192
|
+
let currentHeight = 0;
|
|
193
|
+
|
|
194
|
+
while (current && currentHeight < targetHeight) {
|
|
195
|
+
// Quick check for obvious overflow conditions
|
|
196
|
+
if (current.value > BigInt(4) && currentHeight > 3) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
current = current.next;
|
|
200
|
+
currentHeight++;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Try actual computation with a lower overflow threshold
|
|
204
|
+
const safeOptions = { ...this.options, maxValue: this.options.maxValue >> BigInt(1) };
|
|
205
|
+
const safeTower = new PowerTower(safeOptions);
|
|
206
|
+
safeTower.build(this.head!.value, targetHeight);
|
|
207
|
+
safeTower.evaluate();
|
|
208
|
+
|
|
209
|
+
return true;
|
|
210
|
+
} catch {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Gets the computation state at each level
|
|
217
|
+
*/
|
|
218
|
+
public getState(): { height: number; value: bigint; evaluated: boolean }[] {
|
|
219
|
+
const state = [];
|
|
220
|
+
let current = this.head;
|
|
221
|
+
|
|
222
|
+
while (current) {
|
|
223
|
+
state.push({
|
|
224
|
+
height: current.height,
|
|
225
|
+
value: current.value,
|
|
226
|
+
evaluated: current.evaluated
|
|
227
|
+
});
|
|
228
|
+
current = current.next;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return state;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Clears the power tower
|
|
236
|
+
*/
|
|
237
|
+
public clear(): void {
|
|
238
|
+
this.head = null;
|
|
239
|
+
this.tail = null;
|
|
240
|
+
this.size = 0;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Gets the maximum computationally feasible height for a given base
|
|
245
|
+
*/
|
|
246
|
+
public static getMaxFeasibleHeight(base: bigint | number | string): number {
|
|
247
|
+
const baseValue = typeof base === 'bigint' ? base : BigInt(base);
|
|
248
|
+
validateNonNegative(baseValue);
|
|
249
|
+
|
|
250
|
+
if (baseValue === BigInt(0)) return 0;
|
|
251
|
+
if (baseValue === BigInt(1)) return Infinity;
|
|
252
|
+
if (baseValue === BigInt(2)) return 4; // 2↑↑4 is already enormous
|
|
253
|
+
if (baseValue === BigInt(3)) return 3; // 3↑↑3 is already astronomical
|
|
254
|
+
if (baseValue === BigInt(4)) return 2;
|
|
255
|
+
return 1; // For bases > 4, only height 1 is reliably computable
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Creates a string representation of the power tower
|
|
260
|
+
*/
|
|
261
|
+
public toString(): string {
|
|
262
|
+
if (!this.head) {
|
|
263
|
+
return "Empty Tower";
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
let result = this.head.value.toString();
|
|
267
|
+
let current = this.head;
|
|
268
|
+
|
|
269
|
+
while (current.next) {
|
|
270
|
+
result = `${current.next.value}^(${result})`;
|
|
271
|
+
current = current.next;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export default PowerTower;
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { RoundingMode } from '../utils/precision';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Valid input types for numeric values
|
|
5
|
+
*/
|
|
6
|
+
export type NumericInput = bigint | string | number;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Result type for operations that may fail
|
|
10
|
+
*/
|
|
11
|
+
export type Result<T> = {
|
|
12
|
+
success: boolean;
|
|
13
|
+
value?: T;
|
|
14
|
+
error?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Base options interface for operations
|
|
19
|
+
*/
|
|
20
|
+
export interface BaseOptions {
|
|
21
|
+
precision?: number;
|
|
22
|
+
roundingMode?: RoundingMode;
|
|
23
|
+
checkOverflow?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Basic configuration options
|
|
28
|
+
*/
|
|
29
|
+
export interface BasicConfig {
|
|
30
|
+
precision?: number;
|
|
31
|
+
roundingMode?: RoundingMode;
|
|
32
|
+
checkOverflow?: boolean;
|
|
33
|
+
maxSteps?: number;
|
|
34
|
+
debug?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Configuration for arithmetic operations
|
|
39
|
+
*/
|
|
40
|
+
export interface ArithmeticConfig {
|
|
41
|
+
defaultPrecision: number;
|
|
42
|
+
defaultRoundingMode: RoundingMode;
|
|
43
|
+
checkOverflow: boolean;
|
|
44
|
+
maxComputationSteps: number;
|
|
45
|
+
autoPrecision: {
|
|
46
|
+
enabled: boolean;
|
|
47
|
+
maxPrecision: number;
|
|
48
|
+
minPrecision: number;
|
|
49
|
+
};
|
|
50
|
+
constants: MathConstantsConfig;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Configuration for data structures
|
|
55
|
+
*/
|
|
56
|
+
export interface DataStructuresConfig {
|
|
57
|
+
array: {
|
|
58
|
+
initialCapacity: number;
|
|
59
|
+
growthFactor: number;
|
|
60
|
+
maxSize: number;
|
|
61
|
+
};
|
|
62
|
+
tree: {
|
|
63
|
+
maxDepth: number;
|
|
64
|
+
autoBalance: boolean;
|
|
65
|
+
nodeLimit: number;
|
|
66
|
+
};
|
|
67
|
+
heap: {
|
|
68
|
+
initialCapacity: number;
|
|
69
|
+
growthPolicy: 'double' | 'linear' | 'fibonacci';
|
|
70
|
+
validatePropertyOnOperation: boolean;
|
|
71
|
+
};
|
|
72
|
+
cache: CacheConfig & {
|
|
73
|
+
enabled: boolean;
|
|
74
|
+
persistToDisk: boolean;
|
|
75
|
+
compressionEnabled: boolean;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Configuration for number formatting
|
|
81
|
+
*/
|
|
82
|
+
export interface FormattingConfig extends FormatOptions {
|
|
83
|
+
scientific: {
|
|
84
|
+
minExponent: number;
|
|
85
|
+
maxSignificantDigits: number;
|
|
86
|
+
exponentSeparator: string;
|
|
87
|
+
};
|
|
88
|
+
engineering: {
|
|
89
|
+
useSIPrefixes: boolean;
|
|
90
|
+
customUnits?: Map<number, string>;
|
|
91
|
+
};
|
|
92
|
+
localization: {
|
|
93
|
+
locale: string;
|
|
94
|
+
numberFormat?: Intl.NumberFormatOptions;
|
|
95
|
+
useLocaleGrouping: boolean;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Configuration for performance monitoring
|
|
101
|
+
*/
|
|
102
|
+
export interface PerformanceConfig {
|
|
103
|
+
enableTracking: boolean;
|
|
104
|
+
samplingRate: number;
|
|
105
|
+
thresholds: {
|
|
106
|
+
warnThresholdMs: number;
|
|
107
|
+
errorThresholdMs: number;
|
|
108
|
+
maxMemoryBytes: number;
|
|
109
|
+
};
|
|
110
|
+
metrics: {
|
|
111
|
+
timing: boolean;
|
|
112
|
+
memory: boolean;
|
|
113
|
+
cache: boolean;
|
|
114
|
+
custom?: Map<string, (operation: any) => number>;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Feature flags for optional functionality
|
|
120
|
+
*/
|
|
121
|
+
export interface FeatureFlags {
|
|
122
|
+
experimentalFeatures: boolean;
|
|
123
|
+
useWasm: boolean;
|
|
124
|
+
workerThreads: boolean;
|
|
125
|
+
sharedArrayBuffer: boolean;
|
|
126
|
+
bigIntTypedArrays: boolean;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Full configuration interface
|
|
131
|
+
*/
|
|
132
|
+
export interface FullConfig {
|
|
133
|
+
arithmetic: ArithmeticConfig;
|
|
134
|
+
dataStructures: DataStructuresConfig;
|
|
135
|
+
formatting: FormattingConfig;
|
|
136
|
+
performance: PerformanceConfig;
|
|
137
|
+
debug: DebugConfig;
|
|
138
|
+
features: FeatureFlags;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Combined configuration type
|
|
143
|
+
*/
|
|
144
|
+
export type HypernumConfig = BasicConfig | FullConfig;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Default basic configuration
|
|
148
|
+
*/
|
|
149
|
+
export const DEFAULT_BASIC_CONFIG: Required<BasicConfig> = {
|
|
150
|
+
precision: 0,
|
|
151
|
+
roundingMode: RoundingMode.HALF_EVEN,
|
|
152
|
+
checkOverflow: true,
|
|
153
|
+
maxSteps: 1000,
|
|
154
|
+
debug: false
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Default full configuration
|
|
159
|
+
*/
|
|
160
|
+
export const DEFAULT_FULL_CONFIG: FullConfig = {
|
|
161
|
+
arithmetic: {
|
|
162
|
+
defaultPrecision: 0,
|
|
163
|
+
defaultRoundingMode: RoundingMode.HALF_EVEN,
|
|
164
|
+
checkOverflow: true,
|
|
165
|
+
maxComputationSteps: 1000,
|
|
166
|
+
autoPrecision: {
|
|
167
|
+
enabled: true,
|
|
168
|
+
maxPrecision: 100,
|
|
169
|
+
minPrecision: 0
|
|
170
|
+
},
|
|
171
|
+
constants: {
|
|
172
|
+
precision: 50,
|
|
173
|
+
cache: true,
|
|
174
|
+
algorithm: 'series'
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
dataStructures: {
|
|
178
|
+
array: {
|
|
179
|
+
initialCapacity: 16,
|
|
180
|
+
growthFactor: 2,
|
|
181
|
+
maxSize: 1_000_000
|
|
182
|
+
},
|
|
183
|
+
tree: {
|
|
184
|
+
maxDepth: 1000,
|
|
185
|
+
autoBalance: true,
|
|
186
|
+
nodeLimit: 1_000_000
|
|
187
|
+
},
|
|
188
|
+
heap: {
|
|
189
|
+
initialCapacity: 16,
|
|
190
|
+
growthPolicy: 'double',
|
|
191
|
+
validatePropertyOnOperation: true
|
|
192
|
+
},
|
|
193
|
+
cache: {
|
|
194
|
+
enabled: true,
|
|
195
|
+
maxSize: 1000,
|
|
196
|
+
ttl: 3600000,
|
|
197
|
+
evictionPolicy: 'LRU',
|
|
198
|
+
persistToDisk: false,
|
|
199
|
+
compressionEnabled: false
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
formatting: {
|
|
203
|
+
notation: 'standard',
|
|
204
|
+
precision: 0,
|
|
205
|
+
grouping: true,
|
|
206
|
+
groupSize: 3,
|
|
207
|
+
decimalSeparator: '.',
|
|
208
|
+
groupSeparator: ',',
|
|
209
|
+
uppercase: false,
|
|
210
|
+
scientific: {
|
|
211
|
+
minExponent: 6,
|
|
212
|
+
maxSignificantDigits: 6,
|
|
213
|
+
exponentSeparator: 'e'
|
|
214
|
+
},
|
|
215
|
+
engineering: {
|
|
216
|
+
useSIPrefixes: true
|
|
217
|
+
},
|
|
218
|
+
localization: {
|
|
219
|
+
locale: 'en-US',
|
|
220
|
+
useLocaleGrouping: false
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
performance: {
|
|
224
|
+
enableTracking: false,
|
|
225
|
+
samplingRate: 0.1,
|
|
226
|
+
thresholds: {
|
|
227
|
+
warnThresholdMs: 100,
|
|
228
|
+
errorThresholdMs: 1000,
|
|
229
|
+
maxMemoryBytes: 1024 * 1024 * 1024
|
|
230
|
+
},
|
|
231
|
+
metrics: {
|
|
232
|
+
timing: true,
|
|
233
|
+
memory: true,
|
|
234
|
+
cache: true
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
debug: {
|
|
238
|
+
verbose: false,
|
|
239
|
+
trackPerformance: false,
|
|
240
|
+
logLevel: 'error'
|
|
241
|
+
},
|
|
242
|
+
features: {
|
|
243
|
+
experimentalFeatures: false,
|
|
244
|
+
useWasm: false,
|
|
245
|
+
workerThreads: false,
|
|
246
|
+
sharedArrayBuffer: false,
|
|
247
|
+
bigIntTypedArrays: true
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Type guard to check if config is a full configuration
|
|
253
|
+
*/
|
|
254
|
+
export function isFullConfig(config: HypernumConfig): config is FullConfig {
|
|
255
|
+
return 'arithmetic' in config && 'dataStructures' in config;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Type guard to check if config is a basic configuration
|
|
260
|
+
*/
|
|
261
|
+
export function isBasicConfig(config: HypernumConfig): config is BasicConfig {
|
|
262
|
+
return !isFullConfig(config);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Validates configuration values
|
|
267
|
+
*/
|
|
268
|
+
export function validateConfig(config: HypernumConfig): void {
|
|
269
|
+
if (isFullConfig(config)) {
|
|
270
|
+
validateFullConfig(config);
|
|
271
|
+
} else {
|
|
272
|
+
validateBasicConfig(config);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Merges configuration with appropriate defaults
|
|
278
|
+
*/
|
|
279
|
+
export function mergeConfig(custom: Partial<HypernumConfig> = {}): HypernumConfig {
|
|
280
|
+
if (isFullConfig(custom)) {
|
|
281
|
+
return {
|
|
282
|
+
...DEFAULT_FULL_CONFIG,
|
|
283
|
+
...custom,
|
|
284
|
+
arithmetic: { ...DEFAULT_FULL_CONFIG.arithmetic, ...custom.arithmetic },
|
|
285
|
+
dataStructures: { ...DEFAULT_FULL_CONFIG.dataStructures, ...custom.dataStructures },
|
|
286
|
+
formatting: { ...DEFAULT_FULL_CONFIG.formatting, ...custom.formatting },
|
|
287
|
+
performance: { ...DEFAULT_FULL_CONFIG.performance, ...custom.performance },
|
|
288
|
+
debug: { ...DEFAULT_FULL_CONFIG.debug, ...custom.debug },
|
|
289
|
+
features: { ...DEFAULT_FULL_CONFIG.features, ...custom.features }
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return {
|
|
294
|
+
...DEFAULT_BASIC_CONFIG,
|
|
295
|
+
...custom
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Additional required types
|
|
300
|
+
export interface FormatOptions {
|
|
301
|
+
notation?: 'standard' | 'scientific' | 'engineering' | 'compact';
|
|
302
|
+
precision?: number;
|
|
303
|
+
grouping?: boolean;
|
|
304
|
+
groupSize?: number;
|
|
305
|
+
decimalSeparator?: string;
|
|
306
|
+
groupSeparator?: string;
|
|
307
|
+
uppercase?: boolean;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export interface CacheConfig {
|
|
311
|
+
maxSize: number;
|
|
312
|
+
ttl?: number;
|
|
313
|
+
evictionPolicy?: 'LRU' | 'LFU' | 'FIFO';
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface MathConstantsConfig {
|
|
317
|
+
precision: number;
|
|
318
|
+
cache?: boolean;
|
|
319
|
+
algorithm?: 'series' | 'iteration' | 'approximation';
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export interface DebugConfig {
|
|
323
|
+
verbose: boolean;
|
|
324
|
+
trackPerformance: boolean;
|
|
325
|
+
logLevel: 'error' | 'warn' | 'info' | 'debug';
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export interface NumericRange {
|
|
329
|
+
min: bigint;
|
|
330
|
+
max: bigint;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export interface OperationStatus {
|
|
334
|
+
success: boolean;
|
|
335
|
+
message: string;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export interface PerformanceMetrics {
|
|
339
|
+
timing: number;
|
|
340
|
+
memory: number;
|
|
341
|
+
cache: number;
|
|
342
|
+
custom: Map<string, number>;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export interface NodeStats {
|
|
346
|
+
depth: number;
|
|
347
|
+
children: number;
|
|
348
|
+
size: number;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export interface OperationOptions {
|
|
352
|
+
precision?: number;
|
|
353
|
+
roundingMode?: RoundingMode;
|
|
354
|
+
checkOverflow?: boolean;
|
|
355
|
+
maxSteps?: number;
|
|
356
|
+
debug?: boolean;
|
|
357
|
+
}
|