@azx-pbc/axiom-runtime 0.0.0-stage → 0.0.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 -0
- package/README.md +714 -2
- package/dist/cache/index.d.ts +191 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +361 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/canonical/jcs.d.ts +78 -0
- package/dist/canonical/jcs.d.ts.map +1 -0
- package/dist/canonical/jcs.js +500 -0
- package/dist/canonical/jcs.js.map +1 -0
- package/dist/canonical/restricted-json.d.ts +7 -0
- package/dist/canonical/restricted-json.d.ts.map +1 -0
- package/dist/canonical/restricted-json.js +318 -0
- package/dist/canonical/restricted-json.js.map +1 -0
- package/dist/canonical/restricted-value.d.ts +59 -0
- package/dist/canonical/restricted-value.d.ts.map +1 -0
- package/dist/canonical/restricted-value.js +156 -0
- package/dist/canonical/restricted-value.js.map +1 -0
- package/dist/canonical/restricted.d.ts +85 -0
- package/dist/canonical/restricted.d.ts.map +1 -0
- package/dist/canonical/restricted.js +163 -0
- package/dist/canonical/restricted.js.map +1 -0
- package/dist/canonical/signature.d.ts +38 -0
- package/dist/canonical/signature.d.ts.map +1 -0
- package/dist/canonical/signature.js +47 -0
- package/dist/canonical/signature.js.map +1 -0
- package/dist/eval/access/delivery.d.ts +63 -0
- package/dist/eval/access/delivery.d.ts.map +1 -0
- package/dist/eval/access/delivery.js +98 -0
- package/dist/eval/access/delivery.js.map +1 -0
- package/dist/eval/access/overlay.d.ts +72 -0
- package/dist/eval/access/overlay.d.ts.map +1 -0
- package/dist/eval/access/overlay.js +402 -0
- package/dist/eval/access/overlay.js.map +1 -0
- package/dist/eval/access/projection.d.ts +159 -0
- package/dist/eval/access/projection.d.ts.map +1 -0
- package/dist/eval/access/projection.js +211 -0
- package/dist/eval/access/projection.js.map +1 -0
- package/dist/eval/access/window.d.ts +128 -0
- package/dist/eval/access/window.d.ts.map +1 -0
- package/dist/eval/access/window.js +254 -0
- package/dist/eval/access/window.js.map +1 -0
- package/dist/eval/access/write.d.ts +113 -0
- package/dist/eval/access/write.d.ts.map +1 -0
- package/dist/eval/access/write.js +119 -0
- package/dist/eval/access/write.js.map +1 -0
- package/dist/eval/addressing.d.ts +131 -0
- package/dist/eval/addressing.d.ts.map +1 -0
- package/dist/eval/addressing.js +270 -0
- package/dist/eval/addressing.js.map +1 -0
- package/dist/eval/budget.d.ts +143 -0
- package/dist/eval/budget.d.ts.map +1 -0
- package/dist/eval/budget.js +387 -0
- package/dist/eval/budget.js.map +1 -0
- package/dist/eval/computed.d.ts +46 -0
- package/dist/eval/computed.d.ts.map +1 -0
- package/dist/eval/computed.js +89 -0
- package/dist/eval/computed.js.map +1 -0
- package/dist/eval/denials.d.ts +64 -0
- package/dist/eval/denials.d.ts.map +1 -0
- package/dist/eval/denials.js +87 -0
- package/dist/eval/denials.js.map +1 -0
- package/dist/eval/engine/cancellation.d.ts +12 -0
- package/dist/eval/engine/cancellation.d.ts.map +1 -0
- package/dist/eval/engine/cancellation.js +56 -0
- package/dist/eval/engine/cancellation.js.map +1 -0
- package/dist/eval/engine/delta.d.ts +104 -0
- package/dist/eval/engine/delta.d.ts.map +1 -0
- package/dist/eval/engine/delta.js +466 -0
- package/dist/eval/engine/delta.js.map +1 -0
- package/dist/eval/engine/deps.d.ts +136 -0
- package/dist/eval/engine/deps.d.ts.map +1 -0
- package/dist/eval/engine/deps.js +345 -0
- package/dist/eval/engine/deps.js.map +1 -0
- package/dist/eval/engine/identity.d.ts +128 -0
- package/dist/eval/engine/identity.d.ts.map +1 -0
- package/dist/eval/engine/identity.js +398 -0
- package/dist/eval/engine/identity.js.map +1 -0
- package/dist/eval/engine/index.d.ts +200 -0
- package/dist/eval/engine/index.d.ts.map +1 -0
- package/dist/eval/engine/index.js +1242 -0
- package/dist/eval/engine/index.js.map +1 -0
- package/dist/eval/engine/measurement.d.ts +23 -0
- package/dist/eval/engine/measurement.d.ts.map +1 -0
- package/dist/eval/engine/measurement.js +42 -0
- package/dist/eval/engine/measurement.js.map +1 -0
- package/dist/eval/engine/naive.d.ts +19 -0
- package/dist/eval/engine/naive.d.ts.map +1 -0
- package/dist/eval/engine/naive.js +59 -0
- package/dist/eval/engine/naive.js.map +1 -0
- package/dist/eval/engine/ops.d.ts +214 -0
- package/dist/eval/engine/ops.d.ts.map +1 -0
- package/dist/eval/engine/ops.js +1422 -0
- package/dist/eval/engine/ops.js.map +1 -0
- package/dist/eval/engine/patches.d.ts +40 -0
- package/dist/eval/engine/patches.d.ts.map +1 -0
- package/dist/eval/engine/patches.js +125 -0
- package/dist/eval/engine/patches.js.map +1 -0
- package/dist/eval/engine/ports.d.ts +71 -0
- package/dist/eval/engine/ports.d.ts.map +1 -0
- package/dist/eval/engine/ports.js +2 -0
- package/dist/eval/engine/ports.js.map +1 -0
- package/dist/eval/engine/session.d.ts +116 -0
- package/dist/eval/engine/session.d.ts.map +1 -0
- package/dist/eval/engine/session.js +653 -0
- package/dist/eval/engine/session.js.map +1 -0
- package/dist/eval/engine/snapshot.d.ts +97 -0
- package/dist/eval/engine/snapshot.d.ts.map +1 -0
- package/dist/eval/engine/snapshot.js +221 -0
- package/dist/eval/engine/snapshot.js.map +1 -0
- package/dist/eval/engine/subscriptions.d.ts +47 -0
- package/dist/eval/engine/subscriptions.d.ts.map +1 -0
- package/dist/eval/engine/subscriptions.js +103 -0
- package/dist/eval/engine/subscriptions.js.map +1 -0
- package/dist/eval/engine/trace.d.ts +77 -0
- package/dist/eval/engine/trace.d.ts.map +1 -0
- package/dist/eval/engine/trace.js +140 -0
- package/dist/eval/engine/trace.js.map +1 -0
- package/dist/eval/error-diagnostic.d.ts +26 -0
- package/dist/eval/error-diagnostic.d.ts.map +1 -0
- package/dist/eval/error-diagnostic.js +63 -0
- package/dist/eval/error-diagnostic.js.map +1 -0
- package/dist/eval/evaluate-expr.d.ts +44 -0
- package/dist/eval/evaluate-expr.d.ts.map +1 -0
- package/dist/eval/evaluate-expr.js +149 -0
- package/dist/eval/evaluate-expr.js.map +1 -0
- package/dist/eval/evaluate.d.ts +282 -0
- package/dist/eval/evaluate.d.ts.map +1 -0
- package/dist/eval/evaluate.js +391 -0
- package/dist/eval/evaluate.js.map +1 -0
- package/dist/eval/evolution/relocate.d.ts +72 -0
- package/dist/eval/evolution/relocate.d.ts.map +1 -0
- package/dist/eval/evolution/relocate.js +427 -0
- package/dist/eval/evolution/relocate.js.map +1 -0
- package/dist/eval/evolution/select.d.ts +11 -0
- package/dist/eval/evolution/select.d.ts.map +1 -0
- package/dist/eval/evolution/select.js +53 -0
- package/dist/eval/evolution/select.js.map +1 -0
- package/dist/eval/evolution/upcast.d.ts +13 -0
- package/dist/eval/evolution/upcast.d.ts.map +1 -0
- package/dist/eval/evolution/upcast.js +88 -0
- package/dist/eval/evolution/upcast.js.map +1 -0
- package/dist/eval/expr/aggregates.d.ts +75 -0
- package/dist/eval/expr/aggregates.d.ts.map +1 -0
- package/dist/eval/expr/aggregates.js +991 -0
- package/dist/eval/expr/aggregates.js.map +1 -0
- package/dist/eval/expr/arithmetic.d.ts +26 -0
- package/dist/eval/expr/arithmetic.d.ts.map +1 -0
- package/dist/eval/expr/arithmetic.js +387 -0
- package/dist/eval/expr/arithmetic.js.map +1 -0
- package/dist/eval/expr/between.d.ts +17 -0
- package/dist/eval/expr/between.d.ts.map +1 -0
- package/dist/eval/expr/between.js +46 -0
- package/dist/eval/expr/between.js.map +1 -0
- package/dist/eval/expr/binder.d.ts +96 -0
- package/dist/eval/expr/binder.d.ts.map +1 -0
- package/dist/eval/expr/binder.js +253 -0
- package/dist/eval/expr/binder.js.map +1 -0
- package/dist/eval/expr/call-dispatch.d.ts +28 -0
- package/dist/eval/expr/call-dispatch.d.ts.map +1 -0
- package/dist/eval/expr/call-dispatch.js +114 -0
- package/dist/eval/expr/call-dispatch.js.map +1 -0
- package/dist/eval/expr/collections.d.ts +20 -0
- package/dist/eval/expr/collections.d.ts.map +1 -0
- package/dist/eval/expr/collections.js +66 -0
- package/dist/eval/expr/collections.js.map +1 -0
- package/dist/eval/expr/compare.d.ts +36 -0
- package/dist/eval/expr/compare.d.ts.map +1 -0
- package/dist/eval/expr/compare.js +115 -0
- package/dist/eval/expr/compare.js.map +1 -0
- package/dist/eval/expr/datasets.d.ts +28 -0
- package/dist/eval/expr/datasets.d.ts.map +1 -0
- package/dist/eval/expr/datasets.js +304 -0
- package/dist/eval/expr/datasets.js.map +1 -0
- package/dist/eval/expr/digest.d.ts +23 -0
- package/dist/eval/expr/digest.d.ts.map +1 -0
- package/dist/eval/expr/digest.js +89 -0
- package/dist/eval/expr/digest.js.map +1 -0
- package/dist/eval/expr/domains.d.ts +19 -0
- package/dist/eval/expr/domains.d.ts.map +1 -0
- package/dist/eval/expr/domains.js +18 -0
- package/dist/eval/expr/domains.js.map +1 -0
- package/dist/eval/expr/host.d.ts +152 -0
- package/dist/eval/expr/host.d.ts.map +1 -0
- package/dist/eval/expr/host.js +36 -0
- package/dist/eval/expr/host.js.map +1 -0
- package/dist/eval/expr/lists.d.ts +24 -0
- package/dist/eval/expr/lists.d.ts.map +1 -0
- package/dist/eval/expr/lists.js +155 -0
- package/dist/eval/expr/lists.js.map +1 -0
- package/dist/eval/expr/member.d.ts +15 -0
- package/dist/eval/expr/member.d.ts.map +1 -0
- package/dist/eval/expr/member.js +32 -0
- package/dist/eval/expr/member.js.map +1 -0
- package/dist/eval/expr/money-ops.d.ts +10 -0
- package/dist/eval/expr/money-ops.d.ts.map +1 -0
- package/dist/eval/expr/money-ops.js +17 -0
- package/dist/eval/expr/money-ops.js.map +1 -0
- package/dist/eval/expr/operands.d.ts +27 -0
- package/dist/eval/expr/operands.d.ts.map +1 -0
- package/dist/eval/expr/operands.js +167 -0
- package/dist/eval/expr/operands.js.map +1 -0
- package/dist/eval/expr/presence.d.ts +27 -0
- package/dist/eval/expr/presence.d.ts.map +1 -0
- package/dist/eval/expr/presence.js +140 -0
- package/dist/eval/expr/presence.js.map +1 -0
- package/dist/eval/expr/records.d.ts +22 -0
- package/dist/eval/expr/records.d.ts.map +1 -0
- package/dist/eval/expr/records.js +101 -0
- package/dist/eval/expr/records.js.map +1 -0
- package/dist/eval/expr/rule-refs.d.ts +25 -0
- package/dist/eval/expr/rule-refs.d.ts.map +1 -0
- package/dist/eval/expr/rule-refs.js +60 -0
- package/dist/eval/expr/rule-refs.js.map +1 -0
- package/dist/eval/expr/sequences.d.ts +26 -0
- package/dist/eval/expr/sequences.d.ts.map +1 -0
- package/dist/eval/expr/sequences.js +151 -0
- package/dist/eval/expr/sequences.js.map +1 -0
- package/dist/eval/expr/value.d.ts +99 -0
- package/dist/eval/expr/value.d.ts.map +1 -0
- package/dist/eval/expr/value.js +14 -0
- package/dist/eval/expr/value.js.map +1 -0
- package/dist/eval/expression.d.ts +142 -0
- package/dist/eval/expression.d.ts.map +1 -0
- package/dist/eval/expression.js +446 -0
- package/dist/eval/expression.js.map +1 -0
- package/dist/eval/firing.d.ts +68 -0
- package/dist/eval/firing.d.ts.map +1 -0
- package/dist/eval/firing.js +222 -0
- package/dist/eval/firing.js.map +1 -0
- package/dist/eval/gate.d.ts +110 -0
- package/dist/eval/gate.d.ts.map +1 -0
- package/dist/eval/gate.js +278 -0
- package/dist/eval/gate.js.map +1 -0
- package/dist/eval/layout-visibility.d.ts +18 -0
- package/dist/eval/layout-visibility.d.ts.map +1 -0
- package/dist/eval/layout-visibility.js +61 -0
- package/dist/eval/layout-visibility.js.map +1 -0
- package/dist/eval/option-availability.d.ts +26 -0
- package/dist/eval/option-availability.d.ts.map +1 -0
- package/dist/eval/option-availability.js +580 -0
- package/dist/eval/option-availability.js.map +1 -0
- package/dist/eval/options-boundary.d.ts +15 -0
- package/dist/eval/options-boundary.d.ts.map +1 -0
- package/dist/eval/options-boundary.js +40 -0
- package/dist/eval/options-boundary.js.map +1 -0
- package/dist/eval/options.d.ts +99 -0
- package/dist/eval/options.d.ts.map +1 -0
- package/dist/eval/options.js +96 -0
- package/dist/eval/options.js.map +1 -0
- package/dist/eval/overrides.d.ts +116 -0
- package/dist/eval/overrides.d.ts.map +1 -0
- package/dist/eval/overrides.js +176 -0
- package/dist/eval/overrides.js.map +1 -0
- package/dist/eval/paths.d.ts +25 -0
- package/dist/eval/paths.d.ts.map +1 -0
- package/dist/eval/paths.js +47 -0
- package/dist/eval/paths.js.map +1 -0
- package/dist/eval/presentation-reads.d.ts +20 -0
- package/dist/eval/presentation-reads.d.ts.map +1 -0
- package/dist/eval/presentation-reads.js +2 -0
- package/dist/eval/presentation-reads.js.map +1 -0
- package/dist/eval/presentation.d.ts +122 -0
- package/dist/eval/presentation.d.ts.map +1 -0
- package/dist/eval/presentation.js +255 -0
- package/dist/eval/presentation.js.map +1 -0
- package/dist/eval/reader/context-value.d.ts +41 -0
- package/dist/eval/reader/context-value.d.ts.map +1 -0
- package/dist/eval/reader/context-value.js +129 -0
- package/dist/eval/reader/context-value.js.map +1 -0
- package/dist/eval/reader/covered.d.ts +53 -0
- package/dist/eval/reader/covered.d.ts.map +1 -0
- package/dist/eval/reader/covered.js +139 -0
- package/dist/eval/reader/covered.js.map +1 -0
- package/dist/eval/reader/declarations.d.ts +182 -0
- package/dist/eval/reader/declarations.d.ts.map +1 -0
- package/dist/eval/reader/declarations.js +153 -0
- package/dist/eval/reader/declarations.js.map +1 -0
- package/dist/eval/reader/member-access.d.ts +87 -0
- package/dist/eval/reader/member-access.d.ts.map +1 -0
- package/dist/eval/reader/member-access.js +212 -0
- package/dist/eval/reader/member-access.js.map +1 -0
- package/dist/eval/reader/memo.d.ts +34 -0
- package/dist/eval/reader/memo.d.ts.map +1 -0
- package/dist/eval/reader/memo.js +67 -0
- package/dist/eval/reader/memo.js.map +1 -0
- package/dist/eval/reader/overlay.d.ts +74 -0
- package/dist/eval/reader/overlay.d.ts.map +1 -0
- package/dist/eval/reader/overlay.js +365 -0
- package/dist/eval/reader/overlay.js.map +1 -0
- package/dist/eval/reader/questions.d.ts +37 -0
- package/dist/eval/reader/questions.d.ts.map +1 -0
- package/dist/eval/reader/questions.js +78 -0
- package/dist/eval/reader/questions.js.map +1 -0
- package/dist/eval/reader/resolve.d.ts +84 -0
- package/dist/eval/reader/resolve.d.ts.map +1 -0
- package/dist/eval/reader/resolve.js +310 -0
- package/dist/eval/reader/resolve.js.map +1 -0
- package/dist/eval/reader/value-read.d.ts +50 -0
- package/dist/eval/reader/value-read.d.ts.map +1 -0
- package/dist/eval/reader/value-read.js +133 -0
- package/dist/eval/reader/value-read.js.map +1 -0
- package/dist/eval/reader/withheld.d.ts +48 -0
- package/dist/eval/reader/withheld.d.ts.map +1 -0
- package/dist/eval/reader/withheld.js +108 -0
- package/dist/eval/reader/withheld.js.map +1 -0
- package/dist/eval/reader-paths.d.ts +24 -0
- package/dist/eval/reader-paths.d.ts.map +1 -0
- package/dist/eval/reader-paths.js +23 -0
- package/dist/eval/reader-paths.js.map +1 -0
- package/dist/eval/reader.d.ts +281 -0
- package/dist/eval/reader.d.ts.map +1 -0
- package/dist/eval/reader.js +560 -0
- package/dist/eval/reader.js.map +1 -0
- package/dist/eval/receipt.d.ts +37 -0
- package/dist/eval/receipt.d.ts.map +1 -0
- package/dist/eval/receipt.js +222 -0
- package/dist/eval/receipt.js.map +1 -0
- package/dist/eval/report/assemble.d.ts +84 -0
- package/dist/eval/report/assemble.d.ts.map +1 -0
- package/dist/eval/report/assemble.js +277 -0
- package/dist/eval/report/assemble.js.map +1 -0
- package/dist/eval/report/fold.d.ts +18 -0
- package/dist/eval/report/fold.d.ts.map +1 -0
- package/dist/eval/report/fold.js +58 -0
- package/dist/eval/report/fold.js.map +1 -0
- package/dist/eval/rule/alternatives.d.ts +23 -0
- package/dist/eval/rule/alternatives.d.ts.map +1 -0
- package/dist/eval/rule/alternatives.js +46 -0
- package/dist/eval/rule/alternatives.js.map +1 -0
- package/dist/eval/rule/behaviour.d.ts +47 -0
- package/dist/eval/rule/behaviour.d.ts.map +1 -0
- package/dist/eval/rule/behaviour.js +249 -0
- package/dist/eval/rule/behaviour.js.map +1 -0
- package/dist/eval/rule/compute.d.ts +46 -0
- package/dist/eval/rule/compute.d.ts.map +1 -0
- package/dist/eval/rule/compute.js +158 -0
- package/dist/eval/rule/compute.js.map +1 -0
- package/dist/eval/rule/create-state.d.ts +42 -0
- package/dist/eval/rule/create-state.d.ts.map +1 -0
- package/dist/eval/rule/create-state.js +134 -0
- package/dist/eval/rule/create-state.js.map +1 -0
- package/dist/eval/rule/diagnostics.d.ts +24 -0
- package/dist/eval/rule/diagnostics.d.ts.map +1 -0
- package/dist/eval/rule/diagnostics.js +45 -0
- package/dist/eval/rule/diagnostics.js.map +1 -0
- package/dist/eval/rule/execution.d.ts +24 -0
- package/dist/eval/rule/execution.d.ts.map +1 -0
- package/dist/eval/rule/execution.js +495 -0
- package/dist/eval/rule/execution.js.map +1 -0
- package/dist/eval/rule/gate.d.ts +12 -0
- package/dist/eval/rule/gate.d.ts.map +1 -0
- package/dist/eval/rule/gate.js +34 -0
- package/dist/eval/rule/gate.js.map +1 -0
- package/dist/eval/rule/item.d.ts +11 -0
- package/dist/eval/rule/item.d.ts.map +1 -0
- package/dist/eval/rule/item.js +265 -0
- package/dist/eval/rule/item.js.map +1 -0
- package/dist/eval/rule/prepare.d.ts +64 -0
- package/dist/eval/rule/prepare.d.ts.map +1 -0
- package/dist/eval/rule/prepare.js +131 -0
- package/dist/eval/rule/prepare.js.map +1 -0
- package/dist/eval/rule/result.d.ts +97 -0
- package/dist/eval/rule/result.d.ts.map +1 -0
- package/dist/eval/rule/result.js +347 -0
- package/dist/eval/rule/result.js.map +1 -0
- package/dist/eval/rule/runner.d.ts +128 -0
- package/dist/eval/rule/runner.d.ts.map +1 -0
- package/dist/eval/rule/runner.js +296 -0
- package/dist/eval/rule/runner.js.map +1 -0
- package/dist/eval/rule/screen.d.ts +32 -0
- package/dist/eval/rule/screen.d.ts.map +1 -0
- package/dist/eval/rule/screen.js +73 -0
- package/dist/eval/rule/screen.js.map +1 -0
- package/dist/eval/rule/state.d.ts +137 -0
- package/dist/eval/rule/state.d.ts.map +1 -0
- package/dist/eval/rule/state.js +2 -0
- package/dist/eval/rule/state.js.map +1 -0
- package/dist/eval/rule/steps.d.ts +44 -0
- package/dist/eval/rule/steps.d.ts.map +1 -0
- package/dist/eval/rule/steps.js +367 -0
- package/dist/eval/rule/steps.js.map +1 -0
- package/dist/eval/rule/visibility.d.ts +18 -0
- package/dist/eval/rule/visibility.d.ts.map +1 -0
- package/dist/eval/rule/visibility.js +79 -0
- package/dist/eval/rule/visibility.js.map +1 -0
- package/dist/eval/seal.d.ts +74 -0
- package/dist/eval/seal.d.ts.map +1 -0
- package/dist/eval/seal.js +154 -0
- package/dist/eval/seal.js.map +1 -0
- package/dist/eval/signature-coverage.d.ts +19 -0
- package/dist/eval/signature-coverage.d.ts.map +1 -0
- package/dist/eval/signature-coverage.js +160 -0
- package/dist/eval/signature-coverage.js.map +1 -0
- package/dist/eval/state/derive.d.ts +72 -0
- package/dist/eval/state/derive.d.ts.map +1 -0
- package/dist/eval/state/derive.js +61 -0
- package/dist/eval/state/derive.js.map +1 -0
- package/dist/eval/state/describe.d.ts +18 -0
- package/dist/eval/state/describe.d.ts.map +1 -0
- package/dist/eval/state/describe.js +19 -0
- package/dist/eval/state/describe.js.map +1 -0
- package/dist/eval/state/field-state.d.ts +471 -0
- package/dist/eval/state/field-state.d.ts.map +1 -0
- package/dist/eval/state/field-state.js +1604 -0
- package/dist/eval/state/field-state.js.map +1 -0
- package/dist/eval/state/measurement.d.ts +136 -0
- package/dist/eval/state/measurement.d.ts.map +1 -0
- package/dist/eval/state/measurement.js +209 -0
- package/dist/eval/state/measurement.js.map +1 -0
- package/dist/eval/state/options.d.ts +21 -0
- package/dist/eval/state/options.d.ts.map +1 -0
- package/dist/eval/state/options.js +3 -0
- package/dist/eval/state/options.js.map +1 -0
- package/dist/eval/state/readiness.d.ts +400 -0
- package/dist/eval/state/readiness.d.ts.map +1 -0
- package/dist/eval/state/readiness.js +1067 -0
- package/dist/eval/state/readiness.js.map +1 -0
- package/dist/eval/state/snapshot.d.ts +130 -0
- package/dist/eval/state/snapshot.d.ts.map +1 -0
- package/dist/eval/state/snapshot.js +35 -0
- package/dist/eval/state/snapshot.js.map +1 -0
- package/dist/eval/state/unavailable-options.d.ts +54 -0
- package/dist/eval/state/unavailable-options.d.ts.map +1 -0
- package/dist/eval/state/unavailable-options.js +82 -0
- package/dist/eval/state/unavailable-options.js.map +1 -0
- package/dist/eval/state/value-state.d.ts +38 -0
- package/dist/eval/state/value-state.d.ts.map +1 -0
- package/dist/eval/state/value-state.js +52 -0
- package/dist/eval/state/value-state.js.map +1 -0
- package/dist/eval/submission/admission.d.ts +50 -0
- package/dist/eval/submission/admission.d.ts.map +1 -0
- package/dist/eval/submission/admission.js +174 -0
- package/dist/eval/submission/admission.js.map +1 -0
- package/dist/eval/submission/authority.d.ts +71 -0
- package/dist/eval/submission/authority.d.ts.map +1 -0
- package/dist/eval/submission/authority.js +118 -0
- package/dist/eval/submission/authority.js.map +1 -0
- package/dist/eval/submission/datasets.d.ts +28 -0
- package/dist/eval/submission/datasets.d.ts.map +1 -0
- package/dist/eval/submission/datasets.js +109 -0
- package/dist/eval/submission/datasets.js.map +1 -0
- package/dist/eval/submission/index.d.ts +15 -0
- package/dist/eval/submission/index.d.ts.map +1 -0
- package/dist/eval/submission/index.js +13 -0
- package/dist/eval/submission/index.js.map +1 -0
- package/dist/eval/submission/refusals.d.ts +103 -0
- package/dist/eval/submission/refusals.d.ts.map +1 -0
- package/dist/eval/submission/refusals.js +15 -0
- package/dist/eval/submission/refusals.js.map +1 -0
- package/dist/eval/submission/signatures.d.ts +7 -0
- package/dist/eval/submission/signatures.d.ts.map +1 -0
- package/dist/eval/submission/signatures.js +215 -0
- package/dist/eval/submission/signatures.js.map +1 -0
- package/dist/eval/submission/writes.d.ts +51 -0
- package/dist/eval/submission/writes.d.ts.map +1 -0
- package/dist/eval/submission/writes.js +203 -0
- package/dist/eval/submission/writes.js.map +1 -0
- package/dist/eval/submission.d.ts +53 -0
- package/dist/eval/submission.d.ts.map +1 -0
- package/dist/eval/submission.js +521 -0
- package/dist/eval/submission.js.map +1 -0
- package/dist/eval/suggestions-to-engine.d.ts +18 -0
- package/dist/eval/suggestions-to-engine.d.ts.map +1 -0
- package/dist/eval/suggestions-to-engine.js +40 -0
- package/dist/eval/suggestions-to-engine.js.map +1 -0
- package/dist/eval/suggestions.d.ts +17 -0
- package/dist/eval/suggestions.d.ts.map +1 -0
- package/dist/eval/suggestions.js +314 -0
- package/dist/eval/suggestions.js.map +1 -0
- package/dist/eval/undecided.d.ts +64 -0
- package/dist/eval/undecided.d.ts.map +1 -0
- package/dist/eval/undecided.js +101 -0
- package/dist/eval/undecided.js.map +1 -0
- package/dist/eval/verdict.d.ts +66 -0
- package/dist/eval/verdict.d.ts.map +1 -0
- package/dist/eval/verdict.js +106 -0
- package/dist/eval/verdict.js.map +1 -0
- package/dist/eval/verify-signature.d.ts +78 -0
- package/dist/eval/verify-signature.d.ts.map +1 -0
- package/dist/eval/verify-signature.js +185 -0
- package/dist/eval/verify-signature.js.map +1 -0
- package/dist/eval/version-dispatch.d.ts +38 -0
- package/dist/eval/version-dispatch.d.ts.map +1 -0
- package/dist/eval/version-dispatch.js +61 -0
- package/dist/eval/version-dispatch.js.map +1 -0
- package/dist/eval/visibility.d.ts +33 -0
- package/dist/eval/visibility.d.ts.map +1 -0
- package/dist/eval/visibility.js +83 -0
- package/dist/eval/visibility.js.map +1 -0
- package/dist/evaluate.d.ts +24 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +18 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/expr/builtin-docs.d.ts +51 -0
- package/dist/expr/builtin-docs.d.ts.map +1 -0
- package/dist/expr/builtin-docs.js +874 -0
- package/dist/expr/builtin-docs.js.map +1 -0
- package/dist/expr/builtins.d.ts +50 -0
- package/dist/expr/builtins.d.ts.map +1 -0
- package/dist/expr/builtins.js +966 -0
- package/dist/expr/builtins.js.map +1 -0
- package/dist/expr/decimal-precision.d.ts +39 -0
- package/dist/expr/decimal-precision.d.ts.map +1 -0
- package/dist/expr/decimal-precision.js +62 -0
- package/dist/expr/decimal-precision.js.map +1 -0
- package/dist/expr/decimal.d.ts +172 -0
- package/dist/expr/decimal.d.ts.map +1 -0
- package/dist/expr/decimal.js +782 -0
- package/dist/expr/decimal.js.map +1 -0
- package/dist/expr/deprecations.d.ts +34 -0
- package/dist/expr/deprecations.d.ts.map +1 -0
- package/dist/expr/deprecations.js +17 -0
- package/dist/expr/deprecations.js.map +1 -0
- package/dist/expr/diagnostics.d.ts +21 -0
- package/dist/expr/diagnostics.d.ts.map +1 -0
- package/dist/expr/diagnostics.js +231 -0
- package/dist/expr/diagnostics.js.map +1 -0
- package/dist/expr/direction.d.ts +30 -0
- package/dist/expr/direction.d.ts.map +1 -0
- package/dist/expr/direction.js +77 -0
- package/dist/expr/direction.js.map +1 -0
- package/dist/expr/example-expression.d.ts +62 -0
- package/dist/expr/example-expression.d.ts.map +1 -0
- package/dist/expr/example-expression.js +670 -0
- package/dist/expr/example-expression.js.map +1 -0
- package/dist/expr/instant.d.ts +49 -0
- package/dist/expr/instant.d.ts.map +1 -0
- package/dist/expr/instant.js +111 -0
- package/dist/expr/instant.js.map +1 -0
- package/dist/expr/logic.d.ts +17 -0
- package/dist/expr/logic.d.ts.map +1 -0
- package/dist/expr/logic.js +65 -0
- package/dist/expr/logic.js.map +1 -0
- package/dist/expr/messages.d.ts +45 -0
- package/dist/expr/messages.d.ts.map +1 -0
- package/dist/expr/messages.js +280 -0
- package/dist/expr/messages.js.map +1 -0
- package/dist/expr/money.d.ts +38 -0
- package/dist/expr/money.d.ts.map +1 -0
- package/dist/expr/money.js +127 -0
- package/dist/expr/money.js.map +1 -0
- package/dist/expr/ordering.d.ts +56 -0
- package/dist/expr/ordering.d.ts.map +1 -0
- package/dist/expr/ordering.js +167 -0
- package/dist/expr/ordering.js.map +1 -0
- package/dist/expr/pattern.d.ts +44 -0
- package/dist/expr/pattern.d.ts.map +1 -0
- package/dist/expr/pattern.js +458 -0
- package/dist/expr/pattern.js.map +1 -0
- package/dist/expr/plain-date.d.ts +90 -0
- package/dist/expr/plain-date.d.ts.map +1 -0
- package/dist/expr/plain-date.js +230 -0
- package/dist/expr/plain-date.js.map +1 -0
- package/dist/expr/plural-categories.d.ts +8 -0
- package/dist/expr/plural-categories.d.ts.map +1 -0
- package/dist/expr/plural-categories.js +15 -0
- package/dist/expr/plural-categories.js.map +1 -0
- package/dist/expr/plural-keys.d.ts +39 -0
- package/dist/expr/plural-keys.d.ts.map +1 -0
- package/dist/expr/plural-keys.js +46 -0
- package/dist/expr/plural-keys.js.map +1 -0
- package/dist/expr/plural.d.ts +33 -0
- package/dist/expr/plural.d.ts.map +1 -0
- package/dist/expr/plural.js +50 -0
- package/dist/expr/plural.js.map +1 -0
- package/dist/expr/quantity.d.ts +31 -0
- package/dist/expr/quantity.d.ts.map +1 -0
- package/dist/expr/quantity.js +83 -0
- package/dist/expr/quantity.js.map +1 -0
- package/dist/expr/reduce.d.ts +50 -0
- package/dist/expr/reduce.d.ts.map +1 -0
- package/dist/expr/reduce.js +236 -0
- package/dist/expr/reduce.js.map +1 -0
- package/dist/expr/regex.d.ts +108 -0
- package/dist/expr/regex.d.ts.map +1 -0
- package/dist/expr/regex.js +1207 -0
- package/dist/expr/regex.js.map +1 -0
- package/dist/expr/select-locale.d.ts +67 -0
- package/dist/expr/select-locale.d.ts.map +1 -0
- package/dist/expr/select-locale.js +219 -0
- package/dist/expr/select-locale.js.map +1 -0
- package/dist/expr/sequences.d.ts +123 -0
- package/dist/expr/sequences.d.ts.map +1 -0
- package/dist/expr/sequences.js +234 -0
- package/dist/expr/sequences.js.map +1 -0
- package/dist/expr/strings.d.ts +50 -0
- package/dist/expr/strings.d.ts.map +1 -0
- package/dist/expr/strings.js +184 -0
- package/dist/expr/strings.js.map +1 -0
- package/dist/expr/validation.d.ts +32 -0
- package/dist/expr/validation.d.ts.map +1 -0
- package/dist/expr/validation.js +182 -0
- package/dist/expr/validation.js.map +1 -0
- package/dist/graph/freeze.d.ts +4 -0
- package/dist/graph/freeze.d.ts.map +1 -0
- package/dist/graph/freeze.js +52 -0
- package/dist/graph/freeze.js.map +1 -0
- package/dist/graph/index.d.ts +15 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +13 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/inspect.d.ts +76 -0
- package/dist/graph/inspect.d.ts.map +1 -0
- package/dist/graph/inspect.js +263 -0
- package/dist/graph/inspect.js.map +1 -0
- package/dist/graph/read-walk.d.ts +101 -0
- package/dist/graph/read-walk.d.ts.map +1 -0
- package/dist/graph/read-walk.js +358 -0
- package/dist/graph/read-walk.js.map +1 -0
- package/dist/graph/record-index.d.ts +24 -0
- package/dist/graph/record-index.d.ts.map +1 -0
- package/dist/graph/record-index.js +35 -0
- package/dist/graph/record-index.js.map +1 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +139 -0
- package/dist/index.js.map +1 -0
- package/dist/lookup/digest.d.ts +51 -0
- package/dist/lookup/digest.d.ts.map +1 -0
- package/dist/lookup/digest.js +46 -0
- package/dist/lookup/digest.js.map +1 -0
- package/dist/lookup/index.d.ts +28 -0
- package/dist/lookup/index.d.ts.map +1 -0
- package/dist/lookup/index.js +27 -0
- package/dist/lookup/index.js.map +1 -0
- package/dist/lookup/install.d.ts +48 -0
- package/dist/lookup/install.d.ts.map +1 -0
- package/dist/lookup/install.js +315 -0
- package/dist/lookup/install.js.map +1 -0
- package/dist/lookup/pass.d.ts +55 -0
- package/dist/lookup/pass.d.ts.map +1 -0
- package/dist/lookup/pass.js +212 -0
- package/dist/lookup/pass.js.map +1 -0
- package/dist/lookup/pins.d.ts +34 -0
- package/dist/lookup/pins.d.ts.map +1 -0
- package/dist/lookup/pins.js +39 -0
- package/dist/lookup/pins.js.map +1 -0
- package/dist/lookup/provenance.d.ts +23 -0
- package/dist/lookup/provenance.d.ts.map +1 -0
- package/dist/lookup/provenance.js +78 -0
- package/dist/lookup/provenance.js.map +1 -0
- package/dist/lookup/readiness.d.ts +13 -0
- package/dist/lookup/readiness.d.ts.map +1 -0
- package/dist/lookup/readiness.js +57 -0
- package/dist/lookup/readiness.js.map +1 -0
- package/dist/lookup/resolve.d.ts +24 -0
- package/dist/lookup/resolve.d.ts.map +1 -0
- package/dist/lookup/resolve.js +201 -0
- package/dist/lookup/resolve.js.map +1 -0
- package/dist/lookup/store.d.ts +41 -0
- package/dist/lookup/store.d.ts.map +1 -0
- package/dist/lookup/store.js +74 -0
- package/dist/lookup/store.js.map +1 -0
- package/dist/model/access.d.ts +200 -0
- package/dist/model/access.d.ts.map +1 -0
- package/dist/model/access.js +125 -0
- package/dist/model/access.js.map +1 -0
- package/dist/model/artifact-members.d.ts +3 -0
- package/dist/model/artifact-members.d.ts.map +1 -0
- package/dist/model/artifact-members.js +38 -0
- package/dist/model/artifact-members.js.map +1 -0
- package/dist/model/composition.d.ts +47 -0
- package/dist/model/composition.d.ts.map +1 -0
- package/dist/model/composition.js +66 -0
- package/dist/model/composition.js.map +1 -0
- package/dist/model/domain.d.ts +51 -0
- package/dist/model/domain.d.ts.map +1 -0
- package/dist/model/domain.js +75 -0
- package/dist/model/domain.js.map +1 -0
- package/dist/model/duration.d.ts +31 -0
- package/dist/model/duration.d.ts.map +1 -0
- package/dist/model/duration.js +136 -0
- package/dist/model/duration.js.map +1 -0
- package/dist/model/errors.d.ts +58 -0
- package/dist/model/errors.d.ts.map +1 -0
- package/dist/model/errors.js +81 -0
- package/dist/model/errors.js.map +1 -0
- package/dist/model/evolution.d.ts +177 -0
- package/dist/model/evolution.d.ts.map +1 -0
- package/dist/model/evolution.js +5 -0
- package/dist/model/evolution.js.map +1 -0
- package/dist/model/expr-children.d.ts +15 -0
- package/dist/model/expr-children.d.ts.map +1 -0
- package/dist/model/expr-children.js +45 -0
- package/dist/model/expr-children.js.map +1 -0
- package/dist/model/guards.d.ts +9 -0
- package/dist/model/guards.d.ts.map +1 -0
- package/dist/model/guards.js +11 -0
- package/dist/model/guards.js.map +1 -0
- package/dist/model/input.d.ts +42 -0
- package/dist/model/input.d.ts.map +1 -0
- package/dist/model/input.js +26 -0
- package/dist/model/input.js.map +1 -0
- package/dist/model/integer.d.ts +14 -0
- package/dist/model/integer.d.ts.map +1 -0
- package/dist/model/integer.js +16 -0
- package/dist/model/integer.js.map +1 -0
- package/dist/model/intrinsic.d.ts +18 -0
- package/dist/model/intrinsic.d.ts.map +1 -0
- package/dist/model/intrinsic.js +21 -0
- package/dist/model/intrinsic.js.map +1 -0
- package/dist/model/layout.d.ts +129 -0
- package/dist/model/layout.d.ts.map +1 -0
- package/dist/model/layout.js +2 -0
- package/dist/model/layout.js.map +1 -0
- package/dist/model/media.d.ts +33 -0
- package/dist/model/media.d.ts.map +1 -0
- package/dist/model/media.js +86 -0
- package/dist/model/media.js.map +1 -0
- package/dist/model/members.generated.d.ts +11 -0
- package/dist/model/members.generated.d.ts.map +1 -0
- package/dist/model/members.generated.js +71 -0
- package/dist/model/members.generated.js.map +1 -0
- package/dist/model/row-address.d.ts +27 -0
- package/dist/model/row-address.d.ts.map +1 -0
- package/dist/model/row-address.js +146 -0
- package/dist/model/row-address.js.map +1 -0
- package/dist/model/schema.d.ts +108 -0
- package/dist/model/schema.d.ts.map +1 -0
- package/dist/model/schema.js +2 -0
- package/dist/model/schema.js.map +1 -0
- package/dist/model/shape.d.ts +193 -0
- package/dist/model/shape.d.ts.map +1 -0
- package/dist/model/shape.js +2 -0
- package/dist/model/shape.js.map +1 -0
- package/dist/model/time.d.ts +61 -0
- package/dist/model/time.d.ts.map +1 -0
- package/dist/model/time.js +110 -0
- package/dist/model/time.js.map +1 -0
- package/dist/model/types.d.ts +1329 -0
- package/dist/model/types.d.ts.map +1 -0
- package/dist/model/types.js +424 -0
- package/dist/model/types.js.map +1 -0
- package/dist/model/values.d.ts +91 -0
- package/dist/model/values.d.ts.map +1 -0
- package/dist/model/values.js +195 -0
- package/dist/model/values.js.map +1 -0
- package/dist/model/wire.d.ts +356 -0
- package/dist/model/wire.d.ts.map +1 -0
- package/dist/model/wire.js +1504 -0
- package/dist/model/wire.js.map +1 -0
- package/dist/offline/index.d.ts +374 -0
- package/dist/offline/index.d.ts.map +1 -0
- package/dist/offline/index.js +422 -0
- package/dist/offline/index.js.map +1 -0
- package/dist/testing.d.ts +30 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +42 -0
- package/dist/testing.js.map +1 -0
- package/dist/version.d.ts +30 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +116 -0
- package/dist/version.js.map +1 -0
- package/package.json +98 -3
|
@@ -0,0 +1,782 @@
|
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
import { AxiomError } from '../model/errors.js';
|
|
3
|
+
import { isSafeInteger } from '../model/integer.js';
|
|
4
|
+
import { DECIMAL_TEXT_PATTERN, INTEGER_TEXT_PATTERN } from '../model/types.js';
|
|
5
|
+
import { workingDecimal } from './decimal-precision.js';
|
|
6
|
+
/** Significant digits an exact decimal carries. */
|
|
7
|
+
export const DECIMAL_PRECISION = 34;
|
|
8
|
+
/**
|
|
9
|
+
* The fractional digits a canonical decimal value carries, `MODEL-2.1.27`.
|
|
10
|
+
*
|
|
11
|
+
* Canonical text admits no trailing fractional zero (`1.50` is refused as a non-canonical
|
|
12
|
+
* spelling of `1.5`), so this is the scale the value states: `1.25` is two and `1.5` is one.
|
|
13
|
+
* The two equal numbers that differ here are `1.5` and `1.50` as *authored text*, and only the
|
|
14
|
+
* canonical one is a value; the count is still what a `maxScale` bound judges.
|
|
15
|
+
*/
|
|
16
|
+
export function fractionalDigitCount(text) {
|
|
17
|
+
const point = text.indexOf('.');
|
|
18
|
+
return point === -1 ? 0 : text.length - point - 1;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The decimal exponent range the runtime will render. Canonical text has
|
|
22
|
+
* no exponent form, so a magnitude beyond this needs more integer (or leading fractional)
|
|
23
|
+
* digits than the language's other text caps, and is refused rather than materialised. A
|
|
24
|
+
* small authored expression can otherwise ask `pow` for a value whose text is petabytes
|
|
25
|
+
* long: `2` raised to the largest canonical integer exponent is finite in decimal.js.
|
|
26
|
+
*
|
|
27
|
+
* Exported because a message count is admitted to the same budget before plural selection:
|
|
28
|
+
* arithmetic and message rendering must not disagree about how wide a value the engine carries.
|
|
29
|
+
*/
|
|
30
|
+
export const MAX_DECIMAL_EXPONENT = 4096;
|
|
31
|
+
/**
|
|
32
|
+
* The runtime's own decimal constructor. Cloning keeps Axiom's precision and output
|
|
33
|
+
* format out of the global `Decimal` configuration a host may already have changed,
|
|
34
|
+
* and disabling exponent output keeps text canonical without a second formatting pass.
|
|
35
|
+
*/
|
|
36
|
+
export const AxiomDecimal = Decimal.clone({
|
|
37
|
+
precision: DECIMAL_PRECISION,
|
|
38
|
+
toExpNeg: -9e15,
|
|
39
|
+
toExpPos: 9e15,
|
|
40
|
+
});
|
|
41
|
+
const ROUNDING_MODES = {
|
|
42
|
+
up: Decimal.ROUND_UP,
|
|
43
|
+
down: Decimal.ROUND_DOWN,
|
|
44
|
+
ceiling: Decimal.ROUND_CEIL,
|
|
45
|
+
floor: Decimal.ROUND_FLOOR,
|
|
46
|
+
half_up: Decimal.ROUND_HALF_UP,
|
|
47
|
+
half_even: Decimal.ROUND_HALF_EVEN,
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Significant digits: the digits that carry the value, so the trailing
|
|
51
|
+
* zeros of `10^34` and the fractional zeros of a padded amount are not counted. Canonical
|
|
52
|
+
* text never carries trailing *fractional* zeros, but an integer such as
|
|
53
|
+
* `10000000000000000000000000000000000` carries 34 of them and is one digit wide.
|
|
54
|
+
*
|
|
55
|
+
* A single scan: the digits that carry the value sit between the first and last non-zero
|
|
56
|
+
* digit, so only their positions matter. Successive `replace` passes allocated four
|
|
57
|
+
* intermediate strings for every comparison in the evaluator.
|
|
58
|
+
*/
|
|
59
|
+
function significantDigits(text) {
|
|
60
|
+
let first = -1;
|
|
61
|
+
let last = -1;
|
|
62
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
63
|
+
const code = text.charCodeAt(index);
|
|
64
|
+
if (code < 49 || code > 57)
|
|
65
|
+
continue; // skip the sign, the point and zeros
|
|
66
|
+
if (first === -1)
|
|
67
|
+
first = index;
|
|
68
|
+
last = index;
|
|
69
|
+
}
|
|
70
|
+
if (first === -1)
|
|
71
|
+
return 1;
|
|
72
|
+
let digits = 0;
|
|
73
|
+
for (let index = first; index <= last; index += 1) {
|
|
74
|
+
const code = text.charCodeAt(index);
|
|
75
|
+
if (code >= 48 && code <= 57)
|
|
76
|
+
digits += 1;
|
|
77
|
+
}
|
|
78
|
+
return digits;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Whether `text` is canonical decimal text: the shape pattern, less the one spelling (`-0`) the
|
|
82
|
+
* pattern admits and the language refuses. Every entry below asks this function, so the brand has
|
|
83
|
+
* one accept rule rather than a copy of it in each door.
|
|
84
|
+
*
|
|
85
|
+
* The `typeof` guard is what makes the predicate total. A JavaScript caller can hand a number
|
|
86
|
+
* where the brand is expected, and `RegExp#test` would coerce `3` to `"3"` and return the
|
|
87
|
+
* *number* carrying the brand: a value that is not text, which every later `startsWith` or
|
|
88
|
+
* `charCodeAt` would read as one. A `DecimalString` is text or it is not one.
|
|
89
|
+
*/
|
|
90
|
+
function isCanonicalDecimalText(text) {
|
|
91
|
+
return typeof text === 'string' && text !== '-0' && DECIMAL_TEXT_PATTERN.test(text);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The authoring constructor of the `DecimalString` brand. Text that is not already canonical
|
|
95
|
+
* decimal text is refused rather than normalised, because two spellings of one amount must not
|
|
96
|
+
* be two values.
|
|
97
|
+
*
|
|
98
|
+
* The refusal repeats the text because its caller is an author reading a diagnostic about a
|
|
99
|
+
* literal they just wrote, and seeing the spelling is what makes the fix obvious. A value a
|
|
100
|
+
* person *submitted* is a different caller: `asWireDecimalString` is that door.
|
|
101
|
+
*/
|
|
102
|
+
export function asDecimalString(text, path = '') {
|
|
103
|
+
if (!isCanonicalDecimalText(text)) {
|
|
104
|
+
throw new AxiomError('ENGINE_ERROR', `not canonical decimal text: ${String(text)}`, path, 'not canonical decimal text');
|
|
105
|
+
}
|
|
106
|
+
return text;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The wire constructor of the `DecimalString` brand: canonical decimal text as a submission
|
|
110
|
+
* states it, refused with the path and the cause but never with the text.
|
|
111
|
+
*
|
|
112
|
+
* Both constructors accept exactly the same text; only the refusal differs. `asDecimalString`
|
|
113
|
+
* echoes the value to the author who typed it, while this entry's caller is the wire reader
|
|
114
|
+
* holding a value someone submitted — possibly for a field the artifact hides — and its
|
|
115
|
+
* refusal is data: `evaluateSubmission` returns it as `detail`, which a backend may relay. The
|
|
116
|
+
* path already names the seat the value was read from; repeating the text would add nothing an
|
|
117
|
+
* operator can act on and everything a hidden field must not disclose.
|
|
118
|
+
*
|
|
119
|
+
* The path is required. A refusal about an untrusted value at no stated place is a refusal an
|
|
120
|
+
* operator cannot trace, and the wire reader always knows the path it read.
|
|
121
|
+
*/
|
|
122
|
+
export function asWireDecimalString(text, path) {
|
|
123
|
+
if (!isCanonicalDecimalText(text)) {
|
|
124
|
+
throw new AxiomError('ENGINE_ERROR', 'not canonical decimal text', path);
|
|
125
|
+
}
|
|
126
|
+
return text;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Whether text's integer and fractional runs are both inside the exponent budget.
|
|
130
|
+
*
|
|
131
|
+
* The budget is a count of digits in the rendered text: at most `MAX_DECIMAL_EXPONENT` integer
|
|
132
|
+
* digits and at most `MAX_DECIMAL_EXPONENT` fraction digits. In terms of the leading digit's
|
|
133
|
+
* exponent that is `-MAX_DECIMAL_EXPONENT <= e <= MAX_DECIMAL_EXPONENT - 1`, which is the same
|
|
134
|
+
* bound `exponentFitsRenderedText` applies to a decimal.js value. The same predicate decides
|
|
135
|
+
* the refusal and the miss, so `parse_decimal` cannot answer a value the arithmetic cannot
|
|
136
|
+
* carry: a value the renderers admit is a value every operand reader admits.
|
|
137
|
+
*/
|
|
138
|
+
function exponentWithinBudget(text) {
|
|
139
|
+
const unsigned = text.startsWith('-') ? text.slice(1) : text;
|
|
140
|
+
const point = unsigned.indexOf('.');
|
|
141
|
+
const whole = point === -1 ? unsigned.length : point;
|
|
142
|
+
const fraction = point === -1 ? 0 : unsigned.length - point - 1;
|
|
143
|
+
return whole <= MAX_DECIMAL_EXPONENT && fraction <= MAX_DECIMAL_EXPONENT;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Whether a leading-digit exponent renders inside the budget.
|
|
147
|
+
*
|
|
148
|
+
* A decimal with exponent `e` has `e + 1` integer digits when `e >= 0`, and `-e` fraction digits
|
|
149
|
+
* when `e < 0` (there is a single `0` before the point). So the text bound above is exactly
|
|
150
|
+
* `e <= MAX_DECIMAL_EXPONENT - 1` and `e >= -MAX_DECIMAL_EXPONENT`. Checking this before
|
|
151
|
+
* rendering is what keeps `pow(10, 4096)` from producing the 4,097-digit text `+`, `round` and
|
|
152
|
+
* `parse_decimal` all refuse (`EXPR-11.1.2`).
|
|
153
|
+
*/
|
|
154
|
+
function exponentFitsRenderedText(exponent) {
|
|
155
|
+
return exponent <= MAX_DECIMAL_EXPONENT - 1 && exponent >= -MAX_DECIMAL_EXPONENT;
|
|
156
|
+
}
|
|
157
|
+
/** The one refusal for a value whose rendered text exceeds the exponent budget. */
|
|
158
|
+
function magnitudeExceeded(path) {
|
|
159
|
+
return new AxiomError('ENGINE_ERROR', `decimal magnitude exceeds ${String(MAX_DECIMAL_EXPONENT)} digits before or after the point`, path);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Refuses text whose integer or fractional run is longer than the exponent budget, so a scale
|
|
163
|
+
* that would make the scaling multiply enormous is refused before the arithmetic starts.
|
|
164
|
+
*/
|
|
165
|
+
function assertExponentWithinBudget(text, path) {
|
|
166
|
+
if (exponentWithinBudget(text))
|
|
167
|
+
return;
|
|
168
|
+
throw magnitudeExceeded(path);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Canonical decimal text the numeric budget can carry, or `undefined` when the text is
|
|
172
|
+
* not one. `parse_decimal` answers from this rather than from a thrown refusal, so text a
|
|
173
|
+
* caller typed is an ordinary `null` result and never an engine error
|
|
174
|
+
*
|
|
175
|
+
*/
|
|
176
|
+
export function tryDecimalString(text) {
|
|
177
|
+
if (!isCanonicalDecimalText(text))
|
|
178
|
+
return undefined;
|
|
179
|
+
if (!exponentWithinBudget(text))
|
|
180
|
+
return undefined;
|
|
181
|
+
if (significantDigits(text) > DECIMAL_PRECISION)
|
|
182
|
+
return undefined;
|
|
183
|
+
return text;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Parses text the brand already proved canonical, holding it to the literal budget.
|
|
187
|
+
*
|
|
188
|
+
* `parseDecimal` is the literal reader: the compiler uses it to refuse a literal the language
|
|
189
|
+
* cannot carry. Arithmetic operands are different: a stored value the wire accepted must be
|
|
190
|
+
* rounded or divided as the value it is, so those paths parse at a working precision derived
|
|
191
|
+
* from the operand and apply the budget to the result instead.
|
|
192
|
+
*/
|
|
193
|
+
function parseCanonicalDecimal(text, path) {
|
|
194
|
+
if (significantDigits(text) > DECIMAL_PRECISION) {
|
|
195
|
+
throw new AxiomError('ENGINE_ERROR', `decimal carries more than ${DECIMAL_PRECISION} significant digits: ${text}`, path, `decimal carries more than ${String(DECIMAL_PRECISION)} significant digits`);
|
|
196
|
+
}
|
|
197
|
+
// A literal is read by the same budget every operand reader applies, so the compiler cannot
|
|
198
|
+
// admit a spelling arithmetic would later refuse (`tryDecimalString` and `toScaledInteger`).
|
|
199
|
+
assertExponentWithinBudget(text, path);
|
|
200
|
+
return new AxiomDecimal(text);
|
|
201
|
+
}
|
|
202
|
+
/** Parses canonical decimal text as a literal, refusing anything the literal budget cannot carry. */
|
|
203
|
+
export function parseDecimal(text, path = '') {
|
|
204
|
+
return parseCanonicalDecimal(asDecimalString(text, path), path);
|
|
205
|
+
}
|
|
206
|
+
/** Renders a finite decimal as canonical text, normalising `-0` to `0`. */
|
|
207
|
+
export function canonicalDecimal(value, path = '') {
|
|
208
|
+
if (!value.isFinite()) {
|
|
209
|
+
throw new AxiomError('ENGINE_ERROR', 'decimal is not finite', path);
|
|
210
|
+
}
|
|
211
|
+
// The exponent is checked before rendering: `toFixed` on an out-of-range magnitude
|
|
212
|
+
// would build the text this bound exists to refuse. The bound is the same one
|
|
213
|
+
// `exponentWithinBudget` applies to canonical text, so this value is a valid operand.
|
|
214
|
+
if (!exponentFitsRenderedText(value.e)) {
|
|
215
|
+
throw magnitudeExceeded(path);
|
|
216
|
+
}
|
|
217
|
+
// Decimal#toFixed never uses exponential notation and drops trailing zeros.
|
|
218
|
+
const text = value.isZero() ? '0' : value.toFixed();
|
|
219
|
+
// The leading digit's exponent does not bound the fraction run: significant digits far from
|
|
220
|
+
// the point render a run longer than the budget (a product of two wide operands is the case
|
|
221
|
+
// that found this). The operand reader would refuse that text, so the renderer must too.
|
|
222
|
+
if (!exponentWithinBudget(text)) {
|
|
223
|
+
throw magnitudeExceeded(path);
|
|
224
|
+
}
|
|
225
|
+
// A result that needs more than 34 significant digits has no exact spelling in this
|
|
226
|
+
// language, so it fails rather than being silently rounded to the working precision.
|
|
227
|
+
// `round` and the explicit division path apply the same budget through `fromScaledInteger`; `pow` renders
|
|
228
|
+
// through here.
|
|
229
|
+
if (significantDigits(text) > DECIMAL_PRECISION) {
|
|
230
|
+
throw new AxiomError('ENGINE_ERROR', `decimal result carries more than ${String(DECIMAL_PRECISION)} significant digits`, path);
|
|
231
|
+
}
|
|
232
|
+
return asDecimalString(text, path);
|
|
233
|
+
}
|
|
234
|
+
const ROUNDING_MODE_NAMES = [
|
|
235
|
+
'up',
|
|
236
|
+
'down',
|
|
237
|
+
'ceiling',
|
|
238
|
+
'floor',
|
|
239
|
+
'half_up',
|
|
240
|
+
'half_even',
|
|
241
|
+
];
|
|
242
|
+
/**
|
|
243
|
+
* Rounds a positive magnitude held as `quotient + remainder/divisor` to an integer under
|
|
244
|
+
* `mode`. `negative` is the sign of the exact value; the caller has already shown the
|
|
245
|
+
* remainder is below one unit and is non-zero.
|
|
246
|
+
*
|
|
247
|
+
* The six modes are decided over integers, so a result exactly at a tie is known rather than
|
|
248
|
+
* inferred from a truncated decimal expansion.
|
|
249
|
+
*/
|
|
250
|
+
function roundMagnitude(quotient, remainder, divisor, mode, negative) {
|
|
251
|
+
if (remainder === 0n)
|
|
252
|
+
return quotient;
|
|
253
|
+
const twice = remainder * 2n;
|
|
254
|
+
switch (mode) {
|
|
255
|
+
// Away from zero: the magnitude grows whatever the sign.
|
|
256
|
+
case 'up':
|
|
257
|
+
return quotient + 1n;
|
|
258
|
+
// Toward zero: the truncated magnitude stands.
|
|
259
|
+
case 'down':
|
|
260
|
+
return quotient;
|
|
261
|
+
case 'ceiling':
|
|
262
|
+
return negative ? quotient : quotient + 1n;
|
|
263
|
+
case 'floor':
|
|
264
|
+
return negative ? quotient + 1n : quotient;
|
|
265
|
+
case 'half_up':
|
|
266
|
+
return twice >= divisor ? quotient + 1n : quotient;
|
|
267
|
+
case 'half_even':
|
|
268
|
+
if (twice > divisor)
|
|
269
|
+
return quotient + 1n;
|
|
270
|
+
if (twice < divisor)
|
|
271
|
+
return quotient;
|
|
272
|
+
return quotient % 2n === 0n ? quotient : quotient + 1n;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Rounds a decimal to `scale` fraction digits and renders the canonical result. An
|
|
277
|
+
* unknown mode is refused rather than defaulted: a silent `half_up` would be a rounding
|
|
278
|
+
* policy the artifact never declared.
|
|
279
|
+
*
|
|
280
|
+
* The operand is rounded as the exact integer it is, so a stored value above the result
|
|
281
|
+
* budget is accepted and only the rendered result is held to 34 significant digits.
|
|
282
|
+
*/
|
|
283
|
+
export function roundDecimal(value, scale, mode, path = '') {
|
|
284
|
+
if (!Number.isInteger(scale) || scale < 0 || scale > DECIMAL_PRECISION) {
|
|
285
|
+
throw new AxiomError('ENGINE_ERROR', `scale out of range: ${String(scale)}`, path);
|
|
286
|
+
}
|
|
287
|
+
if (!ROUNDING_MODE_NAMES.includes(mode)) {
|
|
288
|
+
throw new AxiomError('ENGINE_ERROR', `unknown rounding mode: ${String(mode)}`, path);
|
|
289
|
+
}
|
|
290
|
+
const { units, scale: current } = toScaledInteger(value, path);
|
|
291
|
+
if (current <= scale) {
|
|
292
|
+
// Fewer fraction digits than the target scale: the value is already that exact, and the
|
|
293
|
+
// canonical render drops the padding.
|
|
294
|
+
return fromScaledInteger({ units: units * 10n ** BigInt(scale - current), scale }, path);
|
|
295
|
+
}
|
|
296
|
+
const divisor = 10n ** BigInt(current - scale);
|
|
297
|
+
const magnitude = units < 0n ? -units : units;
|
|
298
|
+
const rounded = roundMagnitude(magnitude / divisor, magnitude % divisor, divisor, mode, units < 0n);
|
|
299
|
+
return fromScaledInteger({ units: units < 0n ? -rounded : rounded, scale }, path);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* The order of two digits strings of the same length: code-unit order is digit order.
|
|
303
|
+
*/
|
|
304
|
+
function compareDigitRuns(left, right) {
|
|
305
|
+
for (let index = 0; index < left.length; index += 1) {
|
|
306
|
+
const a = left.charCodeAt(index);
|
|
307
|
+
const b = right.charCodeAt(index);
|
|
308
|
+
if (a !== b)
|
|
309
|
+
return a < b ? -1 : 1;
|
|
310
|
+
}
|
|
311
|
+
return 0;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Compares two unsigned canonical decimals by their digits. The integer run decides first
|
|
315
|
+
* because canonical text has no leading zeros beyond `0` itself, so the longer run is the
|
|
316
|
+
* larger magnitude; equal runs then compare digit by digit, and the fraction is compared as
|
|
317
|
+
* a zero-padded run because a missing digit is a zero.
|
|
318
|
+
*/
|
|
319
|
+
function compareMagnitudes(left, right) {
|
|
320
|
+
const leftPoint = left.indexOf('.');
|
|
321
|
+
const rightPoint = right.indexOf('.');
|
|
322
|
+
const leftWhole = leftPoint === -1 ? left : left.slice(0, leftPoint);
|
|
323
|
+
const rightWhole = rightPoint === -1 ? right : right.slice(0, rightPoint);
|
|
324
|
+
if (leftWhole.length !== rightWhole.length) {
|
|
325
|
+
return leftWhole.length < rightWhole.length ? -1 : 1;
|
|
326
|
+
}
|
|
327
|
+
const wholeOrder = compareDigitRuns(leftWhole, rightWhole);
|
|
328
|
+
if (wholeOrder !== 0)
|
|
329
|
+
return wholeOrder;
|
|
330
|
+
const leftFraction = leftPoint === -1 ? '' : left.slice(leftPoint + 1);
|
|
331
|
+
const rightFraction = rightPoint === -1 ? '' : right.slice(rightPoint + 1);
|
|
332
|
+
const width = Math.max(leftFraction.length, rightFraction.length);
|
|
333
|
+
for (let index = 0; index < width; index += 1) {
|
|
334
|
+
const a = index < leftFraction.length ? leftFraction.charCodeAt(index) : 48;
|
|
335
|
+
const b = index < rightFraction.length ? rightFraction.charCodeAt(index) : 48;
|
|
336
|
+
if (a !== b)
|
|
337
|
+
return a < b ? -1 : 1;
|
|
338
|
+
}
|
|
339
|
+
return 0;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Exact comparison of two canonical decimals: negative when `a` sorts first, zero when they
|
|
343
|
+
* are the same value, positive otherwise.
|
|
344
|
+
*
|
|
345
|
+
* Comparison is not arithmetic, so it applies no significant-digit budget: a canonical value
|
|
346
|
+
* the wire accepted is compared as the digits it carries, and `x == x` holds for a value longer
|
|
347
|
+
* than the 34-digit arithmetic result budget. The text is still validated, so a spelling the
|
|
348
|
+
* brand never produced cannot be read as a value.
|
|
349
|
+
*/
|
|
350
|
+
export function compareDecimalTexts(a, b, path = '') {
|
|
351
|
+
const left = asDecimalString(a, path);
|
|
352
|
+
const right = asDecimalString(b, path);
|
|
353
|
+
if (left === right)
|
|
354
|
+
return 0;
|
|
355
|
+
const leftNegative = left.startsWith('-');
|
|
356
|
+
const rightNegative = right.startsWith('-');
|
|
357
|
+
if (leftNegative !== rightNegative)
|
|
358
|
+
return leftNegative ? -1 : 1;
|
|
359
|
+
const order = compareMagnitudes(leftNegative ? left.slice(1) : left, rightNegative ? right.slice(1) : right);
|
|
360
|
+
return leftNegative ? -order : order;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Splits canonical decimal text into an exact integer and its decimal scale. The text is
|
|
364
|
+
* checked first: `BigInt('01')` would read as `1`, silently normalising a value whose
|
|
365
|
+
* spelling is not canonical.
|
|
366
|
+
*/
|
|
367
|
+
function toScaledInteger(text, path) {
|
|
368
|
+
asDecimalString(text, path);
|
|
369
|
+
// The bound is applied here, before any bigint exists: a value with 200 000 fraction digits
|
|
370
|
+
// carries one significant digit, so the precision check admits it, and summing it against an
|
|
371
|
+
// ordinary amount would then compute `10n ** 200000` per element.
|
|
372
|
+
assertExponentWithinBudget(text, path);
|
|
373
|
+
const negative = text.startsWith('-');
|
|
374
|
+
const unsigned = negative ? text.slice(1) : text;
|
|
375
|
+
const point = unsigned.indexOf('.');
|
|
376
|
+
const whole = point === -1 ? unsigned : unsigned.slice(0, point);
|
|
377
|
+
const fraction = point === -1 ? '' : unsigned.slice(point + 1);
|
|
378
|
+
const units = BigInt(`${whole}${fraction}`);
|
|
379
|
+
return { units: negative ? -units : units, scale: fraction.length };
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Renders a scaled integer as canonical decimal text inside the exponent budget, or `undefined`
|
|
383
|
+
* when the text would exceed it.
|
|
384
|
+
*
|
|
385
|
+
* The magnitude bound is a bound on the spelling rather than on the arithmetic, so the miss is
|
|
386
|
+
* distinct from the 34-significant-digit result budget: an operation that answers `UNKNOWN` for
|
|
387
|
+
* an over-budget result (`avg`, `median`) can ask whether the spelling fits instead of turning
|
|
388
|
+
* that answer into an engine error.
|
|
389
|
+
*/
|
|
390
|
+
function renderScaledIntegerWithinBudget({ units, scale }, path = '') {
|
|
391
|
+
if (units === 0n)
|
|
392
|
+
return asDecimalString('0', path);
|
|
393
|
+
const negative = units < 0n;
|
|
394
|
+
const magnitude = (negative ? -units : units).toString();
|
|
395
|
+
const exponent = magnitude.length - scale - 1;
|
|
396
|
+
if (!exponentFitsRenderedText(exponent))
|
|
397
|
+
return undefined;
|
|
398
|
+
const digits = magnitude.padStart(scale + 1, '0');
|
|
399
|
+
const whole = digits.slice(0, digits.length - scale);
|
|
400
|
+
const fraction = digits.slice(digits.length - scale).replace(/0+$/, '');
|
|
401
|
+
const text = fraction === '' ? whole : `${whole}.${fraction}`;
|
|
402
|
+
const rendered = negative ? `-${text}` : text;
|
|
403
|
+
// The pre-render guard checks the leading digit, which does not bound a fraction run whose
|
|
404
|
+
// last significant digit sits far from the point. `+`, `*` and `-` render through here, so
|
|
405
|
+
// without this a result could be text no operand reader accepts.
|
|
406
|
+
if (!exponentWithinBudget(rendered))
|
|
407
|
+
return undefined;
|
|
408
|
+
return asDecimalString(rendered, path);
|
|
409
|
+
}
|
|
410
|
+
/** Renders a scaled integer, refusing text that exceeds the exponent budget. */
|
|
411
|
+
function renderScaledInteger(scaled, path = '') {
|
|
412
|
+
const text = renderScaledIntegerWithinBudget(scaled, path);
|
|
413
|
+
if (text === undefined)
|
|
414
|
+
throw magnitudeExceeded(path);
|
|
415
|
+
return text;
|
|
416
|
+
}
|
|
417
|
+
function fromScaledInteger(scaled, path = '') {
|
|
418
|
+
const text = renderScaledInteger(scaled, path);
|
|
419
|
+
if (significantDigits(text) > DECIMAL_PRECISION) {
|
|
420
|
+
throw new AxiomError('ENGINE_ERROR', `exact result carries more than ${DECIMAL_PRECISION} significant digits`, path);
|
|
421
|
+
}
|
|
422
|
+
return text;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Sums canonical decimals exactly, as an unreduced scaled integer.
|
|
426
|
+
*
|
|
427
|
+
* This is the *arithmetic*: no significant-digit budget is applied, because the budget belongs
|
|
428
|
+
* to a result rather than to a total an operation later divides. `avg` over two 34-digit
|
|
429
|
+
* decimals has a 35-digit total whose exact mean fits 34 digits; rendering the total here
|
|
430
|
+
* would refuse a legal answer. The exponent bound still applies per operand.
|
|
431
|
+
*/
|
|
432
|
+
function sumScaledIntegers(values, path) {
|
|
433
|
+
let scale = 0;
|
|
434
|
+
const scaled = values.map((value) => {
|
|
435
|
+
const item = toScaledInteger(value, path);
|
|
436
|
+
scale = Math.max(scale, item.scale);
|
|
437
|
+
return item;
|
|
438
|
+
});
|
|
439
|
+
let total = 0n;
|
|
440
|
+
for (const item of scaled) {
|
|
441
|
+
total += item.units * 10n ** BigInt(scale - item.scale);
|
|
442
|
+
}
|
|
443
|
+
return { units: total, scale };
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Sums canonical decimals exactly. Accumulation is integer arithmetic over a common
|
|
447
|
+
* scale rather than `Decimal#plus`, because the 34-digit constructor rounds mid-sum
|
|
448
|
+
* and requires a budget overflow to fail instead of rounding.
|
|
449
|
+
*/
|
|
450
|
+
export function sumDecimalTexts(values, path = '') {
|
|
451
|
+
return fromScaledInteger(sumScaledIntegers(values, path), path);
|
|
452
|
+
}
|
|
453
|
+
/** `-value` in canonical text, with negative zero normalised to `0`. */
|
|
454
|
+
export function negateDecimalText(value, path = '') {
|
|
455
|
+
if (value === '0')
|
|
456
|
+
return value;
|
|
457
|
+
return asDecimalString(value.startsWith('-') ? value.slice(1) : `-${value}`, path);
|
|
458
|
+
}
|
|
459
|
+
/** `a - b` in canonical text: exact, so a 34-digit overflow fails rather than rounds. */
|
|
460
|
+
export function subtractDecimalTexts(minuend, subtrahend, path = '') {
|
|
461
|
+
return sumDecimalTexts([minuend, negateDecimalText(subtrahend, path)], path);
|
|
462
|
+
}
|
|
463
|
+
/** `a * b` in canonical text, exactly, through the same scaled-integer path as `+`/`-`. */
|
|
464
|
+
export function multiplyDecimalTexts(left, right, path = '') {
|
|
465
|
+
const a = toScaledInteger(left, path);
|
|
466
|
+
const b = toScaledInteger(right, path);
|
|
467
|
+
return fromScaledInteger({ units: a.units * b.units, scale: a.scale + b.scale }, path);
|
|
468
|
+
}
|
|
469
|
+
/** The decimal digit count of a positive bigint, one for zero. */
|
|
470
|
+
function digitCount(value) {
|
|
471
|
+
return value === 0n ? 1 : value.toString().length;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* `a / b` at the language's 34 significant digits, rounded once with `half_even`.
|
|
475
|
+
*
|
|
476
|
+
* The quotient is decided over the operands' exact scaled integers, so a repeating expansion
|
|
477
|
+
* is rounded from the exact rational rather than from an already-rounded intermediate. The
|
|
478
|
+
* operands are not rounded to the result budget before the division: only the rendered result
|
|
479
|
+
* is held to 34 significant digits, exactly as `+`, `-` and `*` hold their results.
|
|
480
|
+
*
|
|
481
|
+
* This is the `/` operator's arithmetic. A stated number of fraction digits is a composition:
|
|
482
|
+
* `round(a / b, places)`, or one of its named siblings.
|
|
483
|
+
*/
|
|
484
|
+
export function divideDecimalTexts(dividend, divisor, path = '') {
|
|
485
|
+
const a = toScaledInteger(dividend, path);
|
|
486
|
+
const b = toScaledInteger(divisor, path);
|
|
487
|
+
if (b.units === 0n) {
|
|
488
|
+
throw new AxiomError('ENGINE_ERROR', '/ divisor is zero', path);
|
|
489
|
+
}
|
|
490
|
+
const numerator = a.units * 10n ** BigInt(b.scale);
|
|
491
|
+
const denominator = b.units * 10n ** BigInt(a.scale);
|
|
492
|
+
const negative = numerator < 0n !== denominator < 0n;
|
|
493
|
+
const magnitudeNumerator = numerator < 0n ? -numerator : numerator;
|
|
494
|
+
const magnitudeDenominator = denominator < 0n ? -denominator : denominator;
|
|
495
|
+
if (magnitudeNumerator === 0n)
|
|
496
|
+
return asDecimalString('0', path);
|
|
497
|
+
// The leading digit's exponent, from digit counts rather than a binary float: the quotient
|
|
498
|
+
// sits in [10^(e-1), 10^e), so one exact comparison fixes which side of the estimate it is on.
|
|
499
|
+
let exponent = digitCount(magnitudeNumerator) - digitCount(magnitudeDenominator);
|
|
500
|
+
const compareToEstimate = exponent >= 0
|
|
501
|
+
? magnitudeNumerator >= magnitudeDenominator * 10n ** BigInt(exponent)
|
|
502
|
+
: magnitudeNumerator * 10n ** BigInt(-exponent) >= magnitudeDenominator;
|
|
503
|
+
if (!compareToEstimate)
|
|
504
|
+
exponent -= 1;
|
|
505
|
+
const divideAt = (shift) => {
|
|
506
|
+
const scaledNumerator = shift >= 0 ? magnitudeNumerator * 10n ** BigInt(shift) : magnitudeNumerator;
|
|
507
|
+
const scaledDenominator = shift >= 0 ? magnitudeDenominator : magnitudeDenominator * 10n ** BigInt(-shift);
|
|
508
|
+
return roundMagnitude(scaledNumerator / scaledDenominator, scaledNumerator % scaledDenominator, scaledDenominator, 'half_even', false);
|
|
509
|
+
};
|
|
510
|
+
let shift = DECIMAL_PRECISION - 1 - exponent;
|
|
511
|
+
let rounded = divideAt(shift);
|
|
512
|
+
// Rounding 9.99… up to 10.0… carries one digit, so the exponent moves with it.
|
|
513
|
+
if (rounded >= 10n ** BigInt(DECIMAL_PRECISION)) {
|
|
514
|
+
exponent += 1;
|
|
515
|
+
shift -= 1;
|
|
516
|
+
rounded = divideAt(shift);
|
|
517
|
+
}
|
|
518
|
+
const signed = negative ? -rounded : rounded;
|
|
519
|
+
const trailingExponent = exponent - DECIMAL_PRECISION + 1;
|
|
520
|
+
if (trailingExponent >= 0) {
|
|
521
|
+
return fromScaledInteger({ units: signed * 10n ** BigInt(trailingExponent), scale: 0 }, path);
|
|
522
|
+
}
|
|
523
|
+
return fromScaledInteger({ units: signed, scale: -trailingExponent }, path);
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* `pow(a, b)` for a non-negative integer exponent: repeated multiplication through the same
|
|
527
|
+
* exact path `*` uses. An intermediate or final result beyond 34 significant digits is
|
|
528
|
+
* `ENGINE_ERROR`, exactly as the equivalent chain of `*` would be.
|
|
529
|
+
*/
|
|
530
|
+
export function powDecimalTexts(base, exponent, path = '') {
|
|
531
|
+
if (!Number.isInteger(exponent) || exponent < 0) {
|
|
532
|
+
throw new AxiomError('ENGINE_ERROR', 'pow requires a non-negative integer exponent', path);
|
|
533
|
+
}
|
|
534
|
+
if (exponent === 0)
|
|
535
|
+
return asDecimalString('1', path);
|
|
536
|
+
let result = asDecimalString('1', path);
|
|
537
|
+
let factor = base;
|
|
538
|
+
let remaining = exponent;
|
|
539
|
+
while (remaining > 0) {
|
|
540
|
+
if (remaining % 2 === 1)
|
|
541
|
+
result = multiplyDecimalTexts(result, factor, path);
|
|
542
|
+
remaining = Math.floor(remaining / 2);
|
|
543
|
+
if (remaining > 0)
|
|
544
|
+
factor = multiplyDecimalTexts(factor, factor, path);
|
|
545
|
+
}
|
|
546
|
+
return result;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* `a / b`, rounded to `scale` with `mode`; a zero divisor is `ENGINE_ERROR`.
|
|
550
|
+
*
|
|
551
|
+
* The operands are scaled integers, so the quotient is decided with integer division and the
|
|
552
|
+
* remainder: no working precision, no double rounding. That keeps the exact-rational guarantee
|
|
553
|
+
* for every operand the wire admits, and only the rendered result is held to the 34-digit
|
|
554
|
+
* result budget.
|
|
555
|
+
*/
|
|
556
|
+
export function divideRoundDecimal(dividend, divisor, scale, mode, path = '') {
|
|
557
|
+
if (!ROUNDING_MODE_NAMES.includes(mode)) {
|
|
558
|
+
throw new AxiomError('ENGINE_ERROR', `unknown rounding mode: ${String(mode)}`, path);
|
|
559
|
+
}
|
|
560
|
+
if (!Number.isInteger(scale) || scale < 0 || scale > DECIMAL_PRECISION) {
|
|
561
|
+
throw new AxiomError('ENGINE_ERROR', `scale out of range: ${String(scale)}`, path);
|
|
562
|
+
}
|
|
563
|
+
const a = toScaledInteger(dividend, path);
|
|
564
|
+
const b = toScaledInteger(divisor, path);
|
|
565
|
+
if (b.units === 0n) {
|
|
566
|
+
throw new AxiomError('ENGINE_ERROR', 'divisor is zero', path);
|
|
567
|
+
}
|
|
568
|
+
// (A / 10^sa) / (B / 10^sb) * 10^scale = A * 10^(sb + scale) / (B * 10^sa).
|
|
569
|
+
const numerator = a.units * 10n ** BigInt(b.scale + scale);
|
|
570
|
+
const denominator = b.units * 10n ** BigInt(a.scale);
|
|
571
|
+
const negative = numerator < 0n !== denominator < 0n;
|
|
572
|
+
const magnitudeNumerator = numerator < 0n ? -numerator : numerator;
|
|
573
|
+
const magnitudeDenominator = denominator < 0n ? -denominator : denominator;
|
|
574
|
+
const rounded = roundMagnitude(magnitudeNumerator / magnitudeDenominator, magnitudeNumerator % magnitudeDenominator, magnitudeDenominator, mode, negative);
|
|
575
|
+
return fromScaledInteger({ units: negative ? -rounded : rounded, scale }, path);
|
|
576
|
+
}
|
|
577
|
+
/** A non-integer exponent must round inside six fraction digits. */
|
|
578
|
+
export const POW_EXPONENT_SCALE_LIMIT = 6;
|
|
579
|
+
/**
|
|
580
|
+
* The working precision for one arithmetic operand: never below the result budget, and high
|
|
581
|
+
* enough to hold every significant digit the wire admitted. An operand is not rounded down to
|
|
582
|
+
* the result budget before it is used; only the rendered result is held to that budget.
|
|
583
|
+
*/
|
|
584
|
+
function operandPrecision(text) {
|
|
585
|
+
return Math.max(DECIMAL_PRECISION, significantDigits(text));
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Parses an arithmetic operand exactly at `precision`, refusing only a magnitude the exponent
|
|
589
|
+
* bound cannot carry. The working precision is at least the operand's significant digits, so
|
|
590
|
+
* the value is not rounded before the operation runs.
|
|
591
|
+
*
|
|
592
|
+
* The constructor comes from `decimal-precision.ts`, which caps what it keeps: the widths a
|
|
593
|
+
* stored decimal can name are bounded only by the exponent budget, so a per-width cache is a
|
|
594
|
+
* process-global map an untrusted record can grow.
|
|
595
|
+
*/
|
|
596
|
+
function parseWorkingDecimal(text, precision, path) {
|
|
597
|
+
asDecimalString(text, path);
|
|
598
|
+
assertExponentWithinBudget(text, path);
|
|
599
|
+
const Working = workingDecimal(precision, DECIMAL_PRECISION, AxiomDecimal);
|
|
600
|
+
return new Working(text);
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* `x ^ y` computed at a working precision that holds the operands, then always rounded to
|
|
604
|
+
* `scale` before it is returned. For operands inside the 34-digit budget this is the 34-digit
|
|
605
|
+
* internal precision; a wider stored operand raises the working precision rather than being
|
|
606
|
+
* rounded down. A negative base with a fractional exponent and a zero base with a negative
|
|
607
|
+
* exponent have no exact decimal value, so they are `ENGINE_ERROR` rather than a silent `NaN`
|
|
608
|
+
* or `Infinity`.
|
|
609
|
+
*/
|
|
610
|
+
export function powDecimal(base, exponent, scale, mode, path = '') {
|
|
611
|
+
if (!ROUNDING_MODE_NAMES.includes(mode)) {
|
|
612
|
+
throw new AxiomError('ENGINE_ERROR', `unknown rounding mode: ${String(mode)}`, path);
|
|
613
|
+
}
|
|
614
|
+
if (!Number.isInteger(scale) || scale < 0 || scale > DECIMAL_PRECISION) {
|
|
615
|
+
throw new AxiomError('ENGINE_ERROR', `scale out of range: ${String(scale)}`, path);
|
|
616
|
+
}
|
|
617
|
+
// Each operand is held exactly, at its own width. The power is computed at the base's
|
|
618
|
+
// working precision, so a wide exponent does not inflate the arithmetic.
|
|
619
|
+
const power = parseWorkingDecimal(exponent, operandPrecision(exponent), path);
|
|
620
|
+
if (!power.isInteger() && scale > POW_EXPONENT_SCALE_LIMIT) {
|
|
621
|
+
throw new AxiomError('ENGINE_ERROR', `pow with a fractional exponent requires a scale of at most ${String(POW_EXPONENT_SCALE_LIMIT)}`, path);
|
|
622
|
+
}
|
|
623
|
+
const result = parseWorkingDecimal(base, operandPrecision(base), path).pow(power);
|
|
624
|
+
if (!result.isFinite()) {
|
|
625
|
+
throw new AxiomError('ENGINE_ERROR', 'pow has no exact decimal result', path);
|
|
626
|
+
}
|
|
627
|
+
return canonicalDecimal(result.toDecimalPlaces(scale, ROUNDING_MODES[mode]), path);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* `pow(a, b)` when the exponent is fractional or negative: the power at the language's
|
|
631
|
+
* arithmetic precision, rounded once to 34 significant digits with `half_even`.
|
|
632
|
+
*/
|
|
633
|
+
export function powToPrecisionDecimal(base, exponent, path = '') {
|
|
634
|
+
const power = parseWorkingDecimal(exponent, operandPrecision(exponent), path);
|
|
635
|
+
const value = parseWorkingDecimal(base, operandPrecision(base), path).pow(power);
|
|
636
|
+
if (!value.isFinite()) {
|
|
637
|
+
throw new AxiomError('ENGINE_ERROR', 'pow has no exact decimal result', path);
|
|
638
|
+
}
|
|
639
|
+
return canonicalDecimal(value.toSignificantDigits(DECIMAL_PRECISION, ROUNDING_MODES.half_even), path);
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* `abs(x)`: the magnitude of a canonical decimal, exactly. Negating text is a sign flip, not an
|
|
643
|
+
* arithmetic operation, so no digit is touched and a 34-digit operand stays 34 digits.
|
|
644
|
+
*/
|
|
645
|
+
export function absDecimalText(value, path = '') {
|
|
646
|
+
asDecimalString(value, path);
|
|
647
|
+
return value.startsWith('-') ? asDecimalString(value.slice(1), path) : value;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* `ceil(x)` / `floor(x)` at scale zero, as a canonical integer.
|
|
651
|
+
*
|
|
652
|
+
* The modes are the language's own: `ceiling` is toward positive infinity and `floor` toward
|
|
653
|
+
* negative infinity, so `ceil(-2.1)` is `-2` and `floor(-2.1)` is `-3` (`EXPR-11.1.11`,
|
|
654
|
+
* `EXPR-11.1.12`). `roundDecimal` already decides both over integers, so this is the one
|
|
655
|
+
* rounding implementation with a domain cast on top: a result outside the canonical integer
|
|
656
|
+
* range is an engine error rather than a lossy `Number`.
|
|
657
|
+
*/
|
|
658
|
+
function integralRounded(value, op, path) {
|
|
659
|
+
const rounded = roundDecimal(value, 0, op === 'ceil' ? 'ceiling' : 'floor', path);
|
|
660
|
+
if (!INTEGER_TEXT_PATTERN.test(rounded)) {
|
|
661
|
+
// Rounding at scale zero always renders an integer; a fraction here is a contract
|
|
662
|
+
// violation in `roundDecimal`, not a value the caller can act on.
|
|
663
|
+
throw new AxiomError('ENGINE_ERROR', `${op} produced a non-integer result`, path);
|
|
664
|
+
}
|
|
665
|
+
const result = Number(rounded);
|
|
666
|
+
if (!isSafeInteger(result)) {
|
|
667
|
+
throw new AxiomError('ENGINE_ERROR', `${op} result is outside the canonical integer range`, path);
|
|
668
|
+
}
|
|
669
|
+
return result;
|
|
670
|
+
}
|
|
671
|
+
/** `ceil(x)`: the least integer not below `x`, toward positive infinity. */
|
|
672
|
+
export function ceilDecimal(value, path = '') {
|
|
673
|
+
return integralRounded(asDecimalString(value, path), 'ceil', path);
|
|
674
|
+
}
|
|
675
|
+
/** `floor(x)`: the greatest integer not above `x`, toward negative infinity. */
|
|
676
|
+
export function floorDecimal(value, path = '') {
|
|
677
|
+
return integralRounded(asDecimalString(value, path), 'floor', path);
|
|
678
|
+
}
|
|
679
|
+
/** Euclid's algorithm over the magnitudes the scaled-integer paths produce. */
|
|
680
|
+
function greatestCommonDivisor(left, right) {
|
|
681
|
+
let a = left < 0n ? -left : left;
|
|
682
|
+
let b = right;
|
|
683
|
+
while (b !== 0n) {
|
|
684
|
+
const remainder = a % b;
|
|
685
|
+
a = b;
|
|
686
|
+
b = remainder;
|
|
687
|
+
}
|
|
688
|
+
return a;
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* `sum(values) / values.length` as exact decimal text, or `undefined` when the quotient has no
|
|
692
|
+
* finite base-10 expansion the language can carry: a reduced denominator with a prime factor
|
|
693
|
+
* other than `2` or `5`, the exponent budget, or the 34-significant-digit result budget.
|
|
694
|
+
* The language carries exact decimals, so an average that cannot be written down exactly is
|
|
695
|
+
* undecided rather than rounded: `avg([1, 2, 2])` is `UNKNOWN`, and an author who wants a
|
|
696
|
+
* stated precision writes `round(sum(xs) / count(xs), places)` (`EXPR-10.2.7`). The
|
|
697
|
+
* test is arithmetic on the reduced fraction, not a float approximation: the denominator of
|
|
698
|
+
* an exact decimal may divide only by `2` and `5`.
|
|
699
|
+
*
|
|
700
|
+
* An empty list has no count to divide by, so the caller answers `UNKNOWN` before this runs.
|
|
701
|
+
*/
|
|
702
|
+
export function exactAverageDecimalTexts(values, path = '') {
|
|
703
|
+
if (values.length === 0)
|
|
704
|
+
return undefined;
|
|
705
|
+
// The total is an intermediate: it may carry one more digit than the 34-digit result
|
|
706
|
+
// budget and still have an exact mean inside it (`999…9` twice has `1999…8` as its total
|
|
707
|
+
// and `999…9` as its mean). Only the rendered quotient meets the budget.
|
|
708
|
+
const { units, scale } = sumScaledIntegers(values, path);
|
|
709
|
+
if (units === 0n)
|
|
710
|
+
return asDecimalString('0', path);
|
|
711
|
+
let numerator = units;
|
|
712
|
+
let denominator = BigInt(values.length) * 10n ** BigInt(scale);
|
|
713
|
+
const divisor = greatestCommonDivisor(numerator, denominator);
|
|
714
|
+
numerator /= divisor;
|
|
715
|
+
denominator /= divisor;
|
|
716
|
+
// The reduced denominator is what the render divides by; the factor walk below consumes its
|
|
717
|
+
// copy to learn how many fraction digits it needs, so the original is kept.
|
|
718
|
+
const reducedDenominator = denominator;
|
|
719
|
+
let twos = 0;
|
|
720
|
+
let fives = 0;
|
|
721
|
+
while (denominator % 2n === 0n) {
|
|
722
|
+
denominator /= 2n;
|
|
723
|
+
twos += 1;
|
|
724
|
+
}
|
|
725
|
+
while (denominator % 5n === 0n) {
|
|
726
|
+
denominator /= 5n;
|
|
727
|
+
fives += 1;
|
|
728
|
+
}
|
|
729
|
+
// Any other prime factor repeats forever in base 10, so no decimal spelling exists.
|
|
730
|
+
if (denominator !== 1n)
|
|
731
|
+
return undefined;
|
|
732
|
+
const digits = Math.max(twos, fives);
|
|
733
|
+
// `10^digits` carries enough powers of both primes, so this division is exact. The fraction
|
|
734
|
+
// run may exceed 34 digits while the significant digits fit — a small mean with many leading
|
|
735
|
+
// fractional zeros is the case that found this — so only the rendered value's significant
|
|
736
|
+
// digits and exponent budget decide the answer.
|
|
737
|
+
const rendered = renderScaledIntegerWithinBudget({
|
|
738
|
+
units: (numerator * 10n ** BigInt(digits)) / reducedDenominator,
|
|
739
|
+
scale: digits,
|
|
740
|
+
}, path);
|
|
741
|
+
if (rendered === undefined)
|
|
742
|
+
return undefined;
|
|
743
|
+
return significantDigits(rendered) > DECIMAL_PRECISION ? undefined : rendered;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* `(a + b) / 2`, exactly. Halving appends one fraction digit and multiplies the magnitude by
|
|
747
|
+
* five, so a midpoint always terminates; `undefined` when the midpoint's rendered text exceeds
|
|
748
|
+
* the exponent budget or needs more than the 34-digit result budget (`EXPR-10.2.8`), which the
|
|
749
|
+
* caller answers as `UNKNOWN` rather than an engine error. The sum is an intermediate and
|
|
750
|
+
* carries no budget of its own.
|
|
751
|
+
*/
|
|
752
|
+
function midpointDecimalTexts(first, second, path = '') {
|
|
753
|
+
const total = sumScaledIntegers([first, second], path);
|
|
754
|
+
if (total.units === 0n)
|
|
755
|
+
return asDecimalString('0', path);
|
|
756
|
+
const rendered = renderScaledIntegerWithinBudget({ units: total.units * 5n, scale: total.scale + 1 }, path);
|
|
757
|
+
if (rendered === undefined)
|
|
758
|
+
return undefined;
|
|
759
|
+
return significantDigits(rendered) > DECIMAL_PRECISION ? undefined : rendered;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* `median(values)`: the middle value of the canonical decimal order, or the exact midpoint of
|
|
763
|
+
* the two middle values for an even count.
|
|
764
|
+
*
|
|
765
|
+
* Ordering is `compareDecimalTexts`, the exact decimal comparison `==` and `<` already use, so
|
|
766
|
+
* no value passes through a binary float and two spellings of one amount cannot split a list.
|
|
767
|
+
* An empty list has no element to choose, so the caller answers `UNKNOWN`.
|
|
768
|
+
*/
|
|
769
|
+
export function medianDecimalTexts(values, path = '') {
|
|
770
|
+
if (values.length === 0)
|
|
771
|
+
return undefined;
|
|
772
|
+
const ordered = [...values].sort((left, right) => compareDecimalTexts(left, right, path));
|
|
773
|
+
const middle = Math.floor(ordered.length / 2);
|
|
774
|
+
if (ordered.length % 2 === 1)
|
|
775
|
+
return ordered[middle];
|
|
776
|
+
const lower = ordered[middle - 1];
|
|
777
|
+
const upper = ordered[middle];
|
|
778
|
+
if (lower === undefined || upper === undefined)
|
|
779
|
+
return undefined;
|
|
780
|
+
return midpointDecimalTexts(lower, upper, path);
|
|
781
|
+
}
|
|
782
|
+
//# sourceMappingURL=decimal.js.map
|