solve-engine 1.0.1 → 1.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/dist/{BytecodeBuilder-B0xskcv5.d.cts → BytecodeBuilder-Bp9xeTmX.d.cts} +4 -0
- package/dist/{BytecodeBuilder-B0xskcv5.d.ts → BytecodeBuilder-Bp9xeTmX.d.ts} +4 -0
- package/dist/{Configuration-B-G5gTRn.d.cts → Configuration-C9W8tJv_.d.cts} +53 -1
- package/dist/{Configuration-B-G5gTRn.d.ts → Configuration-C9W8tJv_.d.ts} +53 -1
- package/dist/{EngineError-LU7W7AgI.d.cts → EngineError-B61GS1jp.d.cts} +14 -0
- package/dist/{EngineError-LU7W7AgI.d.ts → EngineError-B61GS1jp.d.ts} +14 -0
- package/dist/FormattingSettings-CJHyxcYu.d.cts +27 -0
- package/dist/FormattingSettings-CJHyxcYu.d.ts +27 -0
- package/dist/{Lexer-D78E2yDW.d.cts → Lexer-BOs7euZe.d.cts} +58 -1
- package/dist/{Lexer-BN5mt30n.d.ts → Lexer-CSI_lwbW.d.ts} +58 -1
- package/dist/PackageCompatibility-B-7rK1TD.d.cts +76 -0
- package/dist/PackageCompatibility-Dh59eF-X.d.ts +76 -0
- package/dist/{PackageRegistry-B37mRvvz.d.cts → PackageRegistry-BHWJP83F.d.cts} +449 -11
- package/dist/{PackageRegistry-DCUEzbQt.d.ts → PackageRegistry-_8rDlvxI.d.ts} +449 -11
- package/dist/{Parselet-BaySkMV3.d.ts → Parselet-BBT8riYh.d.ts} +12 -3
- package/dist/{Parselet-DuI1Pjiq.d.cts → Parselet-BHcgK9S7.d.cts} +12 -3
- package/dist/{ScopeManager-B6GzdhVG.d.cts → ScopeManager-8vf02dwj.d.cts} +56 -5
- package/dist/{ScopeManager-udv4Twwq.d.ts → ScopeManager-CxA24W5n.d.ts} +56 -5
- package/dist/{Token-BzG5G4ja.d.cts → Token-B1hdkedD.d.cts} +9 -0
- package/dist/{Token-BzG5G4ja.d.ts → Token-B1hdkedD.d.ts} +9 -0
- package/dist/{TokenNormalizer-t_GotBxr.d.ts → TokenNormalizer-C6VzZgHa.d.ts} +1 -1
- package/dist/{TokenNormalizer-DGVa24Q-.d.cts → TokenNormalizer-DRc1Js1V.d.cts} +1 -1
- package/dist/{VMCheckpoints-DwLjivM7.d.cts → VMCheckpoints-ELYqITdF.d.cts} +3 -3
- package/dist/{VMCheckpoints-BiaIlOOY.d.ts → VMCheckpoints-MK--EBH2.d.ts} +3 -3
- package/dist/{Value-CXJqDH9J.d.cts → Value-BUi1RA3S.d.cts} +124 -5
- package/dist/{Value-CXJqDH9J.d.ts → Value-BUi1RA3S.d.ts} +124 -5
- package/dist/WorkerError-_-RkoQ5P.d.ts +75 -0
- package/dist/WorkerError-gzmaopj2.d.cts +75 -0
- package/dist/{chunk-GQCOSXMG.js → chunk-267JPOTF.js} +43 -5
- package/dist/chunk-267JPOTF.js.map +1 -0
- package/dist/{chunk-JMXUNXQS.cjs → chunk-2TZKENDH.cjs} +51 -8
- package/dist/chunk-2TZKENDH.cjs.map +1 -0
- package/dist/chunk-3OWCDIPN.js +215 -0
- package/dist/chunk-3OWCDIPN.js.map +1 -0
- package/dist/{chunk-VB37OC6I.js → chunk-4D6NIHE2.js} +40 -3
- package/dist/chunk-4D6NIHE2.js.map +1 -0
- package/dist/{chunk-TY3TLZAW.cjs → chunk-536WPM2V.cjs} +18 -2
- package/dist/chunk-536WPM2V.cjs.map +1 -0
- package/dist/chunk-5HRB36DK.js +405 -0
- package/dist/chunk-5HRB36DK.js.map +1 -0
- package/dist/chunk-5ON7PUAZ.js +12 -0
- package/dist/chunk-5ON7PUAZ.js.map +1 -0
- package/dist/{chunk-KV7UW6T6.js → chunk-7KYSUDQO.js} +12 -5
- package/dist/chunk-7KYSUDQO.js.map +1 -0
- package/dist/{chunk-6WFMPTGB.cjs → chunk-7ZX6B7SY.cjs} +774 -528
- package/dist/chunk-7ZX6B7SY.cjs.map +1 -0
- package/dist/chunk-ALYRJ72W.cjs +434 -0
- package/dist/chunk-ALYRJ72W.cjs.map +1 -0
- package/dist/{chunk-5KMIY374.cjs → chunk-B4HBEFTB.cjs} +17 -2
- package/dist/chunk-B4HBEFTB.cjs.map +1 -0
- package/dist/chunk-B7NLZMQ3.cjs +74 -0
- package/dist/chunk-B7NLZMQ3.cjs.map +1 -0
- package/dist/{chunk-UQ3UIZJC.js → chunk-BLI4NIQY.js} +6 -2
- package/dist/chunk-BLI4NIQY.js.map +1 -0
- package/dist/{chunk-BHTNFEGZ.cjs → chunk-C75AFGVD.cjs} +11 -11
- package/dist/{chunk-BHTNFEGZ.cjs.map → chunk-C75AFGVD.cjs.map} +1 -1
- package/dist/{chunk-G535KJEG.js → chunk-CCBZZQAE.js} +2 -2
- package/dist/{chunk-G535KJEG.js.map → chunk-CCBZZQAE.js.map} +1 -1
- package/dist/chunk-CKQMXMHR.cjs +219 -0
- package/dist/chunk-CKQMXMHR.cjs.map +1 -0
- package/dist/{chunk-PFUESQTW.cjs → chunk-EJ3ILXX6.cjs} +48 -2
- package/dist/chunk-EJ3ILXX6.cjs.map +1 -0
- package/dist/{chunk-526PMQOA.js → chunk-ENKKJYD3.js} +10 -4
- package/dist/chunk-ENKKJYD3.js.map +1 -0
- package/dist/{chunk-5X2PTP6F.cjs → chunk-ENRIK36Q.cjs} +2 -12
- package/dist/chunk-ENRIK36Q.cjs.map +1 -0
- package/dist/{chunk-3D7V24DG.js → chunk-ERCOHGXD.js} +17 -2
- package/dist/chunk-ERCOHGXD.js.map +1 -0
- package/dist/{chunk-IF532O7C.js → chunk-FD5ZZHEU.js} +3 -12
- package/dist/chunk-FD5ZZHEU.js.map +1 -0
- package/dist/{chunk-TBN7DEHO.js → chunk-G7Z4HJQA.js} +11 -5
- package/dist/chunk-G7Z4HJQA.js.map +1 -0
- package/dist/{chunk-QY25VWBF.js → chunk-GQMUHVE3.js} +142 -6
- package/dist/chunk-GQMUHVE3.js.map +1 -0
- package/dist/chunk-GUG7SNSV.js +1764 -0
- package/dist/chunk-GUG7SNSV.js.map +1 -0
- package/dist/{chunk-UM6BVY2S.cjs → chunk-HIQ5HSZL.cjs} +175 -43
- package/dist/chunk-HIQ5HSZL.cjs.map +1 -0
- package/dist/{chunk-HVQFNJKE.cjs → chunk-HVRVSI2Z.cjs} +104 -86
- package/dist/chunk-HVRVSI2Z.cjs.map +1 -0
- package/dist/{chunk-3LAEG75D.js → chunk-I4GAWIPW.js} +24 -6
- package/dist/chunk-I4GAWIPW.js.map +1 -0
- package/dist/{chunk-PA4VC73I.cjs → chunk-J45BCEZ4.cjs} +33 -27
- package/dist/chunk-J45BCEZ4.cjs.map +1 -0
- package/dist/{chunk-V5PYO44Y.js → chunk-JIPATHVY.js} +1853 -2638
- package/dist/chunk-JIPATHVY.js.map +1 -0
- package/dist/{chunk-YPPPYLSR.js → chunk-JJIXHXFQ.js} +5 -5
- package/dist/{chunk-YPPPYLSR.js.map → chunk-JJIXHXFQ.js.map} +1 -1
- package/dist/chunk-L2TE7PMO.cjs +14 -0
- package/dist/chunk-L2TE7PMO.cjs.map +1 -0
- package/dist/{chunk-B7TLZABL.cjs → chunk-MG6Q3DUO.cjs} +1962 -2746
- package/dist/chunk-MG6Q3DUO.cjs.map +1 -0
- package/dist/{chunk-R3PY4G7J.js → chunk-MVTOCRV2.js} +48 -3
- package/dist/chunk-MVTOCRV2.js.map +1 -0
- package/dist/{chunk-Y7FT4IQT.js → chunk-NKW7LKYU.js} +266 -28
- package/dist/chunk-NKW7LKYU.js.map +1 -0
- package/dist/{chunk-O3ANBHSA.js → chunk-NNQ2TYDF.js} +123 -5
- package/dist/chunk-NNQ2TYDF.js.map +1 -0
- package/dist/{chunk-5F4C26RU.js → chunk-OADDUPT3.js} +4 -4
- package/dist/{chunk-5F4C26RU.js.map → chunk-OADDUPT3.js.map} +1 -1
- package/dist/{chunk-3AFRJYP4.cjs → chunk-OTN6SZOD.cjs} +1868 -393
- package/dist/chunk-OTN6SZOD.cjs.map +1 -0
- package/dist/{chunk-5LI5EPGJ.cjs → chunk-QFTDTX6K.cjs} +40 -3
- package/dist/chunk-QFTDTX6K.cjs.map +1 -0
- package/dist/{chunk-HMOISHXR.js → chunk-RRLHC37V.js} +1530 -57
- package/dist/chunk-RRLHC37V.js.map +1 -0
- package/dist/chunk-SNHVVOJK.cjs +1768 -0
- package/dist/chunk-SNHVVOJK.cjs.map +1 -0
- package/dist/{chunk-HDP7VK3C.cjs → chunk-SRGQ72IR.cjs} +649 -349
- package/dist/chunk-SRGQ72IR.cjs.map +1 -0
- package/dist/{chunk-4B2CNWQU.cjs → chunk-SSV46KFA.cjs} +14 -7
- package/dist/chunk-SSV46KFA.cjs.map +1 -0
- package/dist/{chunk-AJA6LUI7.js → chunk-UO6BUV6K.js} +18 -2
- package/dist/chunk-UO6BUV6K.js.map +1 -0
- package/dist/chunk-WWQEY7BV.js +67 -0
- package/dist/chunk-WWQEY7BV.js.map +1 -0
- package/dist/{chunk-5WVP4YHP.js → chunk-WXEHD6TT.js} +333 -33
- package/dist/chunk-WXEHD6TT.js.map +1 -0
- package/dist/{chunk-47LRVGOT.cjs → chunk-XA4CKRML.cjs} +2 -2
- package/dist/{chunk-47LRVGOT.cjs.map → chunk-XA4CKRML.cjs.map} +1 -1
- package/dist/{chunk-6KFYJ6TD.cjs → chunk-XIYYHA65.cjs} +6 -2
- package/dist/chunk-XIYYHA65.cjs.map +1 -0
- package/dist/{chunk-KBSXGXPM.cjs → chunk-XJGJCF2R.cjs} +6 -6
- package/dist/{chunk-KBSXGXPM.cjs.map → chunk-XJGJCF2R.cjs.map} +1 -1
- package/dist/{chunk-YWQ6V4ZN.cjs → chunk-YTIYVHL7.cjs} +211 -75
- package/dist/chunk-YTIYVHL7.cjs.map +1 -0
- package/dist/{chunk-TMA4RCEN.js → chunk-Z7XGGLI2.js} +3 -3
- package/dist/{chunk-TMA4RCEN.js.map → chunk-Z7XGGLI2.js.map} +1 -1
- package/dist/{chunk-A2N2GFCG.cjs → chunk-ZVTWQLK4.cjs} +10 -10
- package/dist/{chunk-A2N2GFCG.cjs.map → chunk-ZVTWQLK4.cjs.map} +1 -1
- package/dist/{chunk-2XLQPQKI.cjs → chunk-ZXCESUJS.cjs} +15 -9
- package/dist/chunk-ZXCESUJS.cjs.map +1 -0
- package/dist/constants.cjs +5 -5
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +2 -2
- package/dist/engine.cjs +52 -35
- package/dist/engine.d.cts +13 -13
- package/dist/engine.d.ts +13 -13
- package/dist/engine.js +26 -21
- package/dist/errors.cjs +44 -19
- package/dist/errors.d.cts +3 -2
- package/dist/errors.d.ts +3 -2
- package/dist/errors.js +2 -1
- package/dist/format.cjs +19 -169
- package/dist/format.cjs.map +1 -1
- package/dist/format.d.cts +18 -26
- package/dist/format.d.ts +18 -26
- package/dist/format.js +7 -171
- package/dist/format.js.map +1 -1
- package/dist/index.cjs +250 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +110 -74
- package/dist/index.d.ts +110 -74
- package/dist/index.js +228 -23
- package/dist/index.js.map +1 -1
- package/dist/language.cjs +9 -9
- package/dist/language.d.cts +12 -12
- package/dist/language.d.ts +12 -12
- package/dist/language.js +3 -3
- package/dist/lexer.cjs +16 -16
- package/dist/lexer.d.cts +3 -3
- package/dist/lexer.d.ts +3 -3
- package/dist/lexer.js +5 -5
- package/dist/normalizer.cjs +10 -10
- package/dist/normalizer.d.cts +3 -3
- package/dist/normalizer.d.ts +3 -3
- package/dist/normalizer.js +4 -4
- package/dist/packages.cjs +45 -36
- package/dist/packages.d.cts +135 -31
- package/dist/packages.d.ts +135 -31
- package/dist/packages.js +14 -13
- package/dist/parser.cjs +16 -16
- package/dist/parser.d.cts +6 -5
- package/dist/parser.d.ts +6 -5
- package/dist/parser.js +6 -6
- package/dist/{pipeline-BEb3hujr.d.cts → pipeline-CtfJtPQc.d.cts} +3 -3
- package/dist/{pipeline-B6k5lCB7.d.ts → pipeline-DCd5M6Gk.d.ts} +3 -3
- package/dist/resolvers.d.cts +3 -3
- package/dist/resolvers.d.ts +3 -3
- package/dist/testing.cjs +478 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +271 -0
- package/dist/testing.d.ts +271 -0
- package/dist/testing.js +470 -0
- package/dist/testing.js.map +1 -0
- package/dist/uom.cjs +16 -16
- package/dist/uom.d.cts +3 -3
- package/dist/uom.d.ts +3 -3
- package/dist/uom.js +6 -6
- package/dist/utilities.cjs +6 -5
- package/dist/utilities.js +2 -1
- package/dist/vm.cjs +34 -34
- package/dist/vm.d.cts +8 -8
- package/dist/vm.d.ts +8 -8
- package/dist/vm.js +9 -9
- package/dist/worker.cjs +493 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.d.cts +509 -0
- package/dist/worker.d.ts +509 -0
- package/dist/worker.js +484 -0
- package/dist/worker.js.map +1 -0
- package/package.json +21 -1
- package/dist/chunk-2XLQPQKI.cjs.map +0 -1
- package/dist/chunk-3AFRJYP4.cjs.map +0 -1
- package/dist/chunk-3D7V24DG.js.map +0 -1
- package/dist/chunk-3LAEG75D.js.map +0 -1
- package/dist/chunk-4B2CNWQU.cjs.map +0 -1
- package/dist/chunk-526PMQOA.js.map +0 -1
- package/dist/chunk-5KMIY374.cjs.map +0 -1
- package/dist/chunk-5LI5EPGJ.cjs.map +0 -1
- package/dist/chunk-5WVP4YHP.js.map +0 -1
- package/dist/chunk-5X2PTP6F.cjs.map +0 -1
- package/dist/chunk-6KFYJ6TD.cjs.map +0 -1
- package/dist/chunk-6WFMPTGB.cjs.map +0 -1
- package/dist/chunk-AJA6LUI7.js.map +0 -1
- package/dist/chunk-B7TLZABL.cjs.map +0 -1
- package/dist/chunk-GQCOSXMG.js.map +0 -1
- package/dist/chunk-HDP7VK3C.cjs.map +0 -1
- package/dist/chunk-HMOISHXR.js.map +0 -1
- package/dist/chunk-HVQFNJKE.cjs.map +0 -1
- package/dist/chunk-IF532O7C.js.map +0 -1
- package/dist/chunk-JMXUNXQS.cjs.map +0 -1
- package/dist/chunk-KV7UW6T6.js.map +0 -1
- package/dist/chunk-O3ANBHSA.js.map +0 -1
- package/dist/chunk-PA4VC73I.cjs.map +0 -1
- package/dist/chunk-PFUESQTW.cjs.map +0 -1
- package/dist/chunk-QY25VWBF.js.map +0 -1
- package/dist/chunk-R3PY4G7J.js.map +0 -1
- package/dist/chunk-TBN7DEHO.js.map +0 -1
- package/dist/chunk-TY3TLZAW.cjs.map +0 -1
- package/dist/chunk-UM6BVY2S.cjs.map +0 -1
- package/dist/chunk-UQ3UIZJC.js.map +0 -1
- package/dist/chunk-V5PYO44Y.js.map +0 -1
- package/dist/chunk-VB37OC6I.js.map +0 -1
- package/dist/chunk-Y7FT4IQT.js.map +0 -1
- package/dist/chunk-YWQ6V4ZN.cjs.map +0 -1
|
@@ -162,7 +162,52 @@ function getBestUnit(value, unit) {
|
|
|
162
162
|
return { value, unit: u };
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
+
function expandUnitToRate(value, unit) {
|
|
166
|
+
const slash = unit.indexOf("/");
|
|
167
|
+
if (slash >= 0) {
|
|
168
|
+
return { value, numerator: unit.slice(0, slash), denominator: unit.slice(slash + 1) };
|
|
169
|
+
}
|
|
170
|
+
const ext = EXTENDED_UNITS[unit];
|
|
171
|
+
if (ext !== void 0 && ext.measure === "speed") {
|
|
172
|
+
return { value: value * ext.toBase, numerator: "m", denominator: "s" };
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
function rateAxisFactor(from, to) {
|
|
177
|
+
if (from === to) return 1;
|
|
178
|
+
if (from === "" || to === "") return null;
|
|
179
|
+
const fromMeasure = getMeasure(from);
|
|
180
|
+
const toMeasure = getMeasure(to);
|
|
181
|
+
if (fromMeasure === void 0 || toMeasure === void 0 || fromMeasure !== toMeasure) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return convertUnit(1, from, to);
|
|
185
|
+
}
|
|
186
|
+
function convertRate(value, from, to) {
|
|
187
|
+
const source = expandUnitToRate(value, from);
|
|
188
|
+
if (source === null) return null;
|
|
189
|
+
let targetNumerator;
|
|
190
|
+
let targetDenominator;
|
|
191
|
+
let targetScale;
|
|
192
|
+
const slash = to.indexOf("/");
|
|
193
|
+
if (slash >= 0) {
|
|
194
|
+
targetNumerator = to.slice(0, slash);
|
|
195
|
+
targetDenominator = to.slice(slash + 1);
|
|
196
|
+
targetScale = 1;
|
|
197
|
+
} else {
|
|
198
|
+
const ext = EXTENDED_UNITS[to];
|
|
199
|
+
if (ext === void 0 || ext.measure !== "speed") return null;
|
|
200
|
+
targetNumerator = "m";
|
|
201
|
+
targetDenominator = "s";
|
|
202
|
+
targetScale = ext.toBase;
|
|
203
|
+
}
|
|
204
|
+
const numeratorFactor = rateAxisFactor(source.numerator, targetNumerator);
|
|
205
|
+
if (numeratorFactor === null) return null;
|
|
206
|
+
const denominatorFactor = rateAxisFactor(source.denominator, targetDenominator);
|
|
207
|
+
if (denominatorFactor === null) return null;
|
|
208
|
+
return source.value * numeratorFactor / denominatorFactor / targetScale;
|
|
209
|
+
}
|
|
165
210
|
|
|
166
|
-
export { canConvert, convertUnit, getBestUnit, getConvertiblePossibilities, getMeasure, isConvertibleUnit, isWorkdayUnit, resolveUnit };
|
|
167
|
-
//# sourceMappingURL=chunk-
|
|
168
|
-
//# sourceMappingURL=chunk-
|
|
211
|
+
export { canConvert, convertRate, convertUnit, getBestUnit, getConvertiblePossibilities, getMeasure, isConvertibleUnit, isWorkdayUnit, resolveUnit };
|
|
212
|
+
//# sourceMappingURL=chunk-MVTOCRV2.js.map
|
|
213
|
+
//# sourceMappingURL=chunk-MVTOCRV2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/uom/UnitConversion.ts","../src/uom/UomConverter.ts"],"names":[],"mappings":";;;AAmCA,IAAM,cAA8C,IAAI,GAAA,CAAI,MAAA,CAAO,OAAA,CAAQ,UAAU,CAAC,CA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,CAAO,KAAA,GAAQ,eAAA,GAAmB,iBAAA,GAAoB,WAAA;AAChE","file":"chunk-MVTOCRV2.js","sourcesContent":["/**\n * The unit conversion algorithm, ported from the `convert` npm package v7.0.2\n * alongside its tables (see `generated/UnitTable.generated.ts` and\n * THIRD-PARTY-NOTICES.md).\n *\n * Transliterated expression for expression rather than rewritten. Floating\n * point is not associative, so `(q + d) * (a / b) - d2` and any algebraically\n * equal rearrangement disagree in the last bits. Those bits are observable:\n * `0.5 l` best-converts to `500.00000000000006 mL` today, and the test suite\n * pins several conversions to ten decimal places.\n *\n * This module is deliberately unaware of the engine's own additions. Workdays,\n * extended units, currency and the caches all live in `UomConverter.ts`, which\n * layers them on top of these three functions.\n */\n\nimport {\n UNIT_TABLE,\n UNIT_DIFFERENCES,\n BEST_UNITS_METRIC,\n type UnitEntry,\n} from \"./generated/UnitTable.generated\";\n\n/**\n * The generated tables re-keyed into Maps once at module load.\n *\n * Not a micro-optimization. A 1456-key object literal lands in V8's dictionary\n * mode, and guarding a read on it against inherited names (`constructor`,\n * `toString`) costs about 123ns per call with either `hasOwnProperty.call` or\n * `Object.hasOwn`, measured. `Map.get` is about 6ns and needs no guard at all,\n * because a Map has no prototype chain to fall through to. That is a 20x\n * difference on the single hottest operation in the unit system: `convertRaw`\n * performs two of these per call, and `LanguageService` sweeps all 1456 keys\n * to build completions.\n */\nconst UNIT_LOOKUP: ReadonlyMap<string, UnitEntry> = new Map(Object.entries(UNIT_TABLE));\n\n/**\n * Temperature offsets, as a Map for the same reason.\n *\n * Also removes a latent hazard: the upstream code tests membership with `in`,\n * and `\"toString\" in UNIT_DIFFERENCES` is true, so an inherited name reaching\n * that branch would add a function to a number.\n */\nconst DIFFERENCE_LOOKUP: ReadonlyMap<string, number> = new Map(Object.entries(UNIT_DIFFERENCES));\n\n/**\n * Looks up a unit spelling.\n *\n * @returns its `[kind, ratio]` entry, or `undefined` if the spelling is not a\n * unit. Case-sensitive: no normalization or aliasing happens anywhere in this\n * module.\n *\n * The one deliberate deviation from upstream. `convert` tests membership with\n * `in` and reads the property directly, so inherited names like \"constructor\"\n * and \"toString\" reach its measure comparison and fail there with \"Cannot\n * convert between different measures\" instead of \"is not a valid unit\". Both\n * throw a RangeError and both report no measure, so nothing downstream can\n * tell the difference, and naming the real problem is the better message.\n */\nexport function lookupUnit(unit: string): UnitEntry | undefined {\n return UNIT_LOOKUP.get(unit);\n}\n\n/**\n * Converts `quantity` from one unit to another.\n *\n * THROWS a `RangeError` for an unknown unit or a pair in different measures.\n * Callers depend on that: `VM.ts`'s `extractDurationMs()` calls this with an\n * arbitrary unit inside a bare try/catch and treats the throw as \"not a\n * duration, contribute zero\". Returning NaN or the input unchanged instead\n * would turn `<date> + 5 kg` into an Invalid Date rather than a no-op.\n */\nexport function convertRaw(quantity: number, from: string, to: string): number {\n const parsedFrom = UNIT_LOOKUP.get(from);\n if (parsedFrom === undefined) {\n throw new RangeError(`${from} is not a valid unit`);\n }\n\n const parsedTo = UNIT_LOOKUP.get(to);\n if (parsedTo === undefined) {\n throw new RangeError(`${to} is not a valid unit`);\n }\n\n return convertResolved(quantity, from, to, parsedFrom, parsedTo);\n}\n\n/**\n * The conversion arithmetic, for callers that have already looked both units\n * up and want to skip doing it twice.\n *\n * Split out for `UomConverter.convertUnit()`, which has to check whether\n * either side is a workday or an extended unit before it can dispatch, and\n * would otherwise resolve each unit once to decide and again to convert. The\n * entries MUST be the ones this module returned for these exact spellings.\n */\nexport function convertResolved(\n quantity: number,\n from: string,\n to: string,\n fromEntry: UnitEntry,\n toEntry: UnitEntry\n): number {\n const parsedFrom = fromEntry;\n const parsedTo = toEntry;\n\n if (parsedFrom[0] !== parsedTo[0]) {\n // DELIBERATE DEVIATION from the ported original, which silently reinterpreted\n // \"m\" as minutes whenever the other side was a time unit. That is a guess,\n // and this project's stated position is that refusing to guess is the safer\n // default for a tool doing arithmetic on someone's real numbers (see\n // docs/architecture/design-decisions.md). The guess was not harmless: it\n // reached `<date> + <duration>` through VM.ts's extractDurationMs(), where\n // `today + 5 m` silently added five MINUTES for someone who wrote metres.\n //\n // Minutes are spelled \"min\", \"minute\" or \"minutes\", all of which the table\n // has always accepted.\n throw new RangeError(`Cannot convert between different measures: ${from} and ${to}`);\n }\n\n const fromRatio = parsedFrom[1];\n const toRatio = parsedTo[1];\n\n // Only six units in the whole table carry an offset, so the common path is\n // both misses. Reading the Map once per side and reusing the value beats\n // testing membership and then reading it again.\n const fromDifference = DIFFERENCE_LOOKUP.get(from);\n const toDifference = DIFFERENCE_LOOKUP.get(to);\n\n // Scales that do not share an origin (temperature) need the offset applied\n // around the ratio. Do not refactor the four branches into one expression:\n // the grouping is what makes the result bit-identical to the original.\n if (fromDifference !== undefined) {\n if (toDifference !== undefined) {\n return (quantity + fromDifference) * (fromRatio / toRatio) - toDifference;\n }\n return (quantity + fromDifference) * (fromRatio / toRatio);\n }\n\n if (toDifference !== undefined) {\n return quantity * (fromRatio / toRatio) - toDifference;\n }\n\n return quantity * (fromRatio / toRatio);\n}\n\n/**\n * Picks the most readable metric unit for a magnitude and converts to it.\n *\n * Only the metric lists are ported; nothing has ever requested the imperial\n * ones. Note the final conversion goes from the ORIGINAL unit to the chosen\n * one directly rather than via the smallest unit, which is what keeps the\n * result exact.\n */\nexport function convertToBestMetric(\n quantity: number,\n from: string\n): { quantity: number; unit: string } {\n const parsedFrom = UNIT_LOOKUP.get(from);\n if (parsedFrom === undefined) {\n throw new RangeError(`${from} is not a valid unit`);\n }\n\n const best = BEST_UNITS_METRIC[parsedFrom[0]];\n const smallestUnit = best[0][0];\n let bestUnit = smallestUnit;\n\n const baseQuantity = convertRaw(quantity, from, smallestUnit);\n const absQuantity = baseQuantity < 0 ? -baseQuantity : baseQuantity;\n\n // Thresholds are expressed in the smallest unit and ascend, so the last one\n // the magnitude reaches wins. Breaking early rather than scanning the whole\n // list matters for zero and for negatives, which stay on the smallest unit.\n for (let i = 0; i < best.length; i++) {\n const bestEntry = best[i];\n if (absQuantity >= bestEntry[1]) {\n bestUnit = bestEntry[0];\n } else {\n break;\n }\n }\n\n return { quantity: convertRaw(quantity, from, bestUnit), unit: bestUnit };\n}\n","/**\n * UoM Converter, built on the in-house unit tables in `UnitConversion.ts` and\n * `generated/UnitTable.generated.ts` (ported from the `convert` npm package\n * v7.0.2 so the engine ships with no runtime dependencies).\n *\n * Units are strictly case-sensitive and are looked up without aliasing. No unit\n * remapping, what you type is what you get.\n * e.g. 'C' = Celsius, 'c' = cup; 'MB' = megabytes, 'mb' = millibits.\n *\n * This file owns everything the base tables do not: the workday shim, the\n * extended (custom-measure) units, and the two caches.\n */\n\nimport { lookupUnit, convertRaw, convertResolved, convertToBestMetric } from \"@solve-js/uom/UnitConversion\";\nimport { MEASURE_KIND_NAMES, MEASURE_SYMBOLS, UNIT_TABLE } from \"@solve-js/uom/generated/UnitTable.generated\";\nimport { EXTENDED_UNITS } from \"@solve-js/uom/ExtendedUnits\";\n\n// ── \"workday\", a synthetic unit with no entry in the base table ───────────\n//\n// A business day (Mon-Fri) backing the datetime package's `<date> + N\n// workdays` arithmetic and `$X/workday` Rate literals\n// (packages/datetime/). NOT a real physical unit, a business day has no\n// fixed duration, since it depends on which calendar dates are weekends\n// so the ported base table has no concept of it and can't be\n// taught one without monkey-patching its internal unit table.\n//\n// For RATE-MATH purposes only (e.g. \"$500/workday x 4 weeks\" needs a\n// workday count to multiply by), a workday is treated as a FIXED 7/5 of a\n// calendar day: 5 workdays span exactly 7 calendar days in a whole week,\n// so this ratio is exact for whole-week spans and a reasonable linear\n// approximation otherwise. This is deliberately NOT the same\n// calendar-aware, weekend-skipping logic real \"<date> + N workdays\" date\n// arithmetic needs (see vm/VM.ts's addBusinessDays()), that can't be\n// reduced to a fixed ratio, since the exact skip pattern depends on which\n// day of the week the calculation actually starts from.\n//\n// Handled here as a thin pre/post layer in front of the normal\n// base-table path (rather than inside the tables themselves) so every\n// caller of getMeasure()/convertUnit()/canConvert() automatically gets\n// workday support for free.\nconst WORKDAY_UNIT_NAMES = new Set([\"workday\", \"workdays\"]);\nconst WORKDAY_TO_DAY_FACTOR = 7 / 5; // 1 workday == 1.4 calendar days\n\n/** Whether `unit` is the synthetic \"workday\" unit (see module note above). */\nexport function isWorkdayUnit(unit: string | undefined): unit is string {\n return typeof unit === \"string\" && WORKDAY_UNIT_NAMES.has(unit);\n}\n\n/**\n * Validate `unit` against the known unit table.\n *\n * @returns `unit` unchanged in all cases. This does NOT normalize casing\n * or aliasing (units are strictly case-sensitive, see the module note\n * above). A unit the table doesn't recognize is still\n * returned as-is (not thrown), so callers must not assume a returned\n * string is actually convertible, check with {@link isConvertibleUnit}\n * or {@link canConvert} first if that matters.\n *\n * Kept as an identity function purely for API compatibility. It used to guard\n * a validity cache, which existed because validating a unit meant a\n * throw/catch round trip through the old dependency. Validation is now a Map\n * lookup, so the cache cost more than it saved: worse, it was capped at 1000\n * entries against a 1456-unit table, so any sweep over the full vocabulary\n * (which is exactly what LanguageService does to build completions) evicted\n * on almost every call. That one change took the full-table sweep from 7.7ms\n * to under 20us.\n */\nexport function resolveUnit(unit: string): string {\n return unit;\n}\n\n// MEASURE_KIND_NAMES now comes from the generated table (it is derived data,\n// so the generator emits it rather than it being retyped here). The reason it\n// is a module-level constant has not changed: getMeasure() runs at least twice\n// per conversion, and this used to be reallocated on every call.\n\n/**\n * Get the measure/dimension kind for `unit` (e.g. `\"length\"`, `\"mass\"`,\n * `\"temperature\"`), used to check whether two units are even in the same\n * dimension before attempting a conversion.\n *\n * @returns `undefined` if `unit` isn't recognized, rather than throwing.\n */\nexport function getMeasure(unit: string): string | undefined {\n // Workday is a Time-measure unit by convention (see isWorkdayUnit's doc\n // comment) and is not in the base table, so resolve its measure via \"day\"\n // instead of attempting the real lookup below.\n if (isWorkdayUnit(unit)) return getMeasure(\"day\");\n\n // Extended (custom) categories the base table has no measure kind for,\n // see ExtendedUnits.ts.\n const extended = EXTENDED_UNITS[unit];\n if (extended) return extended.measure;\n\n const entry = lookupUnit(unit);\n if (entry === undefined) return undefined;\n\n return MEASURE_KIND_NAMES[entry[0]];\n}\n\n/**\n * Check whether `from` can be converted to `to`. Same unit, or same\n * measure kind (length, mass, ...) and the underlying tables accept the pair.\n * Never throws; returns `false` on any failure.\n */\nexport function canConvert(from: string, to: string): boolean {\n if (from === to) return true;\n if (isWorkdayUnit(from) || isWorkdayUnit(to)) {\n const fromMeasure = getMeasure(from);\n const toMeasure = getMeasure(to);\n return !!fromMeasure && fromMeasure === toMeasure;\n }\n // One table read per side, comparing numeric kind ids. The old shape called\n // getMeasure() on each side (two more reads) purely to compare the resulting\n // STRINGS, then did a throwaway conversion to confirm what the kind check had\n // already established.\n const fromEntry = lookupUnit(from);\n const toEntry = lookupUnit(to);\n if (fromEntry !== undefined && toEntry !== undefined) {\n return fromEntry[0] === toEntry[0];\n }\n\n // Extended (custom) categories aren't in the base table at all, so they are\n // compared on their own measure names instead.\n const fromExtended = EXTENDED_UNITS[from];\n const toExtended = EXTENDED_UNITS[to];\n if (fromExtended !== undefined && toExtended !== undefined) {\n return fromExtended.measure === toExtended.measure;\n }\n\n // Mixed: one side is in the base table and the other is extended. That used\n // to be refused outright, on the grounds that the two measure spaces are\n // disjoint. They are not, once an extended unit names a measure the base\n // table also has: `furlong` is a length and so is `m`, and the ratio between\n // them is exactly what both tables already record.\n return bridgesToBaseMeasure(from, to) || bridgesToBaseMeasure(to, from);\n}\n\n/**\n * Whether `extendedUnit` extends a measure the base table also knows, so a\n * value in it can reach `baseUnit`.\n *\n * The bridge works because both tables express a unit as a ratio to the same\n * physical base: the generated table's length ratios are metres and its mass\n * ratios are grams, and an extended unit declaring `measure: \"length\"` states\n * its `toBase` in the same metres. Composing the two ratios is then ordinary\n * arithmetic rather than a second conversion system.\n *\n * A measure the base table has no concept of, such as pace, still fails here,\n * which is the behaviour this replaced and the reason the check is by measure\n * name rather than by presence in the extended table.\n */\nfunction bridgesToBaseMeasure(extendedUnit: string, baseUnit: string): boolean {\n const extended = EXTENDED_UNITS[extendedUnit];\n if (extended === undefined) return false;\n\n const base = lookupUnit(resolveUnit(baseUnit));\n if (base === undefined) return false;\n\n return MEASURE_KIND_NAMES[base[0]] === extended.measure;\n}\n\n/**\n * Convert `value` from unit `from` to unit `to`.\n *\n * Does not validate that the conversion is possible, callers should check\n * with {@link canConvert} first if `from`/`to` aren't already known-good.\n *\n * THROWS a RangeError for an unknown unit or a cross-measure pair. `VM.ts`'s\n * `extractDurationMs()` depends on that, see {@link convertRaw}.\n *\n * This used to memoize a per-pair conversion factor in an LFU cache. The cache\n * is gone: computing the factor is now two Map reads, while the cache cost a\n * template-string key allocation on every call plus the LFU's own frequency\n * bookkeeping, so it was slower than the work it avoided. Removing it is\n * bit-exact, not merely close: the cache stored `convertRaw(1, f, t)`, which is\n * exactly `fromRatio / toRatio`, and then multiplied, which is the identical\n * expression `convertRaw(value, f, t)` evaluates. It also deleted the special\n * case that existed only to keep offset-based temperature pairs out of a\n * factor cache.\n */\nexport function convertUnit(value: number, from: string, to: string): number {\n if (from === to) return value;\n\n // Fast path first: two ordinary units, which is nearly every call. Resolving\n // both here and handing the entries to convertResolved() avoids looking them\n // up again inside convertRaw(). Neither workdays nor extended units appear in\n // the base table, so they always fall through to the branches below and this\n // ordering cannot steal a case from them. UnitVocabulary.spec.ts pins that\n // the two vocabularies stay disjoint.\n const fromEntry = lookupUnit(from);\n const toEntry = lookupUnit(to);\n if (fromEntry !== undefined && toEntry !== undefined) {\n return convertResolved(value, from, to, fromEntry, toEntry);\n }\n\n // Workday <-> any other Time-measure unit: pivot through \"day\" using the\n // fixed 7/5 ratio (see isWorkdayUnit's doc comment above).\n if (isWorkdayUnit(from) && isWorkdayUnit(to)) return value; // \"workday\" <-> \"workdays\" alias\n if (isWorkdayUnit(from)) {\n const days = value * WORKDAY_TO_DAY_FACTOR;\n return to === \"day\" ? days : convertUnit(days, \"day\", to);\n }\n if (isWorkdayUnit(to)) {\n const days = from === \"day\" ? value : convertUnit(value, from, \"day\");\n return days / WORKDAY_TO_DAY_FACTOR;\n }\n\n // Extended (custom) categories the base table has no measure kind for\n // (see ExtendedUnits.ts), compute the ratio directly from each unit's\n // factor-to-base value instead of calling convertRaw(), which would throw\n // on an unrecognized unit string. Every extended category is a pure linear\n // ratio scale (no Temperature-style offset), so this is always safe.\n const fExt = EXTENDED_UNITS[from];\n const tExt = EXTENDED_UNITS[to];\n if (fExt !== undefined && tExt !== undefined) {\n return value * (fExt.toBase / tExt.toBase);\n }\n\n // One side extended, the other in the base table, sharing a measure. Convert\n // through the measure's base unit, which both tables state their ratios\n // against: an extended length declares its `toBase` in metres, and the\n // generated table's length ratios are metres too.\n if (fExt !== undefined && bridgesToBaseMeasure(from, to)) {\n return convertRaw(value * fExt.toBase, baseUnitFor(to), to);\n }\n if (tExt !== undefined && bridgesToBaseMeasure(to, from)) {\n return convertRaw(value, from, baseUnitFor(from)) / tExt.toBase;\n }\n\n // Offsets, cross-measure rejection and the unknown-unit throw all live in\n // convertRaw. Nothing is layered on top here any more.\n return convertRaw(value, from, to);\n}\n\n/**\n * The unit a measure states its ratios against, found from any unit in it.\n *\n * Read out of the table rather than hard-coded, so it cannot drift from the\n * ratios it has to agree with: the base is whichever unit of that measure has\n * a ratio of exactly one.\n */\nfunction baseUnitFor(unit: string): string {\n const entry = lookupUnit(resolveUnit(unit));\n if (entry === undefined) return unit;\n\n for (const symbol of Object.keys(UNIT_TABLE)) {\n const candidate = UNIT_TABLE[symbol];\n if (candidate[0] === entry[0] && candidate[1] === 1) return symbol;\n }\n return unit;\n}\n\n/**\n * List every unit symbol in the same measure/dimension as `unit` (wiki:\n * Units-Of-Measurement, \"Conversion Possibilities\", `sourceUnit to ?`\n * e.g. `cm to ?\"` → every Length unit). Excludes `unit` itself.\n *\n * Reads MEASURE_SYMBOLS, which is a curated symbols-only vocabulary and\n * deliberately NOT the keys of the unit table filtered by kind. The two\n * differ: Volume's symbols include `c` and `pt` but not `cup`/`cups`, and\n * Time's include `wk` and `mo` but not `week`/`month`. Deriving this list\n * from the unit table instead would roughly quadruple every answer.\n *\n * @returns `[]` if `unit` isn't recognized, rather than throwing.\n */\nexport function getConvertiblePossibilities(unit: string): string[] {\n const resolved = resolveUnit(unit);\n const entry = lookupUnit(resolved);\n if (entry === undefined) return [];\n const symbols = MEASURE_SYMBOLS[entry[0]];\n if (!symbols) return [];\n return symbols.filter((s) => s !== resolved);\n}\n\n/** Check whether `unit` is a unit the conversion tables recognize. Never throws. */\nexport function isConvertibleUnit(unit: string): boolean {\n if (isWorkdayUnit(unit)) return true;\n if (EXTENDED_UNITS[unit]) return true;\n return lookupUnit(resolveUnit(unit)) !== undefined;\n}\n\n/**\n * Convert `value` (in `unit`) to whichever unit of the same measure gives\n * the most human-readable magnitude, e.g. 1500 metres becomes 1.5 km. Falls\n * back to returning `value`/`unit` unchanged if `unit` isn't recognized,\n * which is what every extended unit and workday does.\n *\n * Note the chosen unit is drawn from the best-unit lists, which are not\n * restricted to spellings the lexer accepts: 0.5 l reports \"mL\".\n */\nexport function getBestUnit(value: number, unit: string): { value: number; unit: string } {\n const u = resolveUnit(unit);\n try {\n const result = convertToBestMetric(value, u);\n return { value: result.quantity, unit: result.unit };\n } catch {\n return { value, unit: u };\n }\n}\n\n// ── Rate and derived-unit conversion ───────────────────────────────────────\n//\n// A rate value carries a compound unit spelled \"numerator/denominator\" (e.g.\n// \"km/h\", \"m/s\"), see vm/Value.ts's rateValue(). Plain convertUnit() cannot\n// touch one, because neither half is the whole unit and getMeasure(\"km/h\") is\n// undefined. This section converts a rate to another rate, and bridges a rate\n// to the single-token speed spellings (mph, kph, mps, ...) that ExtendedUnits.ts\n// already carries, so \"100 km/h in mph\" and \"60 mph in km/h\" resolve instead of\n// reporting incompatible units.\n\n/** A rate reduced to a numerator unit over a denominator unit. */\ninterface RateForm {\n /** Magnitude, scaled so `value numerator/denominator` is the physical quantity. */\n value: number;\n /** Numerator unit spelling, or `\"\"` for a countless rate such as `30/week`. */\n numerator: string;\n /** Denominator unit spelling. */\n denominator: string;\n}\n\n/**\n * Express `value unit` as a numerator/denominator rate, or `null` when `unit`\n * is neither a compound rate spelling nor a single-token speed alias.\n *\n * A speed alias (mph, kph, ...) is one unit standing for a length/time rate, so\n * it expands to the base pair `m`/`s` with its value scaled by the alias's\n * metres-per-second factor. That collapses both inputs to one shape, so a\n * single routine handles rate/rate and rate/alias without a second code path.\n */\nfunction expandUnitToRate(value: number, unit: string): RateForm | null {\n const slash = unit.indexOf(\"/\");\n if (slash >= 0) {\n return { value, numerator: unit.slice(0, slash), denominator: unit.slice(slash + 1) };\n }\n const ext = EXTENDED_UNITS[unit];\n if (ext !== undefined && ext.measure === \"speed\") {\n // 1 alias == ext.toBase m/s, so `value alias` is `value * toBase` m/s.\n return { value: value * ext.toBase, numerator: \"m\", denominator: \"s\" };\n }\n return null;\n}\n\n/**\n * The factor that turns one `from` into `to` along a single rate axis, or\n * `null` when the two cannot line up.\n *\n * Same spelling needs no conversion. A countless axis (`\"\"`) only lines up with\n * another countless one, never with a real unit. Otherwise both sides must name\n * the same measure, which is what keeps a length numerator from pairing with a\n * mass one.\n */\nfunction rateAxisFactor(from: string, to: string): number | null {\n if (from === to) return 1;\n if (from === \"\" || to === \"\") return null;\n const fromMeasure = getMeasure(from);\n const toMeasure = getMeasure(to);\n if (fromMeasure === undefined || toMeasure === undefined || fromMeasure !== toMeasure) {\n return null;\n }\n return convertUnit(1, from, to);\n}\n\n/**\n * Convert `value` from a rate/speed unit `from` to a rate/speed unit `to`,\n * returning the converted magnitude, or `null` when the pair is not\n * rate-convertible (so the caller falls back to its own incompatible-units\n * handling).\n *\n * Handles rate to rate (`10 m/s in km/h`), rate to speed alias\n * (`100 km/h in mph`) and speed alias to rate (`60 mph in km/h`). Plain\n * same-measure pairs (`kph in mph`, `km in miles`) never reach here, they are\n * resolved by {@link convertUnit} first.\n *\n * The rule is the ordinary one for a quotient of quantities: convert the\n * numerator and the denominator each on their own, so `A/B -> C/D` scales by\n * `(A->C) / (B->D)`.\n */\nexport function convertRate(value: number, from: string, to: string): number | null {\n const source = expandUnitToRate(value, from);\n if (source === null) return null;\n\n // The target is either a rate spelling or a single-token speed alias. An\n // alias expands to the base m/s pair, and `targetScale` is what the base-form\n // magnitude is divided by to read out in the alias itself.\n let targetNumerator: string;\n let targetDenominator: string;\n let targetScale: number;\n const slash = to.indexOf(\"/\");\n if (slash >= 0) {\n targetNumerator = to.slice(0, slash);\n targetDenominator = to.slice(slash + 1);\n targetScale = 1;\n } else {\n const ext = EXTENDED_UNITS[to];\n if (ext === undefined || ext.measure !== \"speed\") return null;\n targetNumerator = \"m\";\n targetDenominator = \"s\";\n targetScale = ext.toBase;\n }\n\n const numeratorFactor = rateAxisFactor(source.numerator, targetNumerator);\n if (numeratorFactor === null) return null;\n const denominatorFactor = rateAxisFactor(source.denominator, targetDenominator);\n if (denominatorFactor === null) return null;\n\n return (source.value * numeratorFactor) / denominatorFactor / targetScale;\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { VariableResolver } from './chunk-GCM5JHMX.js';
|
|
2
|
-
import { sharedCurrencyExchange } from './chunk-
|
|
3
|
-
import { powNode, callNode, simplifySymbolic, sameShape, cancelSymbolic, complexNode, complex, RATIONAL_ZERO, rationalFromNumber, freeVariables, symbolicToEntry, rowMajorToColumnMajor, expandSymbolic, matrixMultiply, inverse, determinant, transpose, matrixPower,
|
|
4
|
-
import { faultedOperand, errorValue, symbolicValue, numberValue, bigIntValue, uomValue, matrixValue, percentageValue, stringValue, hexValue } from './chunk-
|
|
5
|
-
import { getMeasure, convertUnit } from './chunk-
|
|
2
|
+
import { sharedCurrencyExchange } from './chunk-Z7XGGLI2.js';
|
|
3
|
+
import { decimalFromInteger, toPolynomial, polyDegree, polyCoefficients, fromPolynomial, constNode, rationalDiv, rationalNeg, powNode, callNode, decimalCompare, isRationalZero, rationalMul, rationalSub, rationalAdd, rationalToNumber, rationalCompare, simplifySymbolic, sameShape, decimalFromNumberIfExact, decimalMultiply, decimalToNumber, decimalAdd, decimalNegate, cancelSymbolic, complexNode, complex, RATIONAL_ZERO, rationalFromNumber, freeVariables, symbolicToEntry, rowMajorToColumnMajor, expandSymbolic, matrixMultiply, inverse, determinant, transpose, matrixPower, exactIntegerSqrt, surdNode, rational, decimalIsZero, decimalDivide, decimalSubtract, decimalFromLiteral, decimalRound, substitute, varNode, isRationalOne, RATIONAL_ONE, polyUnivariateVar, COMPLEX_I, squareFreePart, coefficientGcd, polynomialDivide, isZeroPolynomial, exactRationalSqrt, symbolicKey, compareMonomials, signedSurdNode, monomialFromKey, monomialToKey, exactIntegerCbrt } from './chunk-NNQ2TYDF.js';
|
|
4
|
+
import { faultedOperand, errorValue, numberValueRational, numberValueUncertain, symbolicValue, numberValue, bigIntValue, uomValue, matrixValue, uomValueExact, percentageValue, stringValue, hexValue } from './chunk-267JPOTF.js';
|
|
5
|
+
import { getMeasure, convertUnit } from './chunk-MVTOCRV2.js';
|
|
6
6
|
import { UNIT_TABLE } from './chunk-V4XG5QF6.js';
|
|
7
|
-
import { ErrorFactory } from './chunk-
|
|
7
|
+
import { ErrorFactory } from './chunk-ERCOHGXD.js';
|
|
8
8
|
|
|
9
9
|
// src/symbolic/MultivariateFactor.ts
|
|
10
10
|
function exactRoot(value, degree) {
|
|
@@ -1134,15 +1134,59 @@ function largestFiniteMagnitude(a, b, c) {
|
|
|
1134
1134
|
function compareUom(l, r) {
|
|
1135
1135
|
const { lv, rv, sameMeasure } = unifyUom(l, r);
|
|
1136
1136
|
if (!sameMeasure) return { lv, rv, equal: false, sameMeasure: false };
|
|
1137
|
+
if (l.type === 6 /* Uom */ && r.type === 6 /* Uom */ && l.unit !== void 0 && l.unit === r.unit && l.exact !== void 0 && r.exact !== void 0 && sharedCurrencyExchange.isCurrency(l.unit)) {
|
|
1138
|
+
return { lv, rv, equal: decimalCompare(l.exact, r.exact) === 0, sameMeasure: true };
|
|
1139
|
+
}
|
|
1137
1140
|
if (lv === rv) return { lv, rv, equal: true, sameMeasure: true };
|
|
1138
1141
|
if (!Number.isFinite(lv) || !Number.isFinite(rv)) return { lv, rv, equal: false, sameMeasure: true };
|
|
1139
1142
|
const scale2 = largestFiniteMagnitude(lv, rv, r.toNumber());
|
|
1140
1143
|
return { lv, rv, equal: Math.abs(lv - rv) <= scale2 * UNIFIED_COMPARISON_TOLERANCE, sameMeasure: true };
|
|
1141
1144
|
}
|
|
1145
|
+
var MEASURE_NOUNS = {
|
|
1146
|
+
time: "duration",
|
|
1147
|
+
luminousIntensity: "luminous intensity"
|
|
1148
|
+
};
|
|
1149
|
+
var UNCOUNTABLE_MEASURES = /* @__PURE__ */ new Set(["money", "data"]);
|
|
1150
|
+
var COMBINE_VERBS = {
|
|
1151
|
+
add: "added",
|
|
1152
|
+
sub: "subtracted",
|
|
1153
|
+
mul: "multiplied",
|
|
1154
|
+
div: "divided"
|
|
1155
|
+
};
|
|
1156
|
+
function describeMeasure(unit) {
|
|
1157
|
+
if (sharedCurrencyExchange.isCurrency(unit)) return "money";
|
|
1158
|
+
const measure = getMeasure(unit);
|
|
1159
|
+
if (measure === void 0) return void 0;
|
|
1160
|
+
return MEASURE_NOUNS[measure] ?? measure;
|
|
1161
|
+
}
|
|
1162
|
+
function withMeasureArticle(noun) {
|
|
1163
|
+
if (UNCOUNTABLE_MEASURES.has(noun)) return noun;
|
|
1164
|
+
return /^[aeiou]/.test(noun) ? `an ${noun}` : `a ${noun}`;
|
|
1165
|
+
}
|
|
1166
|
+
function describeMeasureMismatch(lUnit, rUnit, verb) {
|
|
1167
|
+
const left = lUnit === void 0 ? void 0 : describeMeasure(lUnit);
|
|
1168
|
+
const right = rUnit === void 0 ? void 0 : describeMeasure(rUnit);
|
|
1169
|
+
if (left !== void 0 && right !== void 0 && left !== right) {
|
|
1170
|
+
return `${left} and ${right} cannot be ${verb}`;
|
|
1171
|
+
}
|
|
1172
|
+
return void 0;
|
|
1173
|
+
}
|
|
1174
|
+
function combineVerb(op) {
|
|
1175
|
+
return op !== void 0 ? COMBINE_VERBS[op] ?? "combined" : "combined";
|
|
1176
|
+
}
|
|
1177
|
+
function describeConversionMismatch(fromUnit, toUnit) {
|
|
1178
|
+
const from = describeMeasure(fromUnit);
|
|
1179
|
+
const to = describeMeasure(toUnit);
|
|
1180
|
+
if (from !== void 0 && to !== void 0 && from !== to) {
|
|
1181
|
+
return `${withMeasureArticle(from)} cannot be converted to ${withMeasureArticle(to)}`;
|
|
1182
|
+
}
|
|
1183
|
+
return void 0;
|
|
1184
|
+
}
|
|
1142
1185
|
function incomparableUnitsError(l, r) {
|
|
1143
1186
|
const lUnit = l.type === 6 /* Uom */ ? l.unit : void 0;
|
|
1144
1187
|
const rUnit = r.type === 6 /* Uom */ ? r.unit : void 0;
|
|
1145
|
-
|
|
1188
|
+
const named = describeMeasureMismatch(lUnit, rUnit, "compared");
|
|
1189
|
+
return errorValue("INCOMPATIBLE_UNITS", named ?? `Cannot compare incompatible units: ${lUnit ?? "?"} and ${rUnit ?? "?"}`);
|
|
1146
1190
|
}
|
|
1147
1191
|
function toBigIntOperand(v) {
|
|
1148
1192
|
if (v.type === 2 /* BigInt */) return v.value;
|
|
@@ -1182,6 +1226,121 @@ function power(base, exponent) {
|
|
|
1182
1226
|
if (base === -1 && !Number.isNaN(exponent)) return 1;
|
|
1183
1227
|
return Math.pow(base, exponent);
|
|
1184
1228
|
}
|
|
1229
|
+
function operandExactDecimal(v) {
|
|
1230
|
+
if (v.exact !== void 0) return v.exact;
|
|
1231
|
+
return decimalFromNumberIfExact(v.toNumber());
|
|
1232
|
+
}
|
|
1233
|
+
function exactMoneyOp(l, r, op) {
|
|
1234
|
+
const lMoney = l.type === 6 /* Uom */ && l.unit !== void 0 && l.exact !== void 0 && sharedCurrencyExchange.isCurrency(l.unit);
|
|
1235
|
+
const rMoney = r.type === 6 /* Uom */ && r.unit !== void 0 && r.exact !== void 0 && sharedCurrencyExchange.isCurrency(r.unit);
|
|
1236
|
+
if (!lMoney && !rMoney) return null;
|
|
1237
|
+
let ld;
|
|
1238
|
+
let rd;
|
|
1239
|
+
let unit;
|
|
1240
|
+
if (lMoney && rMoney) {
|
|
1241
|
+
if (l.unit !== r.unit || op === "div") return null;
|
|
1242
|
+
ld = l.exact;
|
|
1243
|
+
rd = r.exact;
|
|
1244
|
+
unit = l.unit;
|
|
1245
|
+
} else if (lMoney && r.type !== 6 /* Uom */) {
|
|
1246
|
+
ld = l.exact;
|
|
1247
|
+
unit = l.unit;
|
|
1248
|
+
rd = operandExactDecimal(r);
|
|
1249
|
+
} else if (rMoney && l.type !== 6 /* Uom */) {
|
|
1250
|
+
rd = r.exact;
|
|
1251
|
+
unit = r.unit;
|
|
1252
|
+
ld = operandExactDecimal(l);
|
|
1253
|
+
} else {
|
|
1254
|
+
return null;
|
|
1255
|
+
}
|
|
1256
|
+
if (ld === null || rd === null) return null;
|
|
1257
|
+
let result;
|
|
1258
|
+
switch (op) {
|
|
1259
|
+
case "add":
|
|
1260
|
+
result = decimalAdd(ld, rd);
|
|
1261
|
+
break;
|
|
1262
|
+
case "sub":
|
|
1263
|
+
result = decimalSubtract(ld, rd);
|
|
1264
|
+
break;
|
|
1265
|
+
case "mul":
|
|
1266
|
+
result = decimalMultiply(ld, rd);
|
|
1267
|
+
break;
|
|
1268
|
+
case "div":
|
|
1269
|
+
if (decimalIsZero(rd)) return null;
|
|
1270
|
+
result = decimalDivide(ld, rd);
|
|
1271
|
+
break;
|
|
1272
|
+
}
|
|
1273
|
+
return uomValueExact(decimalToNumber(result), unit, result);
|
|
1274
|
+
}
|
|
1275
|
+
function operandRational(v) {
|
|
1276
|
+
if (v.rational !== void 0) return v.rational;
|
|
1277
|
+
if ((v.type === 0 /* Number */ || v.type === 1 /* Hex */) && typeof v.value === "number" && Number.isInteger(v.value)) {
|
|
1278
|
+
return rational(BigInt(v.value));
|
|
1279
|
+
}
|
|
1280
|
+
return null;
|
|
1281
|
+
}
|
|
1282
|
+
function exactRationalOp(l, r, op) {
|
|
1283
|
+
const lr = operandRational(l);
|
|
1284
|
+
if (lr === null) return null;
|
|
1285
|
+
const rr = operandRational(r);
|
|
1286
|
+
if (rr === null) return null;
|
|
1287
|
+
if (op === "div" && isRationalZero(rr)) return null;
|
|
1288
|
+
let result;
|
|
1289
|
+
try {
|
|
1290
|
+
switch (op) {
|
|
1291
|
+
case "add":
|
|
1292
|
+
result = rationalAdd(lr, rr);
|
|
1293
|
+
break;
|
|
1294
|
+
case "sub":
|
|
1295
|
+
result = rationalSub(lr, rr);
|
|
1296
|
+
break;
|
|
1297
|
+
case "mul":
|
|
1298
|
+
result = rationalMul(lr, rr);
|
|
1299
|
+
break;
|
|
1300
|
+
case "div":
|
|
1301
|
+
result = rationalDiv(lr, rr);
|
|
1302
|
+
break;
|
|
1303
|
+
}
|
|
1304
|
+
} catch {
|
|
1305
|
+
return null;
|
|
1306
|
+
}
|
|
1307
|
+
return numberValueRational(rationalToNumber(result), result);
|
|
1308
|
+
}
|
|
1309
|
+
function uncertainOp(l, r, op) {
|
|
1310
|
+
if (l.type !== 0 /* Number */ || r.type !== 0 /* Number */) return null;
|
|
1311
|
+
const a = l.value;
|
|
1312
|
+
const b = r.value;
|
|
1313
|
+
const sa = l.uncertainty ?? 0;
|
|
1314
|
+
const sb = r.uncertainty ?? 0;
|
|
1315
|
+
let center;
|
|
1316
|
+
let sigma;
|
|
1317
|
+
switch (op) {
|
|
1318
|
+
case "add":
|
|
1319
|
+
center = a + b;
|
|
1320
|
+
sigma = Math.hypot(sa, sb);
|
|
1321
|
+
break;
|
|
1322
|
+
case "sub":
|
|
1323
|
+
center = a - b;
|
|
1324
|
+
sigma = Math.hypot(sa, sb);
|
|
1325
|
+
break;
|
|
1326
|
+
case "mul":
|
|
1327
|
+
center = a * b;
|
|
1328
|
+
sigma = Math.hypot(b * sa, a * sb);
|
|
1329
|
+
break;
|
|
1330
|
+
case "div":
|
|
1331
|
+
center = a / b;
|
|
1332
|
+
sigma = Math.hypot(sa / b, a * sb / (b * b));
|
|
1333
|
+
break;
|
|
1334
|
+
}
|
|
1335
|
+
return numberValueUncertain(center, sigma);
|
|
1336
|
+
}
|
|
1337
|
+
function compareRationalOperands(l, r) {
|
|
1338
|
+
const lr = operandRational(l);
|
|
1339
|
+
if (lr === null) return null;
|
|
1340
|
+
const rr = operandRational(r);
|
|
1341
|
+
if (rr === null) return null;
|
|
1342
|
+
return rationalCompare(lr, rr);
|
|
1343
|
+
}
|
|
1185
1344
|
function binaryOp(l, r, op, bigOp, symbolicOp) {
|
|
1186
1345
|
if (l.type === 13 /* Error */) return l;
|
|
1187
1346
|
if (r.type === 13 /* Error */) return r;
|
|
@@ -1209,11 +1368,16 @@ function binaryOp(l, r, op, bigOp, symbolicOp) {
|
|
|
1209
1368
|
return bigIntValue(lb + rb);
|
|
1210
1369
|
}
|
|
1211
1370
|
if (l.type === 6 /* Uom */ || r.type === 6 /* Uom */) {
|
|
1371
|
+
if (symbolicOp) {
|
|
1372
|
+
const exactMoney = exactMoneyOp(l, r, symbolicOp);
|
|
1373
|
+
if (exactMoney) return exactMoney;
|
|
1374
|
+
}
|
|
1212
1375
|
const { lv, rv, unit, sameMeasure } = unifyUom(l, r);
|
|
1213
1376
|
if (!sameMeasure) {
|
|
1214
1377
|
const lUnit = l.type === 6 /* Uom */ ? l.unit : void 0;
|
|
1215
1378
|
const rUnit = r.type === 6 /* Uom */ ? r.unit : void 0;
|
|
1216
|
-
|
|
1379
|
+
const named = describeMeasureMismatch(lUnit, rUnit, combineVerb(symbolicOp));
|
|
1380
|
+
return errorValue("INCOMPATIBLE_UNITS", named ?? `Cannot combine incompatible units: ${lUnit ?? "?"} and ${rUnit ?? "?"}`);
|
|
1217
1381
|
}
|
|
1218
1382
|
return uomValue(op(lv, rv), unit);
|
|
1219
1383
|
}
|
|
@@ -1288,6 +1452,57 @@ var OpRegistry = class {
|
|
|
1288
1452
|
};
|
|
1289
1453
|
var sharedOpRegistry = new OpRegistry();
|
|
1290
1454
|
|
|
1455
|
+
// src/vm/MoneyExact.ts
|
|
1456
|
+
var ONE_DECIMAL = decimalFromInteger(1);
|
|
1457
|
+
function moneyExactMagnitude(operand, unit) {
|
|
1458
|
+
if (!sharedCurrencyExchange.isCurrency(unit)) return null;
|
|
1459
|
+
return operand.exact ?? decimalFromNumberIfExact(operand.toNumber());
|
|
1460
|
+
}
|
|
1461
|
+
function decimalFromShortDecimal(n) {
|
|
1462
|
+
if (!Number.isFinite(n)) return null;
|
|
1463
|
+
if (Number.isInteger(n)) return decimalFromInteger(BigInt(n));
|
|
1464
|
+
const s = String(n);
|
|
1465
|
+
if (!/^-?\d+\.\d+$/.test(s)) return null;
|
|
1466
|
+
return decimalFromLiteral(s);
|
|
1467
|
+
}
|
|
1468
|
+
function scaleMoneyExact(amount, factor, unit) {
|
|
1469
|
+
const base = moneyExactMagnitude(amount, unit);
|
|
1470
|
+
const factorDecimal = decimalFromShortDecimal(factor);
|
|
1471
|
+
if (base !== null && factorDecimal !== null) {
|
|
1472
|
+
const result = decimalMultiply(base, factorDecimal);
|
|
1473
|
+
return uomValueExact(decimalToNumber(result), unit, result);
|
|
1474
|
+
}
|
|
1475
|
+
return uomValue(amount.toNumber() * factor, unit);
|
|
1476
|
+
}
|
|
1477
|
+
function scaleMoneyByPercent(money, unit, percent, sign) {
|
|
1478
|
+
const base = moneyExactMagnitude(money, unit);
|
|
1479
|
+
const percentDecimal = decimalFromShortDecimal(percent);
|
|
1480
|
+
if (base !== null && percentDecimal !== null) {
|
|
1481
|
+
const factor = decimalAdd(ONE_DECIMAL, sign === 1 ? percentDecimal : decimalNegate(percentDecimal));
|
|
1482
|
+
const result = decimalMultiply(base, factor);
|
|
1483
|
+
return uomValueExact(decimalToNumber(result), unit, result);
|
|
1484
|
+
}
|
|
1485
|
+
return uomValue(money.toNumber() * (1 + sign * percent), unit);
|
|
1486
|
+
}
|
|
1487
|
+
function onePlusRateDecimal(rate) {
|
|
1488
|
+
const rateDecimal = decimalFromShortDecimal(rate);
|
|
1489
|
+
return rateDecimal === null ? null : decimalAdd(ONE_DECIMAL, rateDecimal);
|
|
1490
|
+
}
|
|
1491
|
+
function removeTaxExact(money, unit, rate) {
|
|
1492
|
+
const base = moneyExactMagnitude(money, unit);
|
|
1493
|
+
const divisor = onePlusRateDecimal(rate);
|
|
1494
|
+
if (base === null || divisor === null || decimalIsZero(divisor)) return null;
|
|
1495
|
+
const quotient = decimalDivide(base, divisor);
|
|
1496
|
+
return uomValueExact(decimalToNumber(quotient), unit, quotient);
|
|
1497
|
+
}
|
|
1498
|
+
function taxInExact(money, unit, rate) {
|
|
1499
|
+
const base = moneyExactMagnitude(money, unit);
|
|
1500
|
+
const divisor = onePlusRateDecimal(rate);
|
|
1501
|
+
if (base === null || divisor === null || decimalIsZero(divisor)) return null;
|
|
1502
|
+
const tax = decimalSubtract(base, decimalDivide(base, divisor));
|
|
1503
|
+
return uomValueExact(decimalToNumber(tax), unit, tax);
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1291
1506
|
// src/symbolic/PartialFractions.ts
|
|
1292
1507
|
var APART_MAX_DEGREE = 12;
|
|
1293
1508
|
function multiply2(a, b) {
|
|
@@ -1958,9 +2173,10 @@ function extremum(args, wantLargest) {
|
|
|
1958
2173
|
if (!sameMeasure) {
|
|
1959
2174
|
const bestUnit = best.type === 6 /* Uom */ ? best.unit : void 0;
|
|
1960
2175
|
const otherUnit = a.type === 6 /* Uom */ ? a.unit : void 0;
|
|
2176
|
+
const named = describeMeasureMismatch(bestUnit, otherUnit, "compared");
|
|
1961
2177
|
return errorValue(
|
|
1962
2178
|
"INCOMPATIBLE_UNITS",
|
|
1963
|
-
`Cannot compare incompatible units: ${bestUnit ?? "?"} and ${otherUnit ?? "?"}`
|
|
2179
|
+
named ?? `Cannot compare incompatible units: ${bestUnit ?? "?"} and ${otherUnit ?? "?"}`
|
|
1964
2180
|
);
|
|
1965
2181
|
}
|
|
1966
2182
|
if (wantLargest ? rv > lv : rv < lv) best = a;
|
|
@@ -1973,6 +2189,25 @@ function keepUnit(operand, magnitude2) {
|
|
|
1973
2189
|
if (operand.type === 6 /* Uom */ && operand.unit !== void 0) return uomValue(magnitude2, operand.unit);
|
|
1974
2190
|
return numberValue(magnitude2);
|
|
1975
2191
|
}
|
|
2192
|
+
function roundToPlaces(source, places) {
|
|
2193
|
+
const p = Number.isFinite(places) ? Math.min(100, Math.max(0, Math.trunc(places))) : 0;
|
|
2194
|
+
if (source.exact !== void 0) {
|
|
2195
|
+
const rounded = decimalRound(source.exact, p);
|
|
2196
|
+
return withPlaces(source, decimalToNumber(rounded), p, rounded);
|
|
2197
|
+
}
|
|
2198
|
+
const value = source.toNumber();
|
|
2199
|
+
if (!Number.isFinite(value)) return withPlaces(source, value, p);
|
|
2200
|
+
const scale2 = Math.pow(10, p);
|
|
2201
|
+
const scaled = value * scale2;
|
|
2202
|
+
if (!Number.isFinite(scaled) || Math.abs(scaled) > Number.MAX_SAFE_INTEGER) return withPlaces(source, value, p);
|
|
2203
|
+
return withPlaces(source, Math.round(scaled) / scale2, p);
|
|
2204
|
+
}
|
|
2205
|
+
function withPlaces(source, magnitude2, places, exact) {
|
|
2206
|
+
const result = source.type === 6 /* Uom */ && source.unit !== void 0 ? uomValue(magnitude2, source.unit) : numberValue(magnitude2);
|
|
2207
|
+
result.decimalPlaces = places;
|
|
2208
|
+
if (exact !== void 0) result.exact = exact;
|
|
2209
|
+
return result;
|
|
2210
|
+
}
|
|
1976
2211
|
function nonFiniteEuclidOperand(a, b, name) {
|
|
1977
2212
|
if (Number.isFinite(a) && Number.isFinite(b)) return null;
|
|
1978
2213
|
const culprit = Number.isFinite(a) ? b : a;
|
|
@@ -2013,7 +2248,13 @@ var builtinFunctions = {
|
|
|
2013
2248
|
// round/ceil/floor keep a unit for the same reason abs does; see keepUnit().
|
|
2014
2249
|
6: (args) => keepUnit(args[0], Math.ceil(args[0].toNumber())),
|
|
2015
2250
|
7: (args) => keepUnit(args[0], Math.floor(args[0].toNumber())),
|
|
2016
|
-
8: (args) =>
|
|
2251
|
+
8: (args) => args.length >= 2 ? (
|
|
2252
|
+
// round(x, n): round to n decimal places and display at that precision.
|
|
2253
|
+
roundToPlaces(args[0], args[1].toNumber())
|
|
2254
|
+
) : (
|
|
2255
|
+
// round(x): nearest whole number, the way it always was.
|
|
2256
|
+
keepUnit(args[0], Math.round(args[0].toNumber()))
|
|
2257
|
+
),
|
|
2017
2258
|
// min/max: see extremum() for why the winner is carried around as a Value
|
|
2018
2259
|
// rather than as a running number.
|
|
2019
2260
|
9: (args) => extremum(args, false),
|
|
@@ -2357,8 +2598,8 @@ var builtinFunctions = {
|
|
|
2357
2598
|
58: (args) => {
|
|
2358
2599
|
const amount = args[0].toNumber();
|
|
2359
2600
|
const rate = args[1].toNumber();
|
|
2360
|
-
|
|
2361
|
-
return
|
|
2601
|
+
if (args[0].type === 6 /* Uom */) return scaleMoneyByPercent(args[0], args[0].unit, rate, 1);
|
|
2602
|
+
return numberValue(amount * (1 + rate));
|
|
2362
2603
|
},
|
|
2363
2604
|
// taxRemove(amount, rate) -> amount / (1 + rate), extracts the
|
|
2364
2605
|
// pre-tax amount from a tax-INCLUSIVE total. Backs "tax off $X at R%" /
|
|
@@ -2369,7 +2610,10 @@ var builtinFunctions = {
|
|
|
2369
2610
|
if (1 + rate <= 0) {
|
|
2370
2611
|
return errorValue("INVALID_RATE", `taxRemove: rate ${rate} makes (1 + rate) non-positive`);
|
|
2371
2612
|
}
|
|
2372
|
-
|
|
2613
|
+
if (args[0].type === 6 /* Uom */) {
|
|
2614
|
+
return removeTaxExact(args[0], args[0].unit, rate) ?? uomValue(amount / (1 + rate), args[0].unit);
|
|
2615
|
+
}
|
|
2616
|
+
return numberValue(amount / (1 + rate));
|
|
2373
2617
|
},
|
|
2374
2618
|
// inflationAdjust(amount, fromYear, toYear) -- CPI-based inflation
|
|
2375
2619
|
// adjustment between two arbitrary years, using the bundled CPI-U
|
|
@@ -2580,7 +2824,10 @@ var builtinFunctions = {
|
|
|
2580
2824
|
return errorValue("INVALID_RATE", `taxIn: rate ${rate} makes (1 + rate) non-positive`);
|
|
2581
2825
|
}
|
|
2582
2826
|
const tax = amount - amount / (1 + rate);
|
|
2583
|
-
|
|
2827
|
+
if (args[0].type === 6 /* Uom */) {
|
|
2828
|
+
return taxInExact(args[0], args[0].unit, rate) ?? uomValue(tax, args[0].unit);
|
|
2829
|
+
}
|
|
2830
|
+
return numberValue(tax);
|
|
2584
2831
|
},
|
|
2585
2832
|
// taxOn(amount, rate) -> amount * rate, the tax itself.
|
|
2586
2833
|
//
|
|
@@ -2592,8 +2839,8 @@ var builtinFunctions = {
|
|
|
2592
2839
|
86: (args) => {
|
|
2593
2840
|
const amount = args[0].toNumber();
|
|
2594
2841
|
const rate = args[1].toNumber();
|
|
2595
|
-
|
|
2596
|
-
return
|
|
2842
|
+
if (args[0].type === 6 /* Uom */) return scaleMoneyExact(args[0], rate, args[0].unit);
|
|
2843
|
+
return numberValue(amount * rate);
|
|
2597
2844
|
},
|
|
2598
2845
|
// ── Degree-taking trig (sind/cosd/tand and the inverses) ──────────────
|
|
2599
2846
|
// The "d" spellings take and return degrees rather than radians, which is
|
|
@@ -2783,16 +3030,7 @@ var builtinFunctions = {
|
|
|
2783
3030
|
// fractional part to round at all, and the round trip through 1e23 was
|
|
2784
3031
|
// pure loss. Asking for fewer decimal places than a number has cannot
|
|
2785
3032
|
// change it, so a value that is already whole is returned untouched.
|
|
2786
|
-
97: (args) =>
|
|
2787
|
-
const source = args[0];
|
|
2788
|
-
const value = source.toNumber();
|
|
2789
|
-
const places = args[1].toNumber();
|
|
2790
|
-
if (!Number.isFinite(value) || Number.isInteger(value)) return keepUnit(source, value);
|
|
2791
|
-
const scale2 = Math.pow(10, places);
|
|
2792
|
-
const scaled = value * scale2;
|
|
2793
|
-
if (!Number.isFinite(scaled) || Math.abs(scaled) > Number.MAX_SAFE_INTEGER) return keepUnit(source, value);
|
|
2794
|
-
return keepUnit(source, Math.round(scaled) / scale2);
|
|
2795
|
-
}
|
|
3033
|
+
97: (args) => roundToPlaces(args[0], args[1].toNumber())
|
|
2796
3034
|
};
|
|
2797
3035
|
function applyComplexAccessor(name, value) {
|
|
2798
3036
|
const node = valueToSymbolic(value);
|
|
@@ -2942,6 +3180,6 @@ function globalDagKey(name) {
|
|
|
2942
3180
|
return `global:${name}`;
|
|
2943
3181
|
}
|
|
2944
3182
|
|
|
2945
|
-
export { CPI_MAX_YEAR, CPI_MIN_YEAR, OpRegistry, SYMBOLIC_NATIVE_BUILTINS, adjustForInflation, allocatePluginFunctionIndex, asConverterRegistry, bigIntDivisionByZero, binaryOp, builtinFunctions, compareBigIntOperands, compareUom, createEngineContext, defaultEngineContext, globalDagKey, incomparableUnitsError, pluginFunctionRegistry, power, registerAsConverter, sharedGlobalVariableStore, sharedOpRegistry, solveEquationValues, symbolicBuiltin, symbolicNeg, symbolicPow, toBigIntOperand, unifyUom, unregisterAsConverter };
|
|
2946
|
-
//# sourceMappingURL=chunk-
|
|
2947
|
-
//# sourceMappingURL=chunk-
|
|
3183
|
+
export { CPI_MAX_YEAR, CPI_MIN_YEAR, OpRegistry, SYMBOLIC_NATIVE_BUILTINS, adjustForInflation, allocatePluginFunctionIndex, asConverterRegistry, bigIntDivisionByZero, binaryOp, builtinFunctions, compareBigIntOperands, compareRationalOperands, compareUom, createEngineContext, defaultEngineContext, describeConversionMismatch, exactRationalOp, globalDagKey, incomparableUnitsError, moneyExactMagnitude, pluginFunctionRegistry, power, registerAsConverter, scaleMoneyByPercent, scaleMoneyExact, sharedGlobalVariableStore, sharedOpRegistry, solveEquationValues, solveForVariable, symbolicBuiltin, symbolicNeg, symbolicPow, toBigIntOperand, uncertainOp, unifyUom, unregisterAsConverter };
|
|
3184
|
+
//# sourceMappingURL=chunk-NKW7LKYU.js.map
|
|
3185
|
+
//# sourceMappingURL=chunk-NKW7LKYU.js.map
|