@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,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common type definitions for Hypernum library
|
|
3
|
+
* Contains shared types used throughout the library's modules
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { RoundingMode } from '../utils/precision';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Valid input types for numeric values
|
|
10
|
+
*/
|
|
11
|
+
export type NumericInput = bigint | string | number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Result type for operations that may fail
|
|
15
|
+
*/
|
|
16
|
+
export type Result<T> = {
|
|
17
|
+
/** Whether the operation succeeded */
|
|
18
|
+
success: boolean;
|
|
19
|
+
/** The operation result if successful */
|
|
20
|
+
value?: T;
|
|
21
|
+
/** Error message if operation failed */
|
|
22
|
+
error?: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Base options interface for operations
|
|
27
|
+
*/
|
|
28
|
+
export interface BaseOptions {
|
|
29
|
+
/** Decimal precision for operations */
|
|
30
|
+
precision?: number;
|
|
31
|
+
/** Rounding mode for decimal operations */
|
|
32
|
+
roundingMode?: RoundingMode;
|
|
33
|
+
/** Whether to check for overflow */
|
|
34
|
+
checkOverflow?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Options for number formatting
|
|
39
|
+
*/
|
|
40
|
+
export interface FormatOptions extends BaseOptions {
|
|
41
|
+
/** Number notation style */
|
|
42
|
+
notation?: 'standard' | 'scientific' | 'engineering' | 'compact';
|
|
43
|
+
/** Enable grouping separators */
|
|
44
|
+
grouping?: boolean;
|
|
45
|
+
/** Size of digit groups */
|
|
46
|
+
groupSize?: number;
|
|
47
|
+
/** Decimal point character */
|
|
48
|
+
decimalSeparator?: string;
|
|
49
|
+
/** Grouping separator character */
|
|
50
|
+
groupSeparator?: string;
|
|
51
|
+
/** Convert to uppercase (for special formats) */
|
|
52
|
+
uppercase?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Cache configuration
|
|
57
|
+
*/
|
|
58
|
+
export interface CacheConfig {
|
|
59
|
+
/** Maximum number of entries */
|
|
60
|
+
maxSize: number;
|
|
61
|
+
/** Time-to-live in milliseconds */
|
|
62
|
+
ttl?: number;
|
|
63
|
+
/** Eviction policy */
|
|
64
|
+
evictionPolicy?: 'LRU' | 'LFU' | 'FIFO';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Mathematical constants configuration
|
|
69
|
+
*/
|
|
70
|
+
export interface MathConstantsConfig {
|
|
71
|
+
/** Precision for constant calculations */
|
|
72
|
+
precision: number;
|
|
73
|
+
/** Enable caching of computed values */
|
|
74
|
+
cache?: boolean;
|
|
75
|
+
/** Custom calculation algorithm */
|
|
76
|
+
algorithm?: 'series' | 'iteration' | 'approximation';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Debug configuration
|
|
81
|
+
*/
|
|
82
|
+
export interface DebugConfig {
|
|
83
|
+
/** Enable detailed logging */
|
|
84
|
+
verbose: boolean;
|
|
85
|
+
/** Track operation performance */
|
|
86
|
+
trackPerformance: boolean;
|
|
87
|
+
/** Log level */
|
|
88
|
+
logLevel: 'error' | 'warn' | 'info' | 'debug';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Numeric range specification
|
|
93
|
+
*/
|
|
94
|
+
export interface NumericRange {
|
|
95
|
+
/** Start of range (inclusive) */
|
|
96
|
+
start: bigint;
|
|
97
|
+
/** End of range (inclusive) */
|
|
98
|
+
end: bigint;
|
|
99
|
+
/** Step size for iteration */
|
|
100
|
+
step?: bigint;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Operation status monitoring
|
|
105
|
+
*/
|
|
106
|
+
export interface OperationStatus {
|
|
107
|
+
/** Current phase of operation */
|
|
108
|
+
phase: string;
|
|
109
|
+
/** Percentage complete (0-100) */
|
|
110
|
+
progress: number;
|
|
111
|
+
/** Estimated time remaining (ms) */
|
|
112
|
+
estimatedTimeRemaining?: number;
|
|
113
|
+
/** Memory usage in bytes */
|
|
114
|
+
memoryUsage?: number;
|
|
115
|
+
/** Computation steps completed */
|
|
116
|
+
steps: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Performance metrics
|
|
121
|
+
*/
|
|
122
|
+
export interface PerformanceMetrics {
|
|
123
|
+
/** Operation execution time (ms) */
|
|
124
|
+
executionTime: number;
|
|
125
|
+
/** Number of computation steps */
|
|
126
|
+
steps: number;
|
|
127
|
+
/** Peak memory usage (bytes) */
|
|
128
|
+
peakMemory: number;
|
|
129
|
+
/** Cache hit rate (0-1) */
|
|
130
|
+
cacheHitRate?: number;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Comparison function type
|
|
135
|
+
* Returns:
|
|
136
|
+
* -1: a < b
|
|
137
|
+
* 0: a = b
|
|
138
|
+
* 1: a > b
|
|
139
|
+
*/
|
|
140
|
+
export type Comparator<T> = (a: T, b: T) => -1 | 0 | 1;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Progress callback type
|
|
144
|
+
*/
|
|
145
|
+
export type ProgressCallback = (status: OperationStatus) => void;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Error callback type
|
|
149
|
+
*/
|
|
150
|
+
export type ErrorCallback = (error: Error, phase: string) => void;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Value validation function type
|
|
154
|
+
*/
|
|
155
|
+
export type Validator<T> = (value: T) => boolean;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Node statistics interface
|
|
159
|
+
*/
|
|
160
|
+
export interface NodeStats {
|
|
161
|
+
/** Node height in tree */
|
|
162
|
+
height: number;
|
|
163
|
+
/** Subtree size */
|
|
164
|
+
size: number;
|
|
165
|
+
/** Sum of subtree values */
|
|
166
|
+
sum: bigint;
|
|
167
|
+
/** Minimum value in subtree */
|
|
168
|
+
min: bigint;
|
|
169
|
+
/** Maximum value in subtree */
|
|
170
|
+
max: bigint;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Operation options interface
|
|
175
|
+
*/
|
|
176
|
+
export interface OperationOptions extends BaseOptions {
|
|
177
|
+
/** Maximum computation steps */
|
|
178
|
+
maxSteps?: number;
|
|
179
|
+
/** Progress callback */
|
|
180
|
+
onProgress?: ProgressCallback;
|
|
181
|
+
/** Error callback */
|
|
182
|
+
onError?: ErrorCallback;
|
|
183
|
+
/** Value validator */
|
|
184
|
+
validator?: Validator<bigint>;
|
|
185
|
+
}
|
|
@@ -0,0 +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;
|
|
393
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core constants for Hypernum library
|
|
3
|
+
* Defines fundamental values and limits used across the library
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Numerical limits
|
|
7
|
+
export const MAX_SAFE_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
|
|
8
|
+
export const MIN_SAFE_INTEGER = BigInt(Number.MIN_SAFE_INTEGER);
|
|
9
|
+
export const MAX_PRECISION = 100;
|
|
10
|
+
export const MAX_COMPUTATION_STEPS = 1000;
|
|
11
|
+
export const MAX_BITS = 1024;
|
|
12
|
+
|
|
13
|
+
// Commonly used values
|
|
14
|
+
export const ZERO = BigInt(0);
|
|
15
|
+
export const ONE = BigInt(1);
|
|
16
|
+
export const TWO = BigInt(2);
|
|
17
|
+
export const TEN = BigInt(10);
|
|
18
|
+
export const NEGATIVE_ONE = BigInt(-1);
|
|
19
|
+
|
|
20
|
+
// Power operation limits
|
|
21
|
+
export const MAX_POWER_BASE = BigInt(2) ** BigInt(53);
|
|
22
|
+
export const MAX_POWER_EXPONENT = BigInt(1000);
|
|
23
|
+
export const MAX_TETRATION_HEIGHT = BigInt(4);
|
|
24
|
+
export const MAX_FACTORIAL_INPUT = BigInt(1000);
|
|
25
|
+
|
|
26
|
+
// Tree and heap configuration
|
|
27
|
+
export const DEFAULT_TREE_MAX_DEPTH = 1000;
|
|
28
|
+
export const DEFAULT_HEAP_INITIAL_CAPACITY = 16;
|
|
29
|
+
export const DEFAULT_ARRAY_GROWTH_FACTOR = 2;
|
|
30
|
+
export const MIN_ARRAY_CAPACITY = 16;
|
|
31
|
+
|
|
32
|
+
// Formatting configuration
|
|
33
|
+
export const DEFAULT_DECIMAL_SEPARATOR = '.';
|
|
34
|
+
export const DEFAULT_GROUP_SEPARATOR = ',';
|
|
35
|
+
export const DEFAULT_GROUP_SIZE = 3;
|
|
36
|
+
export const MAX_GROUP_SIZE = 10;
|
|
37
|
+
|
|
38
|
+
// Roman numeral limits
|
|
39
|
+
export const MIN_ROMAN_VALUE = 1;
|
|
40
|
+
export const MAX_ROMAN_VALUE = 3999;
|
|
41
|
+
|
|
42
|
+
// Ackermann function limits
|
|
43
|
+
export const MAX_ACKERMANN_M = 4;
|
|
44
|
+
export const MAX_ACKERMANN_N = 1000;
|
|
45
|
+
|
|
46
|
+
// Cache configuration
|
|
47
|
+
export const DEFAULT_CACHE_SIZE = 1000;
|
|
48
|
+
export const MAX_CACHE_SIZE = 10000;
|
|
49
|
+
|
|
50
|
+
// Error messages
|
|
51
|
+
export const ERROR_MESSAGES = {
|
|
52
|
+
OVERFLOW: 'Operation would result in overflow',
|
|
53
|
+
UNDERFLOW: 'Operation would result in underflow',
|
|
54
|
+
NEGATIVE_ROOT: 'Cannot compute root of negative number',
|
|
55
|
+
NEGATIVE_EXPONENT: 'Negative exponents not supported for integers',
|
|
56
|
+
DIVISION_BY_ZERO: 'Division by zero',
|
|
57
|
+
INVALID_PRECISION: 'Precision must be non-negative and not exceed MAX_PRECISION',
|
|
58
|
+
INVALID_BASE: 'Base must be a positive integer',
|
|
59
|
+
INVALID_ROMAN: 'Invalid Roman numeral',
|
|
60
|
+
COMPUTATION_LIMIT: 'Computation exceeded maximum allowed steps',
|
|
61
|
+
NEGATIVE_INDEX: 'Array index cannot be negative',
|
|
62
|
+
TREE_DEPTH_EXCEEDED: 'Maximum tree depth exceeded',
|
|
63
|
+
INVALID_HEAP_PROPERTY: 'Heap property violation detected'
|
|
64
|
+
} as const;
|
|
65
|
+
|
|
66
|
+
// Feature flags for optional functionality
|
|
67
|
+
export const FEATURES = {
|
|
68
|
+
OVERFLOW_CHECKING: true,
|
|
69
|
+
AUTOMATIC_PRECISION: true,
|
|
70
|
+
MEMOIZATION: true,
|
|
71
|
+
TREE_BALANCING: true,
|
|
72
|
+
DEBUG_MODE: false
|
|
73
|
+
} as const;
|
|
74
|
+
|
|
75
|
+
// Default options for various operations
|
|
76
|
+
export const DEFAULT_OPTIONS = {
|
|
77
|
+
precision: 0,
|
|
78
|
+
roundingMode: 'HALF_EVEN',
|
|
79
|
+
checkOverflow: true,
|
|
80
|
+
maxSteps: MAX_COMPUTATION_STEPS,
|
|
81
|
+
grouping: true,
|
|
82
|
+
uppercase: false,
|
|
83
|
+
cache: true
|
|
84
|
+
} as const;
|
|
85
|
+
|
|
86
|
+
// Units for number formatting (powers of 1000)
|
|
87
|
+
export const NUMBER_UNITS = [
|
|
88
|
+
{ value: 1n, symbol: '' },
|
|
89
|
+
{ value: 1000n, symbol: 'K' },
|
|
90
|
+
{ value: 1000000n, symbol: 'M' },
|
|
91
|
+
{ value: 1000000000n, symbol: 'B' },
|
|
92
|
+
{ value: 1000000000000n, symbol: 'T' },
|
|
93
|
+
{ value: 1000000000000000n, symbol: 'Q' }
|
|
94
|
+
] as const;
|
|
95
|
+
|
|
96
|
+
// Performance monitoring thresholds
|
|
97
|
+
export const PERFORMANCE = {
|
|
98
|
+
WARN_THRESHOLD_MS: 100,
|
|
99
|
+
ERROR_THRESHOLD_MS: 1000,
|
|
100
|
+
MAX_ARRAY_SIZE: 1000000,
|
|
101
|
+
MAX_TREE_SIZE: 1000000
|
|
102
|
+
} as const;
|