@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/rollup.config.js
CHANGED
|
@@ -1,162 +1,164 @@
|
|
|
1
|
-
import typescript from 'rollup-plugin-typescript2';
|
|
2
|
-
import resolve from '@rollup/plugin-node-resolve';
|
|
3
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
4
|
-
import terser from '@rollup/plugin-terser';
|
|
5
|
-
import dts from 'rollup-plugin-dts';
|
|
6
|
-
import alias from '@rollup/plugin-alias';
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
...Object.keys(pkg.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
{ find: '@
|
|
32
|
-
{ find: '@
|
|
33
|
-
{ find: '@
|
|
34
|
-
{find: '@
|
|
35
|
-
{
|
|
36
|
-
{ find: '@
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
/@
|
|
144
|
-
/@
|
|
145
|
-
/@
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
1
|
+
import typescript from 'rollup-plugin-typescript2';
|
|
2
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
3
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
4
|
+
import terser from '@rollup/plugin-terser';
|
|
5
|
+
import dts from 'rollup-plugin-dts';
|
|
6
|
+
import alias from '@rollup/plugin-alias';
|
|
7
|
+
import json from '@rollup/plugin-json';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { readFileSync } from 'fs';
|
|
10
|
+
import { fileURLToPath } from 'url';
|
|
11
|
+
|
|
12
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
|
|
14
|
+
|
|
15
|
+
const banner = `/**
|
|
16
|
+
* ${pkg.name} v${pkg.version}
|
|
17
|
+
* Precison at Scale
|
|
18
|
+
*${pkg.description}
|
|
19
|
+
* @license ISC
|
|
20
|
+
*/`;
|
|
21
|
+
|
|
22
|
+
// External dependencies
|
|
23
|
+
const external = [
|
|
24
|
+
...Object.keys(pkg.dependencies || {}),
|
|
25
|
+
...Object.keys(pkg.peerDependencies || {}),
|
|
26
|
+
'tslib'
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
// Alias configurations for hypernum specific paths
|
|
30
|
+
const srcAliases = [
|
|
31
|
+
{ find: '@', replacement: path.resolve(__dirname, 'src') },
|
|
32
|
+
{ find: '@core', replacement: path.resolve(__dirname, 'src/core') },
|
|
33
|
+
{ find: '@operations', replacement: path.resolve(__dirname, 'src/operations') },
|
|
34
|
+
{ find: '@structures', replacement: path.resolve(__dirname, 'src/structures') },
|
|
35
|
+
{find: '@storage', replacement: path.resolve(__dirname, 'src/storage') },
|
|
36
|
+
{ find: '@utils', replacement: path.resolve(__dirname, 'src/utils') },
|
|
37
|
+
{ find: '@types', replacement: path.resolve(__dirname, 'src/types') }
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
// TypeScript configuration optimized for BigInt operations
|
|
41
|
+
const typeScriptConfig = {
|
|
42
|
+
tsconfig: './tsconfig.json',
|
|
43
|
+
clean: true,
|
|
44
|
+
useTsconfigDeclarationDir: true,
|
|
45
|
+
tsconfigOverride: {
|
|
46
|
+
compilerOptions: {
|
|
47
|
+
declaration: true,
|
|
48
|
+
declarationDir: './dist/types',
|
|
49
|
+
sourceMap: true,
|
|
50
|
+
module: 'esnext',
|
|
51
|
+
moduleResolution: 'node',
|
|
52
|
+
target: 'es2020', // Ensures BigInt compatibility
|
|
53
|
+
lib: ['es2020', 'dom'],
|
|
54
|
+
allowSyntheticDefaultImports: true
|
|
55
|
+
},
|
|
56
|
+
exclude: ['**/__tests__/**', '**/*.test.ts', 'src/**/*.spec.ts']
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Base plugins configuration
|
|
61
|
+
const basePlugins = [
|
|
62
|
+
alias({ entries: srcAliases }),
|
|
63
|
+
json({ compact: true }),
|
|
64
|
+
resolve({
|
|
65
|
+
browser: true,
|
|
66
|
+
preferBuiltins: true,
|
|
67
|
+
mainFields: ['module', 'browser', 'main'],
|
|
68
|
+
extensions: ['.ts', '.js']
|
|
69
|
+
}),
|
|
70
|
+
commonjs({
|
|
71
|
+
include: /node_modules/,
|
|
72
|
+
requireReturnsDefault: 'auto'
|
|
73
|
+
}),
|
|
74
|
+
typescript(typeScriptConfig)
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
// Base output configuration
|
|
78
|
+
const baseOutput = {
|
|
79
|
+
banner,
|
|
80
|
+
sourcemap: true,
|
|
81
|
+
exports: 'named'
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Main builds configuration
|
|
85
|
+
const mainBuilds = [
|
|
86
|
+
// UMD build
|
|
87
|
+
{
|
|
88
|
+
input: 'src/index.ts',
|
|
89
|
+
output: {
|
|
90
|
+
...baseOutput,
|
|
91
|
+
file: 'dist/index.umd.js',
|
|
92
|
+
format: 'umd',
|
|
93
|
+
name: 'Hypernum',
|
|
94
|
+
globals: {
|
|
95
|
+
tslib: 'tslib'
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
external,
|
|
99
|
+
plugins: [
|
|
100
|
+
...basePlugins,
|
|
101
|
+
terser({
|
|
102
|
+
output: {
|
|
103
|
+
comments: (node, comment) =>
|
|
104
|
+
comment.type === 'comment2' && /@license/i.test(comment.value)
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
// ESM build
|
|
110
|
+
{
|
|
111
|
+
input: 'src/index.ts',
|
|
112
|
+
output: {
|
|
113
|
+
...baseOutput,
|
|
114
|
+
file: 'dist/index.js',
|
|
115
|
+
format: 'esm'
|
|
116
|
+
},
|
|
117
|
+
external,
|
|
118
|
+
plugins: basePlugins
|
|
119
|
+
},
|
|
120
|
+
// CommonJS build
|
|
121
|
+
{
|
|
122
|
+
input: 'src/index.ts',
|
|
123
|
+
output: {
|
|
124
|
+
...baseOutput,
|
|
125
|
+
file: 'dist/index.cjs',
|
|
126
|
+
format: 'cjs'
|
|
127
|
+
},
|
|
128
|
+
external,
|
|
129
|
+
plugins: basePlugins
|
|
130
|
+
}
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
// Types build configuration
|
|
134
|
+
const typesBuild = {
|
|
135
|
+
input: 'src/index.ts',
|
|
136
|
+
output: {
|
|
137
|
+
file: 'dist/index.d.ts',
|
|
138
|
+
format: 'es'
|
|
139
|
+
},
|
|
140
|
+
external: [
|
|
141
|
+
...external,
|
|
142
|
+
/\.css$/,
|
|
143
|
+
/@types\/.*/,
|
|
144
|
+
/@core\/.*/,
|
|
145
|
+
/@operations\/.*/,
|
|
146
|
+
/@structures\/.*/,
|
|
147
|
+
/@utils\/.*/,
|
|
148
|
+
/@\/.*/
|
|
149
|
+
],
|
|
150
|
+
plugins: [
|
|
151
|
+
alias({
|
|
152
|
+
entries: srcAliases.map(entry => ({
|
|
153
|
+
...entry,
|
|
154
|
+
replacement: entry.replacement.replace('/src/', '/dist/types/')
|
|
155
|
+
}))
|
|
156
|
+
}),
|
|
157
|
+
dts()
|
|
158
|
+
]
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export default [
|
|
162
|
+
...mainBuilds,
|
|
163
|
+
typesBuild
|
|
162
164
|
];
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import process from 'node:process';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const DEFAULT_CONFIG = {
|
|
9
|
+
precision: 10,
|
|
10
|
+
roundingMode: 'HALF_EVEN',
|
|
11
|
+
checkOverflow: true,
|
|
12
|
+
maxSteps: 1000,
|
|
13
|
+
debug: false
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const DEFAULT_CONFIG_NAMES = [
|
|
17
|
+
'hypernum.config.json',
|
|
18
|
+
'.hypernumrc',
|
|
19
|
+
'.hypernumrc.json'
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const COMMANDS = {
|
|
23
|
+
// Arithmetic (2 args)
|
|
24
|
+
add: { args: 2, fn: 'add' },
|
|
25
|
+
subtract: { args: 2, fn: 'subtract' },
|
|
26
|
+
multiply: { args: 2, fn: 'multiply' },
|
|
27
|
+
divide: { args: 2, fn: 'divide' },
|
|
28
|
+
mod: { args: 2, fn: 'remainder' },
|
|
29
|
+
gcd: { args: 2, fn: 'gcd' },
|
|
30
|
+
lcm: { args: 2, fn: 'lcm' },
|
|
31
|
+
// Arithmetic (1 arg)
|
|
32
|
+
abs: { args: 1, fn: 'abs' },
|
|
33
|
+
sign: { args: 1, fn: 'sign' },
|
|
34
|
+
// Power
|
|
35
|
+
power: { args: 2, fn: 'power' },
|
|
36
|
+
sqrt: { args: 1, fn: 'sqrt' },
|
|
37
|
+
nthRoot: { args: 2, fn: 'nthRoot' },
|
|
38
|
+
// Factorial
|
|
39
|
+
factorial: { args: 1, fn: 'factorial' },
|
|
40
|
+
binomial: { args: 2, fn: 'binomial' },
|
|
41
|
+
primorial: { args: 1, fn: 'primorial' },
|
|
42
|
+
// Conversion
|
|
43
|
+
toBinary: { args: 1, fn: 'toBinary' },
|
|
44
|
+
toHex: { args: 1, fn: 'toHexadecimal' },
|
|
45
|
+
toOctal: { args: 1, fn: 'toOctal' },
|
|
46
|
+
toRoman: { args: 1, fn: 'toRoman' },
|
|
47
|
+
fromRoman: { args: 1, fn: 'fromRoman', stringArg: true },
|
|
48
|
+
toScientific: { args: 1, fn: 'toScientific' },
|
|
49
|
+
toBase: { args: 2, fn: 'toBase', secondArgIsInt: true },
|
|
50
|
+
// Comparison
|
|
51
|
+
compare: { args: 2, fn: 'compare' },
|
|
52
|
+
equals: { args: 2, fn: 'equals' },
|
|
53
|
+
lessThan: { args: 2, fn: 'lessThan' },
|
|
54
|
+
greaterThan: { args: 2, fn: 'greaterThan' },
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const USAGE = `hypernum - High-precision mathematics CLI
|
|
58
|
+
|
|
59
|
+
Usage:
|
|
60
|
+
hypernum <command> [args...] [options]
|
|
61
|
+
|
|
62
|
+
Arithmetic:
|
|
63
|
+
add <a> <b> Add two numbers
|
|
64
|
+
subtract <a> <b> Subtract b from a
|
|
65
|
+
multiply <a> <b> Multiply two numbers
|
|
66
|
+
divide <a> <b> Divide a by b
|
|
67
|
+
mod <a> <b> Remainder of a / b
|
|
68
|
+
gcd <a> <b> Greatest common divisor
|
|
69
|
+
lcm <a> <b> Least common multiple
|
|
70
|
+
abs <n> Absolute value
|
|
71
|
+
sign <n> Sign (-1, 0, or 1)
|
|
72
|
+
|
|
73
|
+
Power:
|
|
74
|
+
power <base> <exp> Exponentiation
|
|
75
|
+
sqrt <n> Integer square root
|
|
76
|
+
nthRoot <n> <k> k-th root of n
|
|
77
|
+
|
|
78
|
+
Factorial:
|
|
79
|
+
factorial <n> Factorial (n!)
|
|
80
|
+
binomial <n> <k> Binomial coefficient C(n, k)
|
|
81
|
+
primorial <n> Primorial (n#)
|
|
82
|
+
|
|
83
|
+
Conversion:
|
|
84
|
+
toBinary <n> Convert to binary
|
|
85
|
+
toOctal <n> Convert to octal
|
|
86
|
+
toHex <n> Convert to hexadecimal
|
|
87
|
+
toRoman <n> Convert to Roman numeral
|
|
88
|
+
fromRoman <str> Convert from Roman numeral
|
|
89
|
+
toScientific <n> Convert to scientific notation
|
|
90
|
+
toBase <n> <base> Convert to arbitrary base
|
|
91
|
+
|
|
92
|
+
Comparison:
|
|
93
|
+
compare <a> <b> Compare (-1, 0, 1)
|
|
94
|
+
equals <a> <b> Test equality (true/false)
|
|
95
|
+
lessThan <a> <b> Test a < b (true/false)
|
|
96
|
+
greaterThan <a> <b> Test a > b (true/false)
|
|
97
|
+
|
|
98
|
+
Config:
|
|
99
|
+
--init [path] Create a config file (default: ./hypernum.config.json)
|
|
100
|
+
--config [path] Show resolved config
|
|
101
|
+
|
|
102
|
+
Options:
|
|
103
|
+
--precision <n> Set decimal precision
|
|
104
|
+
--no-overflow Disable overflow checking
|
|
105
|
+
--help, -h Show this help
|
|
106
|
+
--version, -v Show version
|
|
107
|
+
|
|
108
|
+
Examples:
|
|
109
|
+
hypernum add 123456789012345678901234567890 987654321098765432109876543210
|
|
110
|
+
hypernum factorial 100
|
|
111
|
+
hypernum toRoman 2024
|
|
112
|
+
hypernum toBase 255 16
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
let _lib = null;
|
|
116
|
+
|
|
117
|
+
async function loadLibrary() {
|
|
118
|
+
if (_lib) return _lib;
|
|
119
|
+
try {
|
|
120
|
+
_lib = await import('@obinexusmk2/hypernum');
|
|
121
|
+
} catch {
|
|
122
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
123
|
+
_lib = await import(path.resolve(__dirname, '../../dist/index.js'));
|
|
124
|
+
}
|
|
125
|
+
return _lib;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function findConfigPath() {
|
|
129
|
+
for (const name of DEFAULT_CONFIG_NAMES) {
|
|
130
|
+
const candidate = path.resolve(process.cwd(), name);
|
|
131
|
+
if (fs.existsSync(candidate)) {
|
|
132
|
+
return candidate;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function readConfig(filePath) {
|
|
139
|
+
try {
|
|
140
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
141
|
+
return JSON.parse(raw);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
console.error(`Unable to read config: ${filePath}`);
|
|
144
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
145
|
+
process.exitCode = 1;
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function resolveConfig() {
|
|
151
|
+
const configPath = findConfigPath();
|
|
152
|
+
if (!configPath) return { ...DEFAULT_CONFIG };
|
|
153
|
+
const fileConfig = readConfig(configPath);
|
|
154
|
+
return { ...DEFAULT_CONFIG, ...(fileConfig || {}) };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function writeConfig(filePath) {
|
|
158
|
+
const targetPath = path.resolve(process.cwd(), filePath || 'hypernum.config.json');
|
|
159
|
+
|
|
160
|
+
if (fs.existsSync(targetPath)) {
|
|
161
|
+
console.error(`Config already exists: ${targetPath}`);
|
|
162
|
+
process.exitCode = 1;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
fs.writeFileSync(targetPath, `${JSON.stringify(DEFAULT_CONFIG, null, 2)}\n`, 'utf8');
|
|
167
|
+
console.log(`Created Hypernum config at ${targetPath}`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function printConfig(explicitPath) {
|
|
171
|
+
const resolvedPath = explicitPath
|
|
172
|
+
? path.resolve(process.cwd(), explicitPath)
|
|
173
|
+
: findConfigPath();
|
|
174
|
+
|
|
175
|
+
if (!resolvedPath) {
|
|
176
|
+
console.log(JSON.stringify(DEFAULT_CONFIG, null, 2));
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const parsed = readConfig(resolvedPath);
|
|
181
|
+
if (!parsed) return;
|
|
182
|
+
|
|
183
|
+
console.log(JSON.stringify({ ...DEFAULT_CONFIG, ...parsed }, null, 2));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function main() {
|
|
187
|
+
const args = process.argv.slice(2);
|
|
188
|
+
|
|
189
|
+
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
|
|
190
|
+
console.log(USAGE);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (args.includes('--version') || args.includes('-v')) {
|
|
195
|
+
const lib = await loadLibrary();
|
|
196
|
+
console.log(lib.VERSION);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (args[0] === '--init') {
|
|
201
|
+
writeConfig(args[1]);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (args[0] === '--config') {
|
|
206
|
+
printConfig(args[1]);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const commandName = args[0];
|
|
211
|
+
const cmd = COMMANDS[commandName];
|
|
212
|
+
|
|
213
|
+
if (!cmd) {
|
|
214
|
+
console.error(`Unknown command: ${commandName}\n`);
|
|
215
|
+
console.log(USAGE);
|
|
216
|
+
process.exitCode = 1;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Parse positional args and options
|
|
221
|
+
const positionalArgs = [];
|
|
222
|
+
// Default: disable overflow checking for CLI (BigInt handles arbitrary precision)
|
|
223
|
+
const options = { checkOverflow: false };
|
|
224
|
+
for (let i = 1; i < args.length; i++) {
|
|
225
|
+
if (args[i] === '--precision' && args[i + 1]) {
|
|
226
|
+
options.precision = parseInt(args[++i], 10);
|
|
227
|
+
} else if (args[i] === '--overflow') {
|
|
228
|
+
options.checkOverflow = true;
|
|
229
|
+
} else if (args[i] === '--no-overflow') {
|
|
230
|
+
options.checkOverflow = false;
|
|
231
|
+
} else if (!args[i].startsWith('--')) {
|
|
232
|
+
positionalArgs.push(args[i]);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (positionalArgs.length < cmd.args) {
|
|
237
|
+
console.error(`Command '${commandName}' requires ${cmd.args} argument(s), got ${positionalArgs.length}`);
|
|
238
|
+
process.exitCode = 1;
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const lib = await loadLibrary();
|
|
243
|
+
const fn = lib[cmd.fn];
|
|
244
|
+
|
|
245
|
+
if (typeof fn !== 'function') {
|
|
246
|
+
console.error(`Function '${cmd.fn}' not found in library`);
|
|
247
|
+
process.exitCode = 1;
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Only pass explicitly provided CLI options to library functions.
|
|
252
|
+
// Config file defaults (precision: 10, etc.) don't map to operation defaults.
|
|
253
|
+
try {
|
|
254
|
+
let result;
|
|
255
|
+
if (cmd.args === 1) {
|
|
256
|
+
result = cmd.stringArg ? fn(positionalArgs[0]) : fn(positionalArgs[0], options);
|
|
257
|
+
} else if (cmd.secondArgIsInt) {
|
|
258
|
+
result = fn(positionalArgs[0], parseInt(positionalArgs[1], 10), options);
|
|
259
|
+
} else {
|
|
260
|
+
result = fn(positionalArgs[0], positionalArgs[1], options);
|
|
261
|
+
}
|
|
262
|
+
console.log(String(result));
|
|
263
|
+
} catch (err) {
|
|
264
|
+
console.error(`Error: ${err.message || err}`);
|
|
265
|
+
process.exitCode = 1;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
main().catch((err) => {
|
|
270
|
+
console.error('hypernum: fatal error:', err.message || err);
|
|
271
|
+
process.exitCode = 1;
|
|
272
|
+
});
|
|
File without changes
|