@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/types/common.d.ts
CHANGED
|
@@ -1,357 +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;
|
|
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
357
|
}
|