@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/config.ts
CHANGED
|
@@ -1,393 +1,393 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration type definitions for Hypernum library
|
|
3
|
-
* Defines all configuration options and their default values
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { RoundingMode } from '../utils/precision';
|
|
7
|
-
import {
|
|
8
|
-
FormatOptions,
|
|
9
|
-
DebugConfig,
|
|
10
|
-
CacheConfig,
|
|
11
|
-
MathConstantsConfig
|
|
12
|
-
} from './common';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Basic configuration options for simple usage
|
|
16
|
-
*/
|
|
17
|
-
export interface BasicConfig {
|
|
18
|
-
/** Decimal precision for operations */
|
|
19
|
-
precision?: number;
|
|
20
|
-
/** Rounding mode for decimal operations */
|
|
21
|
-
roundingMode?: RoundingMode;
|
|
22
|
-
/** Whether to check for overflow */
|
|
23
|
-
checkOverflow?: boolean;
|
|
24
|
-
/** Maximum allowed computation steps */
|
|
25
|
-
maxSteps?: number;
|
|
26
|
-
/** Enable debug mode */
|
|
27
|
-
debug?: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Configuration for arithmetic operations
|
|
32
|
-
*/
|
|
33
|
-
export interface ArithmeticConfig {
|
|
34
|
-
/** Default precision for decimal operations */
|
|
35
|
-
defaultPrecision: number;
|
|
36
|
-
/** Default rounding mode */
|
|
37
|
-
defaultRoundingMode: RoundingMode;
|
|
38
|
-
/** Whether to check for overflow by default */
|
|
39
|
-
checkOverflow: boolean;
|
|
40
|
-
/** Maximum steps for iterative calculations */
|
|
41
|
-
maxComputationSteps: number;
|
|
42
|
-
/** Configure automatic precision adjustment */
|
|
43
|
-
autoPrecision: {
|
|
44
|
-
enabled: boolean;
|
|
45
|
-
maxPrecision: number;
|
|
46
|
-
minPrecision: number;
|
|
47
|
-
};
|
|
48
|
-
/** Constants calculation configuration */
|
|
49
|
-
constants: MathConstantsConfig;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Configuration for data structures
|
|
54
|
-
*/
|
|
55
|
-
export interface DataStructuresConfig {
|
|
56
|
-
/** Array configuration */
|
|
57
|
-
array: {
|
|
58
|
-
initialCapacity: number;
|
|
59
|
-
growthFactor: number;
|
|
60
|
-
maxSize: number;
|
|
61
|
-
};
|
|
62
|
-
/** Tree configuration */
|
|
63
|
-
tree: {
|
|
64
|
-
maxDepth: number;
|
|
65
|
-
autoBalance: boolean;
|
|
66
|
-
nodeLimit: number;
|
|
67
|
-
};
|
|
68
|
-
/** Heap configuration */
|
|
69
|
-
heap: {
|
|
70
|
-
initialCapacity: number;
|
|
71
|
-
growthPolicy: 'double' | 'linear' | 'fibonacci';
|
|
72
|
-
validatePropertyOnOperation: boolean;
|
|
73
|
-
};
|
|
74
|
-
/** Cache configuration */
|
|
75
|
-
cache: CacheConfig & {
|
|
76
|
-
enabled: boolean;
|
|
77
|
-
persistToDisk: boolean;
|
|
78
|
-
compressionEnabled: boolean;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Configuration for number formatting
|
|
84
|
-
*/
|
|
85
|
-
export interface FormattingConfig extends FormatOptions {
|
|
86
|
-
/** Scientific notation configuration */
|
|
87
|
-
scientific: {
|
|
88
|
-
/** Minimum exponent to trigger scientific notation */
|
|
89
|
-
minExponent: number;
|
|
90
|
-
/** Maximum significant digits */
|
|
91
|
-
maxSignificantDigits: number;
|
|
92
|
-
/** Exponent separator character */
|
|
93
|
-
exponentSeparator: string;
|
|
94
|
-
};
|
|
95
|
-
/** Engineering notation configuration */
|
|
96
|
-
engineering: {
|
|
97
|
-
/** Use SI prefixes */
|
|
98
|
-
useSIPrefixes: boolean;
|
|
99
|
-
/** Custom unit definitions */
|
|
100
|
-
customUnits?: Map<number, string>;
|
|
101
|
-
};
|
|
102
|
-
/** Localization settings */
|
|
103
|
-
localization: {
|
|
104
|
-
/** Locale identifier */
|
|
105
|
-
locale: string;
|
|
106
|
-
/** Custom number formatting */
|
|
107
|
-
numberFormat?: Intl.NumberFormatOptions;
|
|
108
|
-
/** Use locale-specific grouping */
|
|
109
|
-
useLocaleGrouping: boolean;
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Configuration for performance monitoring
|
|
115
|
-
*/
|
|
116
|
-
export interface PerformanceConfig {
|
|
117
|
-
/** Enable performance tracking */
|
|
118
|
-
enableTracking: boolean;
|
|
119
|
-
/** Sampling rate for metrics (0-1) */
|
|
120
|
-
samplingRate: number;
|
|
121
|
-
/** Performance thresholds */
|
|
122
|
-
thresholds: {
|
|
123
|
-
/** Warning threshold in milliseconds */
|
|
124
|
-
warnThresholdMs: number;
|
|
125
|
-
/** Error threshold in milliseconds */
|
|
126
|
-
errorThresholdMs: number;
|
|
127
|
-
/** Maximum allowed memory usage in bytes */
|
|
128
|
-
maxMemoryBytes: number;
|
|
129
|
-
};
|
|
130
|
-
/** Metrics collection configuration */
|
|
131
|
-
metrics: {
|
|
132
|
-
/** Enable detailed operation timing */
|
|
133
|
-
timing: boolean;
|
|
134
|
-
/** Track memory usage */
|
|
135
|
-
memory: boolean;
|
|
136
|
-
/** Track cache performance */
|
|
137
|
-
cache: boolean;
|
|
138
|
-
/** Custom metrics to track */
|
|
139
|
-
custom?: Map<string, (operation: any) => number>;
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Feature flags for optional functionality
|
|
145
|
-
*/
|
|
146
|
-
export interface FeatureFlags {
|
|
147
|
-
/** Enable experimental features */
|
|
148
|
-
experimentalFeatures: boolean;
|
|
149
|
-
/** Use WebAssembly implementations when available */
|
|
150
|
-
useWasm: boolean;
|
|
151
|
-
/** Enable worker thread support */
|
|
152
|
-
workerThreads: boolean;
|
|
153
|
-
/** Enable SharedArrayBuffer support */
|
|
154
|
-
sharedArrayBuffer: boolean;
|
|
155
|
-
/** Enable BigInt64Array support */
|
|
156
|
-
bigIntTypedArrays: boolean;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Full configuration interface with all options
|
|
161
|
-
*/
|
|
162
|
-
export interface FullConfig {
|
|
163
|
-
/** Arithmetic operation configuration */
|
|
164
|
-
arithmetic: ArithmeticConfig;
|
|
165
|
-
/** Data structure configuration */
|
|
166
|
-
dataStructures: DataStructuresConfig;
|
|
167
|
-
/** Formatting configuration */
|
|
168
|
-
formatting: FormattingConfig;
|
|
169
|
-
/** Performance configuration */
|
|
170
|
-
performance: PerformanceConfig;
|
|
171
|
-
/** Debug configuration */
|
|
172
|
-
debug: DebugConfig;
|
|
173
|
-
/** Feature flags */
|
|
174
|
-
features: FeatureFlags;
|
|
175
|
-
/** Custom configuration options */
|
|
176
|
-
custom?: Map<string, any>;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Converts FullConfig to BasicConfig if necessary
|
|
181
|
-
*/
|
|
182
|
-
export function convertToBasicConfig(config: HypernumConfig): BasicConfig {
|
|
183
|
-
if (isBasicConfig(config)) {
|
|
184
|
-
return config;
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
precision: config.arithmetic.defaultPrecision,
|
|
188
|
-
roundingMode: config.arithmetic.defaultRoundingMode,
|
|
189
|
-
checkOverflow: config.arithmetic.checkOverflow,
|
|
190
|
-
maxSteps: config.arithmetic.maxComputationSteps,
|
|
191
|
-
debug: config.debug.verbose
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Combined configuration type that can be either basic or full
|
|
197
|
-
*/
|
|
198
|
-
export type HypernumConfig = BasicConfig | FullConfig;
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Default configuration values for basic config
|
|
202
|
-
*/
|
|
203
|
-
export const DEFAULT_BASIC_CONFIG: Required<BasicConfig> = {
|
|
204
|
-
precision: 0,
|
|
205
|
-
roundingMode: RoundingMode.HALF_EVEN,
|
|
206
|
-
checkOverflow: true,
|
|
207
|
-
maxSteps: 1000,
|
|
208
|
-
debug: false
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Full default configuration values
|
|
213
|
-
*/
|
|
214
|
-
export const DEFAULT_FULL_CONFIG: FullConfig = {
|
|
215
|
-
arithmetic: {
|
|
216
|
-
defaultPrecision: 0,
|
|
217
|
-
defaultRoundingMode: RoundingMode.HALF_EVEN,
|
|
218
|
-
checkOverflow: true,
|
|
219
|
-
maxComputationSteps: 1000,
|
|
220
|
-
autoPrecision: {
|
|
221
|
-
enabled: true,
|
|
222
|
-
maxPrecision: 100,
|
|
223
|
-
minPrecision: 0
|
|
224
|
-
},
|
|
225
|
-
constants: {
|
|
226
|
-
precision: 50,
|
|
227
|
-
cache: true,
|
|
228
|
-
algorithm: 'series'
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
dataStructures: {
|
|
232
|
-
array: {
|
|
233
|
-
initialCapacity: 16,
|
|
234
|
-
growthFactor: 2,
|
|
235
|
-
maxSize: 1_000_000
|
|
236
|
-
},
|
|
237
|
-
tree: {
|
|
238
|
-
maxDepth: 1000,
|
|
239
|
-
autoBalance: true,
|
|
240
|
-
nodeLimit: 1_000_000
|
|
241
|
-
},
|
|
242
|
-
heap: {
|
|
243
|
-
initialCapacity: 16,
|
|
244
|
-
growthPolicy: 'double',
|
|
245
|
-
validatePropertyOnOperation: true
|
|
246
|
-
},
|
|
247
|
-
cache: {
|
|
248
|
-
enabled: true,
|
|
249
|
-
maxSize: 1000,
|
|
250
|
-
ttl: 3600000, // 1 hour
|
|
251
|
-
evictionPolicy: 'LRU',
|
|
252
|
-
persistToDisk: false,
|
|
253
|
-
compressionEnabled: false
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
formatting: {
|
|
257
|
-
notation: 'standard',
|
|
258
|
-
precision: 0,
|
|
259
|
-
grouping: true,
|
|
260
|
-
groupSize: 3,
|
|
261
|
-
decimalSeparator: '.',
|
|
262
|
-
groupSeparator: ',',
|
|
263
|
-
uppercase: false,
|
|
264
|
-
scientific: {
|
|
265
|
-
minExponent: 6,
|
|
266
|
-
maxSignificantDigits: 6,
|
|
267
|
-
exponentSeparator: 'e'
|
|
268
|
-
},
|
|
269
|
-
engineering: {
|
|
270
|
-
useSIPrefixes: true
|
|
271
|
-
},
|
|
272
|
-
localization: {
|
|
273
|
-
locale: 'en-US',
|
|
274
|
-
useLocaleGrouping: false
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
performance: {
|
|
278
|
-
enableTracking: false,
|
|
279
|
-
samplingRate: 0.1,
|
|
280
|
-
thresholds: {
|
|
281
|
-
warnThresholdMs: 100,
|
|
282
|
-
errorThresholdMs: 1000,
|
|
283
|
-
maxMemoryBytes: 1024 * 1024 * 1024 // 1GB
|
|
284
|
-
},
|
|
285
|
-
metrics: {
|
|
286
|
-
timing: true,
|
|
287
|
-
memory: true,
|
|
288
|
-
cache: true
|
|
289
|
-
}
|
|
290
|
-
},
|
|
291
|
-
debug: {
|
|
292
|
-
verbose: false,
|
|
293
|
-
trackPerformance: false,
|
|
294
|
-
logLevel: 'error'
|
|
295
|
-
},
|
|
296
|
-
features: {
|
|
297
|
-
experimentalFeatures: false,
|
|
298
|
-
useWasm: false,
|
|
299
|
-
workerThreads: false,
|
|
300
|
-
sharedArrayBuffer: false,
|
|
301
|
-
bigIntTypedArrays: true
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Type guard to check if config is a full configuration
|
|
307
|
-
*/
|
|
308
|
-
export function isFullConfig(config: HypernumConfig): config is FullConfig {
|
|
309
|
-
return 'arithmetic' in config && 'dataStructures' in config;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Type guard to check if config is a basic configuration
|
|
314
|
-
*/
|
|
315
|
-
export function isBasicConfig(config: HypernumConfig): config is BasicConfig {
|
|
316
|
-
return !isFullConfig(config);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Validates configuration values
|
|
321
|
-
*/
|
|
322
|
-
export function validateConfig(config: HypernumConfig): void {
|
|
323
|
-
if (isFullConfig(config)) {
|
|
324
|
-
validateFullConfig(config);
|
|
325
|
-
} else {
|
|
326
|
-
validateBasicConfig(config);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Validates basic configuration values
|
|
332
|
-
*/
|
|
333
|
-
function validateBasicConfig(config: BasicConfig): void {
|
|
334
|
-
if (config.precision !== undefined && config.precision < 0) {
|
|
335
|
-
throw new Error('Precision cannot be negative');
|
|
336
|
-
}
|
|
337
|
-
if (config.maxSteps !== undefined && config.maxSteps <= 0) {
|
|
338
|
-
throw new Error('Maximum steps must be positive');
|
|
339
|
-
}
|
|
340
|
-
if (config.debug !== undefined && typeof config.debug !== 'boolean') {
|
|
341
|
-
throw new Error('Debug flag must be a boolean');
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Validates full configuration values
|
|
347
|
-
*/
|
|
348
|
-
function validateFullConfig(config: FullConfig): void {
|
|
349
|
-
if (config.arithmetic.defaultPrecision < 0) {
|
|
350
|
-
throw new Error('Default precision cannot be negative');
|
|
351
|
-
}
|
|
352
|
-
if (config.arithmetic.maxComputationSteps <= 0) {
|
|
353
|
-
throw new Error('Max computation steps must be positive');
|
|
354
|
-
}
|
|
355
|
-
if (config.dataStructures.array.initialCapacity <= 0) {
|
|
356
|
-
throw new Error('Initial capacity must be positive');
|
|
357
|
-
}
|
|
358
|
-
if (config.dataStructures.array.growthFactor <= 1) {
|
|
359
|
-
throw new Error('Growth factor must be greater than 1');
|
|
360
|
-
}
|
|
361
|
-
if (config.performance.samplingRate < 0 || config.performance.samplingRate > 1) {
|
|
362
|
-
throw new Error('Sampling rate must be between 0 and 1');
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Merges configuration with appropriate defaults
|
|
368
|
-
*/
|
|
369
|
-
export function mergeConfig(custom: Partial<HypernumConfig> = {}): HypernumConfig {
|
|
370
|
-
if (isFullConfig(custom as FullConfig)) {
|
|
371
|
-
const fullConfig = custom as FullConfig;
|
|
372
|
-
return {
|
|
373
|
-
...DEFAULT_FULL_CONFIG,
|
|
374
|
-
...fullConfig,
|
|
375
|
-
arithmetic: { ...DEFAULT_FULL_CONFIG.arithmetic, ...fullConfig.arithmetic },
|
|
376
|
-
dataStructures: { ...DEFAULT_FULL_CONFIG.dataStructures, ...fullConfig.dataStructures },
|
|
377
|
-
formatting: { ...DEFAULT_FULL_CONFIG.formatting, ...fullConfig.formatting },
|
|
378
|
-
performance: { ...DEFAULT_FULL_CONFIG.performance, ...fullConfig.performance },
|
|
379
|
-
debug: { ...DEFAULT_FULL_CONFIG.debug, ...fullConfig.debug },
|
|
380
|
-
features: { ...DEFAULT_FULL_CONFIG.features, ...fullConfig.features }
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const basicConfig: BasicConfig = {
|
|
385
|
-
precision: (custom as Partial<BasicConfig>).precision ?? DEFAULT_BASIC_CONFIG.precision,
|
|
386
|
-
roundingMode: (custom as Partial<BasicConfig>).roundingMode ?? DEFAULT_BASIC_CONFIG.roundingMode,
|
|
387
|
-
checkOverflow: (custom as Partial<BasicConfig>).checkOverflow ?? DEFAULT_BASIC_CONFIG.checkOverflow,
|
|
388
|
-
maxSteps: (custom as Partial<BasicConfig>).maxSteps ?? DEFAULT_BASIC_CONFIG.maxSteps,
|
|
389
|
-
debug: (custom as Partial<BasicConfig>).debug ?? DEFAULT_BASIC_CONFIG.debug
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
return basicConfig;
|
|
1
|
+
/**
|
|
2
|
+
* Configuration type definitions for Hypernum library
|
|
3
|
+
* Defines all configuration options and their default values
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { RoundingMode } from '../utils/precision';
|
|
7
|
+
import {
|
|
8
|
+
FormatOptions,
|
|
9
|
+
DebugConfig,
|
|
10
|
+
CacheConfig,
|
|
11
|
+
MathConstantsConfig
|
|
12
|
+
} from './common';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Basic configuration options for simple usage
|
|
16
|
+
*/
|
|
17
|
+
export interface BasicConfig {
|
|
18
|
+
/** Decimal precision for operations */
|
|
19
|
+
precision?: number;
|
|
20
|
+
/** Rounding mode for decimal operations */
|
|
21
|
+
roundingMode?: RoundingMode;
|
|
22
|
+
/** Whether to check for overflow */
|
|
23
|
+
checkOverflow?: boolean;
|
|
24
|
+
/** Maximum allowed computation steps */
|
|
25
|
+
maxSteps?: number;
|
|
26
|
+
/** Enable debug mode */
|
|
27
|
+
debug?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Configuration for arithmetic operations
|
|
32
|
+
*/
|
|
33
|
+
export interface ArithmeticConfig {
|
|
34
|
+
/** Default precision for decimal operations */
|
|
35
|
+
defaultPrecision: number;
|
|
36
|
+
/** Default rounding mode */
|
|
37
|
+
defaultRoundingMode: RoundingMode;
|
|
38
|
+
/** Whether to check for overflow by default */
|
|
39
|
+
checkOverflow: boolean;
|
|
40
|
+
/** Maximum steps for iterative calculations */
|
|
41
|
+
maxComputationSteps: number;
|
|
42
|
+
/** Configure automatic precision adjustment */
|
|
43
|
+
autoPrecision: {
|
|
44
|
+
enabled: boolean;
|
|
45
|
+
maxPrecision: number;
|
|
46
|
+
minPrecision: number;
|
|
47
|
+
};
|
|
48
|
+
/** Constants calculation configuration */
|
|
49
|
+
constants: MathConstantsConfig;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Configuration for data structures
|
|
54
|
+
*/
|
|
55
|
+
export interface DataStructuresConfig {
|
|
56
|
+
/** Array configuration */
|
|
57
|
+
array: {
|
|
58
|
+
initialCapacity: number;
|
|
59
|
+
growthFactor: number;
|
|
60
|
+
maxSize: number;
|
|
61
|
+
};
|
|
62
|
+
/** Tree configuration */
|
|
63
|
+
tree: {
|
|
64
|
+
maxDepth: number;
|
|
65
|
+
autoBalance: boolean;
|
|
66
|
+
nodeLimit: number;
|
|
67
|
+
};
|
|
68
|
+
/** Heap configuration */
|
|
69
|
+
heap: {
|
|
70
|
+
initialCapacity: number;
|
|
71
|
+
growthPolicy: 'double' | 'linear' | 'fibonacci';
|
|
72
|
+
validatePropertyOnOperation: boolean;
|
|
73
|
+
};
|
|
74
|
+
/** Cache configuration */
|
|
75
|
+
cache: CacheConfig & {
|
|
76
|
+
enabled: boolean;
|
|
77
|
+
persistToDisk: boolean;
|
|
78
|
+
compressionEnabled: boolean;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Configuration for number formatting
|
|
84
|
+
*/
|
|
85
|
+
export interface FormattingConfig extends FormatOptions {
|
|
86
|
+
/** Scientific notation configuration */
|
|
87
|
+
scientific: {
|
|
88
|
+
/** Minimum exponent to trigger scientific notation */
|
|
89
|
+
minExponent: number;
|
|
90
|
+
/** Maximum significant digits */
|
|
91
|
+
maxSignificantDigits: number;
|
|
92
|
+
/** Exponent separator character */
|
|
93
|
+
exponentSeparator: string;
|
|
94
|
+
};
|
|
95
|
+
/** Engineering notation configuration */
|
|
96
|
+
engineering: {
|
|
97
|
+
/** Use SI prefixes */
|
|
98
|
+
useSIPrefixes: boolean;
|
|
99
|
+
/** Custom unit definitions */
|
|
100
|
+
customUnits?: Map<number, string>;
|
|
101
|
+
};
|
|
102
|
+
/** Localization settings */
|
|
103
|
+
localization: {
|
|
104
|
+
/** Locale identifier */
|
|
105
|
+
locale: string;
|
|
106
|
+
/** Custom number formatting */
|
|
107
|
+
numberFormat?: Intl.NumberFormatOptions;
|
|
108
|
+
/** Use locale-specific grouping */
|
|
109
|
+
useLocaleGrouping: boolean;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Configuration for performance monitoring
|
|
115
|
+
*/
|
|
116
|
+
export interface PerformanceConfig {
|
|
117
|
+
/** Enable performance tracking */
|
|
118
|
+
enableTracking: boolean;
|
|
119
|
+
/** Sampling rate for metrics (0-1) */
|
|
120
|
+
samplingRate: number;
|
|
121
|
+
/** Performance thresholds */
|
|
122
|
+
thresholds: {
|
|
123
|
+
/** Warning threshold in milliseconds */
|
|
124
|
+
warnThresholdMs: number;
|
|
125
|
+
/** Error threshold in milliseconds */
|
|
126
|
+
errorThresholdMs: number;
|
|
127
|
+
/** Maximum allowed memory usage in bytes */
|
|
128
|
+
maxMemoryBytes: number;
|
|
129
|
+
};
|
|
130
|
+
/** Metrics collection configuration */
|
|
131
|
+
metrics: {
|
|
132
|
+
/** Enable detailed operation timing */
|
|
133
|
+
timing: boolean;
|
|
134
|
+
/** Track memory usage */
|
|
135
|
+
memory: boolean;
|
|
136
|
+
/** Track cache performance */
|
|
137
|
+
cache: boolean;
|
|
138
|
+
/** Custom metrics to track */
|
|
139
|
+
custom?: Map<string, (operation: any) => number>;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Feature flags for optional functionality
|
|
145
|
+
*/
|
|
146
|
+
export interface FeatureFlags {
|
|
147
|
+
/** Enable experimental features */
|
|
148
|
+
experimentalFeatures: boolean;
|
|
149
|
+
/** Use WebAssembly implementations when available */
|
|
150
|
+
useWasm: boolean;
|
|
151
|
+
/** Enable worker thread support */
|
|
152
|
+
workerThreads: boolean;
|
|
153
|
+
/** Enable SharedArrayBuffer support */
|
|
154
|
+
sharedArrayBuffer: boolean;
|
|
155
|
+
/** Enable BigInt64Array support */
|
|
156
|
+
bigIntTypedArrays: boolean;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Full configuration interface with all options
|
|
161
|
+
*/
|
|
162
|
+
export interface FullConfig {
|
|
163
|
+
/** Arithmetic operation configuration */
|
|
164
|
+
arithmetic: ArithmeticConfig;
|
|
165
|
+
/** Data structure configuration */
|
|
166
|
+
dataStructures: DataStructuresConfig;
|
|
167
|
+
/** Formatting configuration */
|
|
168
|
+
formatting: FormattingConfig;
|
|
169
|
+
/** Performance configuration */
|
|
170
|
+
performance: PerformanceConfig;
|
|
171
|
+
/** Debug configuration */
|
|
172
|
+
debug: DebugConfig;
|
|
173
|
+
/** Feature flags */
|
|
174
|
+
features: FeatureFlags;
|
|
175
|
+
/** Custom configuration options */
|
|
176
|
+
custom?: Map<string, any>;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Converts FullConfig to BasicConfig if necessary
|
|
181
|
+
*/
|
|
182
|
+
export function convertToBasicConfig(config: HypernumConfig): BasicConfig {
|
|
183
|
+
if (isBasicConfig(config)) {
|
|
184
|
+
return config;
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
precision: config.arithmetic.defaultPrecision,
|
|
188
|
+
roundingMode: config.arithmetic.defaultRoundingMode,
|
|
189
|
+
checkOverflow: config.arithmetic.checkOverflow,
|
|
190
|
+
maxSteps: config.arithmetic.maxComputationSteps,
|
|
191
|
+
debug: config.debug.verbose
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Combined configuration type that can be either basic or full
|
|
197
|
+
*/
|
|
198
|
+
export type HypernumConfig = BasicConfig | FullConfig;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Default configuration values for basic config
|
|
202
|
+
*/
|
|
203
|
+
export const DEFAULT_BASIC_CONFIG: Required<BasicConfig> = {
|
|
204
|
+
precision: 0,
|
|
205
|
+
roundingMode: RoundingMode.HALF_EVEN,
|
|
206
|
+
checkOverflow: true,
|
|
207
|
+
maxSteps: 1000,
|
|
208
|
+
debug: false
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Full default configuration values
|
|
213
|
+
*/
|
|
214
|
+
export const DEFAULT_FULL_CONFIG: FullConfig = {
|
|
215
|
+
arithmetic: {
|
|
216
|
+
defaultPrecision: 0,
|
|
217
|
+
defaultRoundingMode: RoundingMode.HALF_EVEN,
|
|
218
|
+
checkOverflow: true,
|
|
219
|
+
maxComputationSteps: 1000,
|
|
220
|
+
autoPrecision: {
|
|
221
|
+
enabled: true,
|
|
222
|
+
maxPrecision: 100,
|
|
223
|
+
minPrecision: 0
|
|
224
|
+
},
|
|
225
|
+
constants: {
|
|
226
|
+
precision: 50,
|
|
227
|
+
cache: true,
|
|
228
|
+
algorithm: 'series'
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
dataStructures: {
|
|
232
|
+
array: {
|
|
233
|
+
initialCapacity: 16,
|
|
234
|
+
growthFactor: 2,
|
|
235
|
+
maxSize: 1_000_000
|
|
236
|
+
},
|
|
237
|
+
tree: {
|
|
238
|
+
maxDepth: 1000,
|
|
239
|
+
autoBalance: true,
|
|
240
|
+
nodeLimit: 1_000_000
|
|
241
|
+
},
|
|
242
|
+
heap: {
|
|
243
|
+
initialCapacity: 16,
|
|
244
|
+
growthPolicy: 'double',
|
|
245
|
+
validatePropertyOnOperation: true
|
|
246
|
+
},
|
|
247
|
+
cache: {
|
|
248
|
+
enabled: true,
|
|
249
|
+
maxSize: 1000,
|
|
250
|
+
ttl: 3600000, // 1 hour
|
|
251
|
+
evictionPolicy: 'LRU',
|
|
252
|
+
persistToDisk: false,
|
|
253
|
+
compressionEnabled: false
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
formatting: {
|
|
257
|
+
notation: 'standard',
|
|
258
|
+
precision: 0,
|
|
259
|
+
grouping: true,
|
|
260
|
+
groupSize: 3,
|
|
261
|
+
decimalSeparator: '.',
|
|
262
|
+
groupSeparator: ',',
|
|
263
|
+
uppercase: false,
|
|
264
|
+
scientific: {
|
|
265
|
+
minExponent: 6,
|
|
266
|
+
maxSignificantDigits: 6,
|
|
267
|
+
exponentSeparator: 'e'
|
|
268
|
+
},
|
|
269
|
+
engineering: {
|
|
270
|
+
useSIPrefixes: true
|
|
271
|
+
},
|
|
272
|
+
localization: {
|
|
273
|
+
locale: 'en-US',
|
|
274
|
+
useLocaleGrouping: false
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
performance: {
|
|
278
|
+
enableTracking: false,
|
|
279
|
+
samplingRate: 0.1,
|
|
280
|
+
thresholds: {
|
|
281
|
+
warnThresholdMs: 100,
|
|
282
|
+
errorThresholdMs: 1000,
|
|
283
|
+
maxMemoryBytes: 1024 * 1024 * 1024 // 1GB
|
|
284
|
+
},
|
|
285
|
+
metrics: {
|
|
286
|
+
timing: true,
|
|
287
|
+
memory: true,
|
|
288
|
+
cache: true
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
debug: {
|
|
292
|
+
verbose: false,
|
|
293
|
+
trackPerformance: false,
|
|
294
|
+
logLevel: 'error'
|
|
295
|
+
},
|
|
296
|
+
features: {
|
|
297
|
+
experimentalFeatures: false,
|
|
298
|
+
useWasm: false,
|
|
299
|
+
workerThreads: false,
|
|
300
|
+
sharedArrayBuffer: false,
|
|
301
|
+
bigIntTypedArrays: true
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Type guard to check if config is a full configuration
|
|
307
|
+
*/
|
|
308
|
+
export function isFullConfig(config: HypernumConfig): config is FullConfig {
|
|
309
|
+
return 'arithmetic' in config && 'dataStructures' in config;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Type guard to check if config is a basic configuration
|
|
314
|
+
*/
|
|
315
|
+
export function isBasicConfig(config: HypernumConfig): config is BasicConfig {
|
|
316
|
+
return !isFullConfig(config);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Validates configuration values
|
|
321
|
+
*/
|
|
322
|
+
export function validateConfig(config: HypernumConfig): void {
|
|
323
|
+
if (isFullConfig(config)) {
|
|
324
|
+
validateFullConfig(config);
|
|
325
|
+
} else {
|
|
326
|
+
validateBasicConfig(config);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Validates basic configuration values
|
|
332
|
+
*/
|
|
333
|
+
function validateBasicConfig(config: BasicConfig): void {
|
|
334
|
+
if (config.precision !== undefined && config.precision < 0) {
|
|
335
|
+
throw new Error('Precision cannot be negative');
|
|
336
|
+
}
|
|
337
|
+
if (config.maxSteps !== undefined && config.maxSteps <= 0) {
|
|
338
|
+
throw new Error('Maximum steps must be positive');
|
|
339
|
+
}
|
|
340
|
+
if (config.debug !== undefined && typeof config.debug !== 'boolean') {
|
|
341
|
+
throw new Error('Debug flag must be a boolean');
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Validates full configuration values
|
|
347
|
+
*/
|
|
348
|
+
function validateFullConfig(config: FullConfig): void {
|
|
349
|
+
if (config.arithmetic.defaultPrecision < 0) {
|
|
350
|
+
throw new Error('Default precision cannot be negative');
|
|
351
|
+
}
|
|
352
|
+
if (config.arithmetic.maxComputationSteps <= 0) {
|
|
353
|
+
throw new Error('Max computation steps must be positive');
|
|
354
|
+
}
|
|
355
|
+
if (config.dataStructures.array.initialCapacity <= 0) {
|
|
356
|
+
throw new Error('Initial capacity must be positive');
|
|
357
|
+
}
|
|
358
|
+
if (config.dataStructures.array.growthFactor <= 1) {
|
|
359
|
+
throw new Error('Growth factor must be greater than 1');
|
|
360
|
+
}
|
|
361
|
+
if (config.performance.samplingRate < 0 || config.performance.samplingRate > 1) {
|
|
362
|
+
throw new Error('Sampling rate must be between 0 and 1');
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Merges configuration with appropriate defaults
|
|
368
|
+
*/
|
|
369
|
+
export function mergeConfig(custom: Partial<HypernumConfig> = {}): HypernumConfig {
|
|
370
|
+
if (isFullConfig(custom as FullConfig)) {
|
|
371
|
+
const fullConfig = custom as FullConfig;
|
|
372
|
+
return {
|
|
373
|
+
...DEFAULT_FULL_CONFIG,
|
|
374
|
+
...fullConfig,
|
|
375
|
+
arithmetic: { ...DEFAULT_FULL_CONFIG.arithmetic, ...fullConfig.arithmetic },
|
|
376
|
+
dataStructures: { ...DEFAULT_FULL_CONFIG.dataStructures, ...fullConfig.dataStructures },
|
|
377
|
+
formatting: { ...DEFAULT_FULL_CONFIG.formatting, ...fullConfig.formatting },
|
|
378
|
+
performance: { ...DEFAULT_FULL_CONFIG.performance, ...fullConfig.performance },
|
|
379
|
+
debug: { ...DEFAULT_FULL_CONFIG.debug, ...fullConfig.debug },
|
|
380
|
+
features: { ...DEFAULT_FULL_CONFIG.features, ...fullConfig.features }
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const basicConfig: BasicConfig = {
|
|
385
|
+
precision: (custom as Partial<BasicConfig>).precision ?? DEFAULT_BASIC_CONFIG.precision,
|
|
386
|
+
roundingMode: (custom as Partial<BasicConfig>).roundingMode ?? DEFAULT_BASIC_CONFIG.roundingMode,
|
|
387
|
+
checkOverflow: (custom as Partial<BasicConfig>).checkOverflow ?? DEFAULT_BASIC_CONFIG.checkOverflow,
|
|
388
|
+
maxSteps: (custom as Partial<BasicConfig>).maxSteps ?? DEFAULT_BASIC_CONFIG.maxSteps,
|
|
389
|
+
debug: (custom as Partial<BasicConfig>).debug ?? DEFAULT_BASIC_CONFIG.debug
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
return basicConfig;
|
|
393
393
|
}
|