@ac-kit/math-numbers 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +28 -0
- package/README.md +111 -0
- package/dist/decimal/_aligned-coefficients.d.ts +5 -0
- package/dist/decimal/_aligned-coefficients.d.ts.map +1 -0
- package/dist/decimal/_aligned-coefficients.js +15 -0
- package/dist/decimal/_aligned-coefficients.js.map +1 -0
- package/dist/decimal/_normalize.d.ts +7 -0
- package/dist/decimal/_normalize.d.ts.map +1 -0
- package/dist/decimal/_normalize.js +24 -0
- package/dist/decimal/_normalize.js.map +1 -0
- package/dist/decimal/_round.d.ts +10 -0
- package/dist/decimal/_round.d.ts.map +1 -0
- package/dist/decimal/_round.js +62 -0
- package/dist/decimal/_round.js.map +1 -0
- package/dist/decimal/decimal-abs.d.ts +4 -0
- package/dist/decimal/decimal-abs.d.ts.map +1 -0
- package/dist/decimal/decimal-abs.js +6 -0
- package/dist/decimal/decimal-abs.js.map +1 -0
- package/dist/decimal/decimal-add.d.ts +4 -0
- package/dist/decimal/decimal-add.d.ts.map +1 -0
- package/dist/decimal/decimal-add.js +9 -0
- package/dist/decimal/decimal-add.js.map +1 -0
- package/dist/decimal/decimal-compare.d.ts +5 -0
- package/dist/decimal/decimal-compare.d.ts.map +1 -0
- package/dist/decimal/decimal-compare.js +10 -0
- package/dist/decimal/decimal-compare.js.map +1 -0
- package/dist/decimal/decimal-digit-at.d.ts +15 -0
- package/dist/decimal/decimal-digit-at.d.ts.map +1 -0
- package/dist/decimal/decimal-digit-at.js +26 -0
- package/dist/decimal/decimal-digit-at.js.map +1 -0
- package/dist/decimal/decimal-div.d.ts +13 -0
- package/dist/decimal/decimal-div.d.ts.map +1 -0
- package/dist/decimal/decimal-div.js +41 -0
- package/dist/decimal/decimal-div.js.map +1 -0
- package/dist/decimal/decimal-fractional-precision.d.ts +12 -0
- package/dist/decimal/decimal-fractional-precision.d.ts.map +1 -0
- package/dist/decimal/decimal-fractional-precision.js +13 -0
- package/dist/decimal/decimal-fractional-precision.js.map +1 -0
- package/dist/decimal/decimal-from-big-int.d.ts +8 -0
- package/dist/decimal/decimal-from-big-int.d.ts.map +1 -0
- package/dist/decimal/decimal-from-big-int.js +10 -0
- package/dist/decimal/decimal-from-big-int.js.map +1 -0
- package/dist/decimal/decimal-from-number.d.ts +8 -0
- package/dist/decimal/decimal-from-number.d.ts.map +1 -0
- package/dist/decimal/decimal-from-number.js +17 -0
- package/dist/decimal/decimal-from-number.js.map +1 -0
- package/dist/decimal/decimal-from-string.d.ts +8 -0
- package/dist/decimal/decimal-from-string.d.ts.map +1 -0
- package/dist/decimal/decimal-from-string.js +33 -0
- package/dist/decimal/decimal-from-string.js.map +1 -0
- package/dist/decimal/decimal-integral-fractional.d.ts +12 -0
- package/dist/decimal/decimal-integral-fractional.d.ts.map +1 -0
- package/dist/decimal/decimal-integral-fractional.js +31 -0
- package/dist/decimal/decimal-integral-fractional.js.map +1 -0
- package/dist/decimal/decimal-integral-precision.d.ts +10 -0
- package/dist/decimal/decimal-integral-precision.d.ts.map +1 -0
- package/dist/decimal/decimal-integral-precision.js +12 -0
- package/dist/decimal/decimal-integral-precision.js.map +1 -0
- package/dist/decimal/decimal-inv.d.ts +4 -0
- package/dist/decimal/decimal-inv.d.ts.map +1 -0
- package/dist/decimal/decimal-inv.js +7 -0
- package/dist/decimal/decimal-inv.js.map +1 -0
- package/dist/decimal/decimal-is-equal.d.ts +4 -0
- package/dist/decimal/decimal-is-equal.d.ts.map +1 -0
- package/dist/decimal/decimal-is-equal.js +6 -0
- package/dist/decimal/decimal-is-equal.js.map +1 -0
- package/dist/decimal/decimal-mul.d.ts +4 -0
- package/dist/decimal/decimal-mul.d.ts.map +1 -0
- package/dist/decimal/decimal-mul.js +7 -0
- package/dist/decimal/decimal-mul.js.map +1 -0
- package/dist/decimal/decimal-neg.d.ts +4 -0
- package/dist/decimal/decimal-neg.d.ts.map +1 -0
- package/dist/decimal/decimal-neg.js +9 -0
- package/dist/decimal/decimal-neg.js.map +1 -0
- package/dist/decimal/decimal-round-to-context.d.ts +9 -0
- package/dist/decimal/decimal-round-to-context.d.ts.map +1 -0
- package/dist/decimal/decimal-round-to-context.js +22 -0
- package/dist/decimal/decimal-round-to-context.js.map +1 -0
- package/dist/decimal/decimal-round-to-place.d.ts +20 -0
- package/dist/decimal/decimal-round-to-place.d.ts.map +1 -0
- package/dist/decimal/decimal-round-to-place.js +32 -0
- package/dist/decimal/decimal-round-to-place.js.map +1 -0
- package/dist/decimal/decimal-sign.d.ts +5 -0
- package/dist/decimal/decimal-sign.d.ts.map +1 -0
- package/dist/decimal/decimal-sign.js +8 -0
- package/dist/decimal/decimal-sign.js.map +1 -0
- package/dist/decimal/decimal-sqrt.d.ts +11 -0
- package/dist/decimal/decimal-sqrt.d.ts.map +1 -0
- package/dist/decimal/decimal-sqrt.js +42 -0
- package/dist/decimal/decimal-sqrt.js.map +1 -0
- package/dist/decimal/decimal-sub.d.ts +4 -0
- package/dist/decimal/decimal-sub.d.ts.map +1 -0
- package/dist/decimal/decimal-sub.js +7 -0
- package/dist/decimal/decimal-sub.js.map +1 -0
- package/dist/decimal/decimal-to-exponential.d.ts +18 -0
- package/dist/decimal/decimal-to-exponential.d.ts.map +1 -0
- package/dist/decimal/decimal-to-exponential.js +41 -0
- package/dist/decimal/decimal-to-exponential.js.map +1 -0
- package/dist/decimal/decimal-to-fixed.d.ts +20 -0
- package/dist/decimal/decimal-to-fixed.d.ts.map +1 -0
- package/dist/decimal/decimal-to-fixed.js +39 -0
- package/dist/decimal/decimal-to-fixed.js.map +1 -0
- package/dist/decimal/decimal-to-number.d.ts +4 -0
- package/dist/decimal/decimal-to-number.d.ts.map +1 -0
- package/dist/decimal/decimal-to-number.js +5 -0
- package/dist/decimal/decimal-to-number.js.map +1 -0
- package/dist/decimal/decimal-to-precision.d.ts +19 -0
- package/dist/decimal/decimal-to-precision.d.ts.map +1 -0
- package/dist/decimal/decimal-to-precision.js +35 -0
- package/dist/decimal/decimal-to-precision.js.map +1 -0
- package/dist/decimal/decimal-to-string.d.ts +28 -0
- package/dist/decimal/decimal-to-string.d.ts.map +1 -0
- package/dist/decimal/decimal-to-string.js +64 -0
- package/dist/decimal/decimal-to-string.js.map +1 -0
- package/dist/decimal/decimal-types.d.ts +54 -0
- package/dist/decimal/decimal-types.d.ts.map +1 -0
- package/dist/decimal/decimal-types.js +45 -0
- package/dist/decimal/decimal-types.js.map +1 -0
- package/dist/format-numeral.d.ts +42 -0
- package/dist/format-numeral.d.ts.map +1 -0
- package/dist/format-numeral.js +80 -0
- package/dist/format-numeral.js.map +1 -0
- package/dist/globals.d.ts +38 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +22 -0
- package/dist/globals.js.map +1 -0
- package/dist/ieee754/binary/_all-ones-exp.d.ts +4 -0
- package/dist/ieee754/binary/_all-ones-exp.d.ts.map +1 -0
- package/dist/ieee754/binary/_all-ones-exp.js +6 -0
- package/dist/ieee754/binary/_all-ones-exp.js.map +1 -0
- package/dist/ieee754/binary/_bias.d.ts +7 -0
- package/dist/ieee754/binary/_bias.d.ts.map +1 -0
- package/dist/ieee754/binary/_bias.js +8 -0
- package/dist/ieee754/binary/_bias.js.map +1 -0
- package/dist/ieee754/binary/_encode-big-int.d.ts +11 -0
- package/dist/ieee754/binary/_encode-big-int.d.ts.map +1 -0
- package/dist/ieee754/binary/_encode-big-int.js +28 -0
- package/dist/ieee754/binary/_encode-big-int.js.map +1 -0
- package/dist/ieee754/binary/_encode-exp-sign.d.ts +11 -0
- package/dist/ieee754/binary/_encode-exp-sign.d.ts.map +1 -0
- package/dist/ieee754/binary/_encode-exp-sign.js +32 -0
- package/dist/ieee754/binary/_encode-exp-sign.js.map +1 -0
- package/dist/ieee754/binary/_encode-limbs.d.ts +8 -0
- package/dist/ieee754/binary/_encode-limbs.d.ts.map +1 -0
- package/dist/ieee754/binary/_encode-limbs.js +21 -0
- package/dist/ieee754/binary/_encode-limbs.js.map +1 -0
- package/dist/ieee754/binary/_exponent-width.d.ts +9 -0
- package/dist/ieee754/binary/_exponent-width.d.ts.map +1 -0
- package/dist/ieee754/binary/_exponent-width.js +10 -0
- package/dist/ieee754/binary/_exponent-width.js.map +1 -0
- package/dist/ieee754/binary/_finite-or-special.d.ts +8 -0
- package/dist/ieee754/binary/_finite-or-special.d.ts.map +1 -0
- package/dist/ieee754/binary/_finite-or-special.js +17 -0
- package/dist/ieee754/binary/_finite-or-special.js.map +1 -0
- package/dist/ieee754/binary/_finite-to-big-int.d.ts +8 -0
- package/dist/ieee754/binary/_finite-to-big-int.d.ts.map +1 -0
- package/dist/ieee754/binary/_finite-to-big-int.js +13 -0
- package/dist/ieee754/binary/_finite-to-big-int.js.map +1 -0
- package/dist/ieee754/binary/_finite-to-limbs.d.ts +7 -0
- package/dist/ieee754/binary/_finite-to-limbs.d.ts.map +1 -0
- package/dist/ieee754/binary/_finite-to-limbs.js +12 -0
- package/dist/ieee754/binary/_finite-to-limbs.js.map +1 -0
- package/dist/ieee754/binary/_get-biased-exp.d.ts +13 -0
- package/dist/ieee754/binary/_get-biased-exp.d.ts.map +1 -0
- package/dist/ieee754/binary/_get-biased-exp.js +26 -0
- package/dist/ieee754/binary/_get-biased-exp.js.map +1 -0
- package/dist/ieee754/binary/_get-sign.d.ts +5 -0
- package/dist/ieee754/binary/_get-sign.d.ts.map +1 -0
- package/dist/ieee754/binary/_get-sign.js +6 -0
- package/dist/ieee754/binary/_get-sign.js.map +1 -0
- package/dist/ieee754/binary/_get-trailing-sig-big-int.d.ts +9 -0
- package/dist/ieee754/binary/_get-trailing-sig-big-int.d.ts.map +1 -0
- package/dist/ieee754/binary/_get-trailing-sig-big-int.js +24 -0
- package/dist/ieee754/binary/_get-trailing-sig-big-int.js.map +1 -0
- package/dist/ieee754/binary/_get-trailing-sig-limbs.d.ts +9 -0
- package/dist/ieee754/binary/_get-trailing-sig-limbs.d.ts.map +1 -0
- package/dist/ieee754/binary/_get-trailing-sig-limbs.js +22 -0
- package/dist/ieee754/binary/_get-trailing-sig-limbs.js.map +1 -0
- package/dist/ieee754/binary/_narrow-to-big-int.d.ts +7 -0
- package/dist/ieee754/binary/_narrow-to-big-int.d.ts.map +1 -0
- package/dist/ieee754/binary/_narrow-to-big-int.js +9 -0
- package/dist/ieee754/binary/_narrow-to-big-int.js.map +1 -0
- package/dist/ieee754/binary/_normalize.d.ts +47 -0
- package/dist/ieee754/binary/_normalize.d.ts.map +1 -0
- package/dist/ieee754/binary/_normalize.js +105 -0
- package/dist/ieee754/binary/_normalize.js.map +1 -0
- package/dist/ieee754/binary/_pack-from-big-int.d.ts +13 -0
- package/dist/ieee754/binary/_pack-from-big-int.d.ts.map +1 -0
- package/dist/ieee754/binary/_pack-from-big-int.js +68 -0
- package/dist/ieee754/binary/_pack-from-big-int.js.map +1 -0
- package/dist/ieee754/binary/_pack-from-limbs.d.ts +9 -0
- package/dist/ieee754/binary/_pack-from-limbs.d.ts.map +1 -0
- package/dist/ieee754/binary/_pack-from-limbs.js +67 -0
- package/dist/ieee754/binary/_pack-from-limbs.js.map +1 -0
- package/dist/ieee754/binary/_to-format.d.ts +12 -0
- package/dist/ieee754/binary/_to-format.d.ts.map +1 -0
- package/dist/ieee754/binary/_to-format.js +20 -0
- package/dist/ieee754/binary/_to-format.js.map +1 -0
- package/dist/ieee754/binary/_trailing-width.d.ts +7 -0
- package/dist/ieee754/binary/_trailing-width.d.ts.map +1 -0
- package/dist/ieee754/binary/_trailing-width.js +8 -0
- package/dist/ieee754/binary/_trailing-width.js.map +1 -0
- package/dist/ieee754/binary/_unpack-to-big-int.d.ts +21 -0
- package/dist/ieee754/binary/_unpack-to-big-int.d.ts.map +1 -0
- package/dist/ieee754/binary/_unpack-to-big-int.js +56 -0
- package/dist/ieee754/binary/_unpack-to-big-int.js.map +1 -0
- package/dist/ieee754/binary/_unpack-to-limbs.d.ts +10 -0
- package/dist/ieee754/binary/_unpack-to-limbs.d.ts.map +1 -0
- package/dist/ieee754/binary/_unpack-to-limbs.js +46 -0
- package/dist/ieee754/binary/_unpack-to-limbs.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-abs.d.ts +4 -0
- package/dist/ieee754/binary/ieee-binary-abs.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-abs.js +9 -0
- package/dist/ieee754/binary/ieee-binary-abs.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-add.d.ts +10 -0
- package/dist/ieee754/binary/ieee-binary-add.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-add.js +125 -0
- package/dist/ieee754/binary/ieee-binary-add.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-cmp.d.ts +10 -0
- package/dist/ieee754/binary/ieee-binary-cmp.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-cmp.js +44 -0
- package/dist/ieee754/binary/ieee-binary-cmp.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-from-decimal.d.ts +19 -0
- package/dist/ieee754/binary/ieee-binary-from-decimal.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-from-decimal.js +39 -0
- package/dist/ieee754/binary/ieee-binary-from-decimal.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-from-number.d.ts +10 -0
- package/dist/ieee754/binary/ieee-binary-from-number.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-from-number.js +23 -0
- package/dist/ieee754/binary/ieee-binary-from-number.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-is-finite.d.ts +11 -0
- package/dist/ieee754/binary/ieee-binary-is-finite.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-is-finite.js +12 -0
- package/dist/ieee754/binary/ieee-binary-is-finite.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-is-infinite.d.ts +9 -0
- package/dist/ieee754/binary/ieee-binary-is-infinite.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-is-infinite.js +10 -0
- package/dist/ieee754/binary/ieee-binary-is-infinite.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-is-nan.d.ts +12 -0
- package/dist/ieee754/binary/ieee-binary-is-nan.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-is-nan.js +13 -0
- package/dist/ieee754/binary/ieee-binary-is-nan.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-neg.d.ts +4 -0
- package/dist/ieee754/binary/ieee-binary-neg.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-neg.js +10 -0
- package/dist/ieee754/binary/ieee-binary-neg.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-normalize.d.ts +13 -0
- package/dist/ieee754/binary/ieee-binary-normalize.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-normalize.js +14 -0
- package/dist/ieee754/binary/ieee-binary-normalize.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-sign.d.ts +19 -0
- package/dist/ieee754/binary/ieee-binary-sign.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-sign.js +25 -0
- package/dist/ieee754/binary/ieee-binary-sign.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-sqrt.d.ts +17 -0
- package/dist/ieee754/binary/ieee-binary-sqrt.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-sqrt.js +56 -0
- package/dist/ieee754/binary/ieee-binary-sqrt.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-sub.d.ts +5 -0
- package/dist/ieee754/binary/ieee-binary-sub.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-sub.js +7 -0
- package/dist/ieee754/binary/ieee-binary-sub.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-to-decimal.d.ts +21 -0
- package/dist/ieee754/binary/ieee-binary-to-decimal.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-to-decimal.js +28 -0
- package/dist/ieee754/binary/ieee-binary-to-decimal.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-to-number.d.ts +14 -0
- package/dist/ieee754/binary/ieee-binary-to-number.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-to-number.js +30 -0
- package/dist/ieee754/binary/ieee-binary-to-number.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-to-shortest-decimal.d.ts +34 -0
- package/dist/ieee754/binary/ieee-binary-to-shortest-decimal.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-to-shortest-decimal.js +108 -0
- package/dist/ieee754/binary/ieee-binary-to-shortest-decimal.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-to-string.d.ts +25 -0
- package/dist/ieee754/binary/ieee-binary-to-string.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-to-string.js +48 -0
- package/dist/ieee754/binary/ieee-binary-to-string.js.map +1 -0
- package/dist/ieee754/binary/ieee-binary-types.d.ts +39 -0
- package/dist/ieee754/binary/ieee-binary-types.d.ts.map +1 -0
- package/dist/ieee754/binary/ieee-binary-types.js +6 -0
- package/dist/ieee754/binary/ieee-binary-types.js.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_axpby-batch.d.ts +4 -0
- package/dist/ieee754/binary/kernels/fallback/_axpby-batch.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_axpby-batch.js +11 -0
- package/dist/ieee754/binary/kernels/fallback/_axpby-batch.js.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_axpby.d.ts +8 -0
- package/dist/ieee754/binary/kernels/fallback/_axpby.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_axpby.js +10 -0
- package/dist/ieee754/binary/kernels/fallback/_axpby.js.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_axpy-batch.d.ts +4 -0
- package/dist/ieee754/binary/kernels/fallback/_axpy-batch.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_axpy-batch.js +10 -0
- package/dist/ieee754/binary/kernels/fallback/_axpy-batch.js.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_axpy.d.ts +8 -0
- package/dist/ieee754/binary/kernels/fallback/_axpy.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_axpy.js +10 -0
- package/dist/ieee754/binary/kernels/fallback/_axpy.js.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_batch-element.d.ts +13 -0
- package/dist/ieee754/binary/kernels/fallback/_batch-element.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_batch-element.js +22 -0
- package/dist/ieee754/binary/kernels/fallback/_batch-element.js.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_div-batch.d.ts +4 -0
- package/dist/ieee754/binary/kernels/fallback/_div-batch.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_div-batch.js +9 -0
- package/dist/ieee754/binary/kernels/fallback/_div-batch.js.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_div.d.ts +11 -0
- package/dist/ieee754/binary/kernels/fallback/_div.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_div.js +46 -0
- package/dist/ieee754/binary/kernels/fallback/_div.js.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_mul-batch.d.ts +7 -0
- package/dist/ieee754/binary/kernels/fallback/_mul-batch.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_mul-batch.js +12 -0
- package/dist/ieee754/binary/kernels/fallback/_mul-batch.js.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_mul.d.ts +11 -0
- package/dist/ieee754/binary/kernels/fallback/_mul.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/_mul.js +38 -0
- package/dist/ieee754/binary/kernels/fallback/_mul.js.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/fallback-kernel.d.ts +24 -0
- package/dist/ieee754/binary/kernels/fallback/fallback-kernel.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/fallback/fallback-kernel.js +23 -0
- package/dist/ieee754/binary/kernels/fallback/fallback-kernel.js.map +1 -0
- package/dist/ieee754/binary/kernels/kernel.d.ts +20 -0
- package/dist/ieee754/binary/kernels/kernel.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/kernel.js +30 -0
- package/dist/ieee754/binary/kernels/kernel.js.map +1 -0
- package/dist/ieee754/binary/kernels/types.d.ts +63 -0
- package/dist/ieee754/binary/kernels/types.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/types.js +2 -0
- package/dist/ieee754/binary/kernels/types.js.map +1 -0
- package/dist/ieee754/binary/kernels/wasm/_wasm-bytes.generated.d.ts +3 -0
- package/dist/ieee754/binary/kernels/wasm/_wasm-bytes.generated.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/wasm/_wasm-bytes.generated.js +3 -0
- package/dist/ieee754/binary/kernels/wasm/_wasm-bytes.generated.js.map +1 -0
- package/dist/ieee754/binary/kernels/wasm/wasm-kernel.d.ts +29 -0
- package/dist/ieee754/binary/kernels/wasm/wasm-kernel.d.ts.map +1 -0
- package/dist/ieee754/binary/kernels/wasm/wasm-kernel.js +91 -0
- package/dist/ieee754/binary/kernels/wasm/wasm-kernel.js.map +1 -0
- package/dist/ieee754/common/_neg-sign.d.ts +4 -0
- package/dist/ieee754/common/_neg-sign.d.ts.map +1 -0
- package/dist/ieee754/common/_neg-sign.js +5 -0
- package/dist/ieee754/common/_neg-sign.js.map +1 -0
- package/dist/ieee754/common/ieee-sign.d.ts +2 -0
- package/dist/ieee754/common/ieee-sign.d.ts.map +1 -0
- package/dist/ieee754/common/ieee-sign.js +2 -0
- package/dist/ieee754/common/ieee-sign.js.map +1 -0
- package/dist/ieee754/decimal/ieee-decimal-types.d.ts +33 -0
- package/dist/ieee754/decimal/ieee-decimal-types.d.ts.map +1 -0
- package/dist/ieee754/decimal/ieee-decimal-types.js +2 -0
- package/dist/ieee754/decimal/ieee-decimal-types.js.map +1 -0
- package/dist/ieee754/ieee-format.d.ts +30 -0
- package/dist/ieee754/ieee-format.d.ts.map +1 -0
- package/dist/ieee754/ieee-format.js +59 -0
- package/dist/ieee754/ieee-format.js.map +1 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +93 -0
- package/dist/index.js.map +1 -0
- package/dist/integral-fractional.d.ts +83 -0
- package/dist/integral-fractional.d.ts.map +1 -0
- package/dist/integral-fractional.js +112 -0
- package/dist/integral-fractional.js.map +1 -0
- package/dist/num/_binary-fp-base.d.ts +49 -0
- package/dist/num/_binary-fp-base.d.ts.map +1 -0
- package/dist/num/_binary-fp-base.js +26 -0
- package/dist/num/_binary-fp-base.js.map +1 -0
- package/dist/num/_factory.d.ts +23 -0
- package/dist/num/_factory.d.ts.map +1 -0
- package/dist/num/_factory.js +36 -0
- package/dist/num/_factory.js.map +1 -0
- package/dist/num/_promote.d.ts +26 -0
- package/dist/num/_promote.d.ts.map +1 -0
- package/dist/num/_promote.js +38 -0
- package/dist/num/_promote.js.map +1 -0
- package/dist/num/_special-value.d.ts +76 -0
- package/dist/num/_special-value.d.ts.map +1 -0
- package/dist/num/_special-value.js +108 -0
- package/dist/num/_special-value.js.map +1 -0
- package/dist/num/binary-fp.d.ts +135 -0
- package/dist/num/binary-fp.d.ts.map +1 -0
- package/dist/num/binary-fp.js +330 -0
- package/dist/num/binary-fp.js.map +1 -0
- package/dist/num/binary-fp128.d.ts +143 -0
- package/dist/num/binary-fp128.d.ts.map +1 -0
- package/dist/num/binary-fp128.js +265 -0
- package/dist/num/binary-fp128.js.map +1 -0
- package/dist/num/binary-fp16.d.ts +131 -0
- package/dist/num/binary-fp16.d.ts.map +1 -0
- package/dist/num/binary-fp16.js +262 -0
- package/dist/num/binary-fp16.js.map +1 -0
- package/dist/num/binary-fp32.d.ts +131 -0
- package/dist/num/binary-fp32.d.ts.map +1 -0
- package/dist/num/binary-fp32.js +254 -0
- package/dist/num/binary-fp32.js.map +1 -0
- package/dist/num/binary-fp64.d.ts +140 -0
- package/dist/num/binary-fp64.d.ts.map +1 -0
- package/dist/num/binary-fp64.js +262 -0
- package/dist/num/binary-fp64.js.map +1 -0
- package/dist/num/decimal-num.d.ts +149 -0
- package/dist/num/decimal-num.d.ts.map +1 -0
- package/dist/num/decimal-num.js +275 -0
- package/dist/num/decimal-num.js.map +1 -0
- package/dist/num/fraction.d.ts +138 -0
- package/dist/num/fraction.d.ts.map +1 -0
- package/dist/num/fraction.js +299 -0
- package/dist/num/fraction.js.map +1 -0
- package/dist/num/ibitwise.d.ts +23 -0
- package/dist/num/ibitwise.d.ts.map +1 -0
- package/dist/num/ibitwise.js +2 -0
- package/dist/num/ibitwise.js.map +1 -0
- package/dist/num/integer-num.d.ts +268 -0
- package/dist/num/integer-num.d.ts.map +1 -0
- package/dist/num/integer-num.js +471 -0
- package/dist/num/integer-num.js.map +1 -0
- package/dist/num/inum.d.ts +125 -0
- package/dist/num/inum.d.ts.map +1 -0
- package/dist/num/inum.js +2 -0
- package/dist/num/inum.js.map +1 -0
- package/dist/overflow-mode.d.ts +17 -0
- package/dist/overflow-mode.d.ts.map +1 -0
- package/dist/overflow-mode.js +8 -0
- package/dist/overflow-mode.js.map +1 -0
- package/dist/precision-kind.d.ts +85 -0
- package/dist/precision-kind.d.ts.map +1 -0
- package/dist/precision-kind.js +9 -0
- package/dist/precision-kind.js.map +1 -0
- package/dist/rational/rational-abs.d.ts +4 -0
- package/dist/rational/rational-abs.d.ts.map +1 -0
- package/dist/rational/rational-abs.js +6 -0
- package/dist/rational/rational-abs.js.map +1 -0
- package/dist/rational/rational-add.d.ts +10 -0
- package/dist/rational/rational-add.d.ts.map +1 -0
- package/dist/rational/rational-add.js +28 -0
- package/dist/rational/rational-add.js.map +1 -0
- package/dist/rational/rational-compare.d.ts +10 -0
- package/dist/rational/rational-compare.d.ts.map +1 -0
- package/dist/rational/rational-compare.js +15 -0
- package/dist/rational/rational-compare.js.map +1 -0
- package/dist/rational/rational-decimal-precision.d.ts +10 -0
- package/dist/rational/rational-decimal-precision.d.ts.map +1 -0
- package/dist/rational/rational-decimal-precision.js +18 -0
- package/dist/rational/rational-decimal-precision.js.map +1 -0
- package/dist/rational/rational-div.d.ts +8 -0
- package/dist/rational/rational-div.d.ts.map +1 -0
- package/dist/rational/rational-div.js +11 -0
- package/dist/rational/rational-div.js.map +1 -0
- package/dist/rational/rational-format.d.ts +21 -0
- package/dist/rational/rational-format.d.ts.map +1 -0
- package/dist/rational/rational-format.js +36 -0
- package/dist/rational/rational-format.js.map +1 -0
- package/dist/rational/rational-fractional-precision.d.ts +16 -0
- package/dist/rational/rational-fractional-precision.d.ts.map +1 -0
- package/dist/rational/rational-fractional-precision.js +37 -0
- package/dist/rational/rational-fractional-precision.js.map +1 -0
- package/dist/rational/rational-from-number.d.ts +10 -0
- package/dist/rational/rational-from-number.d.ts.map +1 -0
- package/dist/rational/rational-from-number.js +51 -0
- package/dist/rational/rational-from-number.js.map +1 -0
- package/dist/rational/rational-integral-fractional.d.ts +10 -0
- package/dist/rational/rational-integral-fractional.d.ts.map +1 -0
- package/dist/rational/rational-integral-fractional.js +16 -0
- package/dist/rational/rational-integral-fractional.js.map +1 -0
- package/dist/rational/rational-inv.d.ts +8 -0
- package/dist/rational/rational-inv.d.ts.map +1 -0
- package/dist/rational/rational-inv.js +23 -0
- package/dist/rational/rational-inv.js.map +1 -0
- package/dist/rational/rational-is-equal.d.ts +4 -0
- package/dist/rational/rational-is-equal.d.ts.map +1 -0
- package/dist/rational/rational-is-equal.js +6 -0
- package/dist/rational/rational-is-equal.js.map +1 -0
- package/dist/rational/rational-mul.d.ts +9 -0
- package/dist/rational/rational-mul.d.ts.map +1 -0
- package/dist/rational/rational-mul.js +24 -0
- package/dist/rational/rational-mul.js.map +1 -0
- package/dist/rational/rational-neg.d.ts +4 -0
- package/dist/rational/rational-neg.d.ts.map +1 -0
- package/dist/rational/rational-neg.js +5 -0
- package/dist/rational/rational-neg.js.map +1 -0
- package/dist/rational/rational-normalize.d.ts +13 -0
- package/dist/rational/rational-normalize.d.ts.map +1 -0
- package/dist/rational/rational-normalize.js +24 -0
- package/dist/rational/rational-normalize.js.map +1 -0
- package/dist/rational/rational-reduce.d.ts +4 -0
- package/dist/rational/rational-reduce.d.ts.map +1 -0
- package/dist/rational/rational-reduce.js +17 -0
- package/dist/rational/rational-reduce.js.map +1 -0
- package/dist/rational/rational-sign.d.ts +5 -0
- package/dist/rational/rational-sign.d.ts.map +1 -0
- package/dist/rational/rational-sign.js +8 -0
- package/dist/rational/rational-sign.js.map +1 -0
- package/dist/rational/rational-sqrt-exact.d.ts +10 -0
- package/dist/rational/rational-sqrt-exact.d.ts.map +1 -0
- package/dist/rational/rational-sqrt-exact.js +22 -0
- package/dist/rational/rational-sqrt-exact.js.map +1 -0
- package/dist/rational/rational-sub.d.ts +4 -0
- package/dist/rational/rational-sub.d.ts.map +1 -0
- package/dist/rational/rational-sub.js +7 -0
- package/dist/rational/rational-sub.js.map +1 -0
- package/dist/rational/rational-to-decimal-string.d.ts +21 -0
- package/dist/rational/rational-to-decimal-string.d.ts.map +1 -0
- package/dist/rational/rational-to-decimal-string.js +39 -0
- package/dist/rational/rational-to-decimal-string.js.map +1 -0
- package/dist/rational/rational-to-number.d.ts +10 -0
- package/dist/rational/rational-to-number.d.ts.map +1 -0
- package/dist/rational/rational-to-number.js +25 -0
- package/dist/rational/rational-to-number.js.map +1 -0
- package/dist/rational/rational-to-string.d.ts +10 -0
- package/dist/rational/rational-to-string.d.ts.map +1 -0
- package/dist/rational/rational-to-string.js +14 -0
- package/dist/rational/rational-to-string.js.map +1 -0
- package/dist/rational/rational-types.d.ts +26 -0
- package/dist/rational/rational-types.d.ts.map +1 -0
- package/dist/rational/rational-types.js +13 -0
- package/dist/rational/rational-types.js.map +1 -0
- package/dist/refill-locale-skeleton.d.ts +25 -0
- package/dist/refill-locale-skeleton.d.ts.map +1 -0
- package/dist/refill-locale-skeleton.js +62 -0
- package/dist/refill-locale-skeleton.js.map +1 -0
- package/dist/resolve-locale-skeleton.d.ts +55 -0
- package/dist/resolve-locale-skeleton.d.ts.map +1 -0
- package/dist/resolve-locale-skeleton.js +105 -0
- package/dist/resolve-locale-skeleton.js.map +1 -0
- package/dist/rounding-mode-from-intl.d.ts +15 -0
- package/dist/rounding-mode-from-intl.d.ts.map +1 -0
- package/dist/rounding-mode-from-intl.js +28 -0
- package/dist/rounding-mode-from-intl.js.map +1 -0
- package/dist/rounding-mode.d.ts +48 -0
- package/dist/rounding-mode.d.ts.map +1 -0
- package/dist/rounding-mode.js +6 -0
- package/dist/rounding-mode.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import { bigIntBitLength, bigIntDivFloor, bigIntMod, bigIntParse, bigIntPopCount, bigIntSqrt, compareNaturalAscending, shiftRightUnsigned64, } from "@ac-kit/core";
|
|
2
|
+
import { INTEGRAL_DOMAIN, OrderedBase } from "@ac-kit/math-algebra";
|
|
3
|
+
import { bigIntDigitAt, bigIntDigitCount, bigIntDivmod, bigIntGcd, bigIntIsPrime, bigIntLcm, } from "@ac-kit/math-integer";
|
|
4
|
+
// Type-only, so the value-level cycle stays broken by the ctor registry below.
|
|
5
|
+
import { decimalFromBigInt } from "../decimal/decimal-from-big-int.js";
|
|
6
|
+
import { decimalToExponential } from "../decimal/decimal-to-exponential.js";
|
|
7
|
+
import { decimalToFixed } from "../decimal/decimal-to-fixed.js";
|
|
8
|
+
import { decimalToPrecision } from "../decimal/decimal-to-precision.js";
|
|
9
|
+
import { formatNumeral } from "../format-numeral.js";
|
|
10
|
+
import { registerConverter } from "./_factory.js";
|
|
11
|
+
let _fractionCtor = null;
|
|
12
|
+
/**
|
|
13
|
+
* Registers the `Fraction` constructor for use by `Integer.inv()`, `.div()`,
|
|
14
|
+
* and `.toFraction()`. Called once by the `fraction.ts` module.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export function _registerBigIntFractionCtor(ctor) {
|
|
19
|
+
_fractionCtor = ctor;
|
|
20
|
+
}
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Integer
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
/**
|
|
25
|
+
* An arbitrary-precision integer, wrapping the native `bigint` primitive.
|
|
26
|
+
*
|
|
27
|
+
* Full integer arithmetic, Euclidean division, bitwise operations, GCD/LCM and
|
|
28
|
+
* primality testing. Its algebraic structure is stated as evidence:
|
|
29
|
+
* {@link Integer.ring} and {@link Integer.euclideanDomain}.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const a = Integer.from(12n);
|
|
33
|
+
* const b = Integer.from(8n);
|
|
34
|
+
* a.add(b).format(); // "20"
|
|
35
|
+
* a.gcd(b).format(); // "4"
|
|
36
|
+
* a.inv().format(); // "1/12" (returns a Fraction)
|
|
37
|
+
* Integer.from(7n).isPrime(); // true
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export class Integer extends OrderedBase {
|
|
41
|
+
precisionKind = "arbitrary";
|
|
42
|
+
radix = 10;
|
|
43
|
+
/** @internal Raw bigint value — use `toBigInt()` for external access. */
|
|
44
|
+
#value;
|
|
45
|
+
constructor(value) {
|
|
46
|
+
super();
|
|
47
|
+
this.#value = value;
|
|
48
|
+
}
|
|
49
|
+
// Static constants
|
|
50
|
+
/** Additive identity `0`. */
|
|
51
|
+
static ZERO = new Integer(0n);
|
|
52
|
+
/** Multiplicative identity `1`. */
|
|
53
|
+
static ONE = new Integer(1n);
|
|
54
|
+
/** The integer `2`. */
|
|
55
|
+
static TWO = new Integer(2n);
|
|
56
|
+
/** The integer `10`. */
|
|
57
|
+
static TEN = new Integer(10n);
|
|
58
|
+
/** Unique type tag used by {@link NumFactory} and {@link NumPromote}. */
|
|
59
|
+
static TAG = Symbol("Integer");
|
|
60
|
+
/** ℤ is an integral domain, not a field — only ±1 are invertible. */
|
|
61
|
+
static STRUCTURE = INTEGRAL_DOMAIN;
|
|
62
|
+
/**
|
|
63
|
+
* Format descriptor for arbitrary-precision decimal integers. Radix 10;
|
|
64
|
+
* exponent range is `[0, +∞)` (integers have no fractional part).
|
|
65
|
+
*/
|
|
66
|
+
static FORMAT_INFO = {
|
|
67
|
+
radix: 10,
|
|
68
|
+
minExponent: 0,
|
|
69
|
+
maxExponent: Infinity,
|
|
70
|
+
};
|
|
71
|
+
// Static evidence (typeclass instances)
|
|
72
|
+
/**
|
|
73
|
+
* Evidence that `Integer` forms a [Euclidean
|
|
74
|
+
* domain](https://en.wikipedia.org/wiki/Euclidean_domain).
|
|
75
|
+
*
|
|
76
|
+
* Pass to generic algorithms such as `gcd()` or `lcm()` that accept any
|
|
77
|
+
* Euclidean domain. Because every Euclidean domain is also a ring, this
|
|
78
|
+
* object also satisfies `Ring<Integer>` — see {@link ring}.
|
|
79
|
+
*/
|
|
80
|
+
static euclideanDomain = {
|
|
81
|
+
zero: Integer.ZERO,
|
|
82
|
+
one: Integer.ONE,
|
|
83
|
+
add: (a, b) => a.add(b),
|
|
84
|
+
neg: (a) => a.neg(),
|
|
85
|
+
sub: (a, b) => a.sub(b),
|
|
86
|
+
mul: (a, b) => a.mul(b),
|
|
87
|
+
eq: (a, b) => a.eq(b),
|
|
88
|
+
// Euclidean degree for ℤ is the absolute value.
|
|
89
|
+
degree: (a) => Math.abs(a.valueOf()),
|
|
90
|
+
divmod: (a, b) => a.divmod(b),
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Evidence that `Integer` forms a
|
|
94
|
+
* [ring](https://en.wikipedia.org/wiki/Ring_(mathematics)).
|
|
95
|
+
*
|
|
96
|
+
* Identical to {@link euclideanDomain} — `Integer` satisfies all ring laws.
|
|
97
|
+
* Provided as a convenience alias when only ring operations are needed by the
|
|
98
|
+
* receiving algorithm.
|
|
99
|
+
*/
|
|
100
|
+
static ring = Integer.euclideanDomain;
|
|
101
|
+
// Static factories
|
|
102
|
+
/** Creates a `Integer` from a `bigint`, `number`, or decimal string. */
|
|
103
|
+
static from(value) {
|
|
104
|
+
if (typeof value === "bigint") {
|
|
105
|
+
return new Integer(value);
|
|
106
|
+
}
|
|
107
|
+
if (typeof value === "number") {
|
|
108
|
+
if (!Number.isInteger(value)) {
|
|
109
|
+
throw new RangeError(`Cannot create Integer from non-integer number: ${value}`);
|
|
110
|
+
}
|
|
111
|
+
return new Integer(BigInt(value));
|
|
112
|
+
}
|
|
113
|
+
return new Integer(bigIntParse(value, 10));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Parses a string in any radix from 2 to 36.
|
|
117
|
+
*
|
|
118
|
+
* @throws {SyntaxError} When the string is not a valid integer in the given
|
|
119
|
+
* radix.
|
|
120
|
+
*/
|
|
121
|
+
static parse(s, radix = 10) {
|
|
122
|
+
return new Integer(bigIntParse(s, radix));
|
|
123
|
+
}
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// Raw value access
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
/** Returns the underlying `bigint` value. */
|
|
128
|
+
toBigInt() {
|
|
129
|
+
return this.#value;
|
|
130
|
+
}
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// INum
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
/** The exact numeral, in `radix` when given — every base from 2 to 36. */
|
|
135
|
+
toString(radix) {
|
|
136
|
+
return this.#value.toString(radix);
|
|
137
|
+
}
|
|
138
|
+
format(locales, options) {
|
|
139
|
+
return formatNumeral(this.#value, locales, options);
|
|
140
|
+
}
|
|
141
|
+
/** Fixed-point notation with `fractionDigits` places, all of them zeros. */
|
|
142
|
+
toFixed(fractionDigits = 0) {
|
|
143
|
+
return decimalToFixed(decimalFromBigInt(this.#value), fractionDigits);
|
|
144
|
+
}
|
|
145
|
+
/** Exponential notation, with as many places as asked for. */
|
|
146
|
+
toExponential(fractionDigits) {
|
|
147
|
+
return decimalToExponential(decimalFromBigInt(this.#value), fractionDigits);
|
|
148
|
+
}
|
|
149
|
+
/** `precision` significant digits, in whichever notation reads better. */
|
|
150
|
+
toPrecision(precision) {
|
|
151
|
+
return decimalToPrecision(decimalFromBigInt(this.#value), precision);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns the nearest IEEE 754 double-precision approximation. Lossy for
|
|
155
|
+
* large values.
|
|
156
|
+
*/
|
|
157
|
+
valueOf() {
|
|
158
|
+
return Number(this.#value);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Coerces to a JS primitive. Returns `bigint` for numeric hints, string for
|
|
162
|
+
* string hint.
|
|
163
|
+
*/
|
|
164
|
+
[Symbol.toPrimitive](hint) {
|
|
165
|
+
if (hint === "string")
|
|
166
|
+
return this.toString();
|
|
167
|
+
return this.#value;
|
|
168
|
+
}
|
|
169
|
+
// ---------------------------------------------------------------------------
|
|
170
|
+
// INum — precision queries
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
/** Number of significant decimal digits in `|this|`. Minimum `1` (for zero). */
|
|
173
|
+
get decimalPrecision() {
|
|
174
|
+
return bigIntDigitCount(this.#value);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Number of decimal digits in the integer part of `|this|`. Equal to
|
|
178
|
+
* `decimalPrecision` for all integers (no fractional part).
|
|
179
|
+
*/
|
|
180
|
+
get integralPrecision() {
|
|
181
|
+
return this.decimalPrecision;
|
|
182
|
+
}
|
|
183
|
+
/** Integers have no fractional digits — always `0`. */
|
|
184
|
+
get fractionalPrecision() {
|
|
185
|
+
return 0;
|
|
186
|
+
}
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
// IMultiplicative / IMultiplicative / IMultiplicative (multiplicative)
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
/**
|
|
191
|
+
* Returns `this × other`.
|
|
192
|
+
*
|
|
193
|
+
* `mode` is accepted for interface compatibility with fixed-width integer
|
|
194
|
+
* types but is ignored — `Integer` is arbitrary-precision and never
|
|
195
|
+
* overflows.
|
|
196
|
+
*/
|
|
197
|
+
mul(other, _mode) {
|
|
198
|
+
return new Integer(this.#value * other.#value);
|
|
199
|
+
}
|
|
200
|
+
/** Returns the multiplicative identity `1`. */
|
|
201
|
+
one() {
|
|
202
|
+
return Integer.ONE;
|
|
203
|
+
}
|
|
204
|
+
// ---------------------------------------------------------------------------
|
|
205
|
+
// IAdditive / IAdditive / IAdditiveGroup
|
|
206
|
+
// ---------------------------------------------------------------------------
|
|
207
|
+
/**
|
|
208
|
+
* Returns `this + other`.
|
|
209
|
+
*
|
|
210
|
+
* `mode` is accepted for interface compatibility with fixed-width integer
|
|
211
|
+
* types but is ignored — `Integer` is arbitrary-precision and never
|
|
212
|
+
* overflows.
|
|
213
|
+
*/
|
|
214
|
+
add(other, _mode) {
|
|
215
|
+
return new Integer(this.#value + other.#value);
|
|
216
|
+
}
|
|
217
|
+
/** Returns the additive identity `0`. */
|
|
218
|
+
zero() {
|
|
219
|
+
return Integer.ZERO;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Returns `−this`.
|
|
223
|
+
*
|
|
224
|
+
* `mode` is accepted for interface compatibility with fixed-width integer
|
|
225
|
+
* types but is ignored — `Integer` is arbitrary-precision and never
|
|
226
|
+
* overflows.
|
|
227
|
+
*/
|
|
228
|
+
neg(_mode) {
|
|
229
|
+
return new Integer(-this.#value);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Returns `this − other`.
|
|
233
|
+
*
|
|
234
|
+
* `mode` is accepted for interface compatibility with fixed-width integer
|
|
235
|
+
* types but is ignored.
|
|
236
|
+
*/
|
|
237
|
+
sub(other, _mode) {
|
|
238
|
+
return new Integer(this.#value - other.#value);
|
|
239
|
+
}
|
|
240
|
+
// ---------------------------------------------------------------------------
|
|
241
|
+
// IOrdered
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
/**
|
|
244
|
+
* Three-way comparison.
|
|
245
|
+
*
|
|
246
|
+
* @returns `-1` if `this < other`, `0` if equal, `+1` if `this > other`.
|
|
247
|
+
*/
|
|
248
|
+
cmp(other) {
|
|
249
|
+
return compareNaturalAscending(this.#value, other.#value);
|
|
250
|
+
}
|
|
251
|
+
// ---------------------------------------------------------------------------
|
|
252
|
+
// IEuclidean
|
|
253
|
+
// ---------------------------------------------------------------------------
|
|
254
|
+
/**
|
|
255
|
+
* Floored integer quotient `⌊this / other⌋`. For positive arguments this
|
|
256
|
+
* equals truncated division. For negative arguments, floors toward −∞ so that
|
|
257
|
+
* `mod` is always non-negative.
|
|
258
|
+
*
|
|
259
|
+
* @throws {RangeError} When `other` is zero.
|
|
260
|
+
*/
|
|
261
|
+
intdiv(other) {
|
|
262
|
+
return new Integer(bigIntDivFloor(this.#value, other.#value));
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Non-negative Euclidean remainder: `this − other × intdiv(this, other)`.
|
|
266
|
+
* Satisfies `0 ≤ mod(a, b) < |b|` for all `a` and nonzero `b`.
|
|
267
|
+
*
|
|
268
|
+
* @throws {RangeError} When `other` is zero.
|
|
269
|
+
*/
|
|
270
|
+
mod(other) {
|
|
271
|
+
return new Integer(bigIntMod(this.#value, other.#value));
|
|
272
|
+
}
|
|
273
|
+
// ---------------------------------------------------------------------------
|
|
274
|
+
// IBitwise
|
|
275
|
+
// ---------------------------------------------------------------------------
|
|
276
|
+
/** Returns `this & other` (bitwise AND). */
|
|
277
|
+
bitwiseAnd(other) {
|
|
278
|
+
return new Integer(this.#value & other.#value);
|
|
279
|
+
}
|
|
280
|
+
/** Returns `this | other` (bitwise OR). */
|
|
281
|
+
bitwiseOr(other) {
|
|
282
|
+
return new Integer(this.#value | other.#value);
|
|
283
|
+
}
|
|
284
|
+
/** Returns `this ^ other` (bitwise XOR). */
|
|
285
|
+
bitwiseXor(other) {
|
|
286
|
+
return new Integer(this.#value ^ other.#value);
|
|
287
|
+
}
|
|
288
|
+
/** Returns `~this` (bitwise NOT). In two's complement: `~n = −n − 1`. */
|
|
289
|
+
bitwiseNot() {
|
|
290
|
+
return new Integer(~this.#value);
|
|
291
|
+
}
|
|
292
|
+
/** Returns `this << n`. Equivalent to multiplying by `2ⁿ`. */
|
|
293
|
+
shiftLeft(n) {
|
|
294
|
+
if (n < 0)
|
|
295
|
+
return this.shiftRight(-n);
|
|
296
|
+
return new Integer(this.#value << BigInt(n));
|
|
297
|
+
}
|
|
298
|
+
/** Returns `this >> n` (arithmetic right shift — sign bit preserved). */
|
|
299
|
+
shiftRight(n) {
|
|
300
|
+
if (n < 0)
|
|
301
|
+
return this.shiftLeft(-n);
|
|
302
|
+
return new Integer(this.#value >> BigInt(n));
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Logical (unsigned) right shift `this >>> n`, treating the value as a 64-bit
|
|
306
|
+
* unsigned integer. Fills with zero bits on the left.
|
|
307
|
+
*/
|
|
308
|
+
unsignedShiftRight(n) {
|
|
309
|
+
return new Integer(shiftRightUnsigned64(this.#value, n));
|
|
310
|
+
}
|
|
311
|
+
bitLength() {
|
|
312
|
+
return bigIntBitLength(this.#value);
|
|
313
|
+
}
|
|
314
|
+
popCount() {
|
|
315
|
+
return bigIntPopCount(this.#value);
|
|
316
|
+
}
|
|
317
|
+
// ---------------------------------------------------------------------------
|
|
318
|
+
// Real operations
|
|
319
|
+
// ---------------------------------------------------------------------------
|
|
320
|
+
/**
|
|
321
|
+
* Absolute value `|this|`.
|
|
322
|
+
*
|
|
323
|
+
* Reference: https://en.wikipedia.org/wiki/Absolute_value
|
|
324
|
+
*/
|
|
325
|
+
abs() {
|
|
326
|
+
return this.#value < 0n ? new Integer(-this.#value) : this;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Sign of this integer.
|
|
330
|
+
*
|
|
331
|
+
* @returns `-1`, `0`, or `+1`. Reference:
|
|
332
|
+
* https://en.wikipedia.org/wiki/Sign_(mathematics)
|
|
333
|
+
*/
|
|
334
|
+
sign() {
|
|
335
|
+
if (this.#value < 0n)
|
|
336
|
+
return -1;
|
|
337
|
+
if (this.#value > 0n)
|
|
338
|
+
return 1;
|
|
339
|
+
return 0;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Integer floor square root `⌊√this⌋`.
|
|
343
|
+
*
|
|
344
|
+
* @throws {RangeError} When `this < 0` (square root of a negative integer is
|
|
345
|
+
* not a real number — use a complex type instead). Reference:
|
|
346
|
+
* https://en.wikipedia.org/wiki/Integer_square_root
|
|
347
|
+
*/
|
|
348
|
+
sqrt() {
|
|
349
|
+
return new Integer(bigIntSqrt(this.#value));
|
|
350
|
+
}
|
|
351
|
+
// ---------------------------------------------------------------------------
|
|
352
|
+
// Promotion to Fraction
|
|
353
|
+
// ---------------------------------------------------------------------------
|
|
354
|
+
/**
|
|
355
|
+
* Returns `1 / this` as an exact {@link Fraction} in ℚ.
|
|
356
|
+
*
|
|
357
|
+
* @throws {RangeError} When called on zero.
|
|
358
|
+
*/
|
|
359
|
+
inv() {
|
|
360
|
+
if (this.#value === 0n)
|
|
361
|
+
throw new RangeError("Division by zero");
|
|
362
|
+
return this.#makeFraction(Integer.ONE, this);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Returns `this / other` as an exact {@link Fraction} in ℚ. For the truncating
|
|
366
|
+
* integer quotient, use {@link intdiv}.
|
|
367
|
+
*
|
|
368
|
+
* @throws {RangeError} When `other` is zero.
|
|
369
|
+
*/
|
|
370
|
+
div(other) {
|
|
371
|
+
if (other.#value === 0n)
|
|
372
|
+
throw new RangeError("Division by zero");
|
|
373
|
+
return this.#makeFraction(this, other);
|
|
374
|
+
}
|
|
375
|
+
/** Returns this integer as the fraction `this / 1`. */
|
|
376
|
+
toFraction() {
|
|
377
|
+
return this.#makeFraction(this, Integer.ONE);
|
|
378
|
+
}
|
|
379
|
+
#makeFraction(n, d) {
|
|
380
|
+
if (_fractionCtor === null) {
|
|
381
|
+
throw new Error("Import fraction.ts before calling inv(), div(), or toFraction() on Integer.");
|
|
382
|
+
}
|
|
383
|
+
return _fractionCtor(n, d);
|
|
384
|
+
}
|
|
385
|
+
// ---------------------------------------------------------------------------
|
|
386
|
+
// IIntegerNum (integer utilities)
|
|
387
|
+
// ---------------------------------------------------------------------------
|
|
388
|
+
/**
|
|
389
|
+
* Returns `gcd(this, other)` — the largest integer that divides both. Always
|
|
390
|
+
* non-negative. `gcd(0, 0) = 0`.
|
|
391
|
+
*/
|
|
392
|
+
gcd(other) {
|
|
393
|
+
return new Integer(bigIntGcd(this.#value, other.#value));
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Returns `lcm(this, other)` — the smallest positive integer divisible by
|
|
397
|
+
* both. Returns `0` when either operand is zero.
|
|
398
|
+
*/
|
|
399
|
+
lcm(other) {
|
|
400
|
+
return new Integer(bigIntLcm(this.#value, other.#value));
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Returns `true` if this integer is a prime number (positive, greater than 1,
|
|
404
|
+
* divisible only by 1 and itself). Uses a deterministic Miller–Rabin test.
|
|
405
|
+
*/
|
|
406
|
+
isPrime() {
|
|
407
|
+
return bigIntIsPrime(this.#value < 0n ? -this.#value : this.#value);
|
|
408
|
+
}
|
|
409
|
+
// ---------------------------------------------------------------------------
|
|
410
|
+
// IArbitraryPrecision / IDecimalEncoded
|
|
411
|
+
// ---------------------------------------------------------------------------
|
|
412
|
+
/**
|
|
413
|
+
* Returns the decimal digit at the given `position`. Position `0` is the ones
|
|
414
|
+
* digit, `1` is tens, `2` is hundreds, etc. Negative positions (fractional
|
|
415
|
+
* digits) always return `0` for integers.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```ts
|
|
419
|
+
* Integer.from(1234n).digitAt(0); // → 4
|
|
420
|
+
* Integer.from(1234n).digitAt(3); // → 1
|
|
421
|
+
* Integer.from(1234n).digitAt(4); // → 0
|
|
422
|
+
* Integer.from(1234n).digitAt(-1); // → 0
|
|
423
|
+
* ```;
|
|
424
|
+
*/
|
|
425
|
+
digitAt(position) {
|
|
426
|
+
return bigIntDigitAt(this.#value, position);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Returns the floored quotient and non-negative remainder of `this ÷ other`
|
|
430
|
+
* as a {@link QuotientRemainder} pair.
|
|
431
|
+
*
|
|
432
|
+
* Invariant: `other × q + r = this` and `0 ≤ r < |other|`.
|
|
433
|
+
*
|
|
434
|
+
* @throws {RangeError} When `other` is zero.
|
|
435
|
+
*/
|
|
436
|
+
divmod(other) {
|
|
437
|
+
const { quotient, remainder } = bigIntDivmod(this.#value, other.#value);
|
|
438
|
+
return {
|
|
439
|
+
quotient: new Integer(quotient),
|
|
440
|
+
remainder: new Integer(remainder),
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Returns this integer as an {@link IntegralFractional}. The fractional part
|
|
445
|
+
* `f` is always `0n` because integers have no fraction.
|
|
446
|
+
*/
|
|
447
|
+
toIntegralFractional() {
|
|
448
|
+
const negative = this.#value < 0n;
|
|
449
|
+
return {
|
|
450
|
+
s: negative ? -1 : 1,
|
|
451
|
+
i: negative ? -this.#value : this.#value,
|
|
452
|
+
f: 0n,
|
|
453
|
+
fracDigits: 0,
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
// Register with the converter registry so Integer.from() is available via convert().
|
|
458
|
+
registerConverter(Integer.TAG, (value) => {
|
|
459
|
+
if (typeof value === "bigint" ||
|
|
460
|
+
typeof value === "number" ||
|
|
461
|
+
typeof value === "string") {
|
|
462
|
+
try {
|
|
463
|
+
return Integer.from(value);
|
|
464
|
+
}
|
|
465
|
+
catch {
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return null;
|
|
470
|
+
});
|
|
471
|
+
//# sourceMappingURL=integer-num.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integer-num.js","sourceRoot":"","sources":["../../src/num/integer-num.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EACf,cAAc,EACd,SAAS,EACT,WAAW,EACX,cAAc,EACd,UAAU,EACV,uBAAuB,EACvB,oBAAoB,GACpB,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E,CAAC;SACb,CAAC;IACH,CAAC;CACD;AAED,qFAAqF;AACrF,iBAAiB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE;IACxC,IACC,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,QAAQ,EACxB,CAAC;QACF,IAAI,CAAC;YACJ,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base interface shared by every numeric type in this library.
|
|
3
|
+
*
|
|
4
|
+
* ## The contract, and where it sits
|
|
5
|
+
*
|
|
6
|
+
* A numeric type in `math-numbers` is built in three layers, and this interface
|
|
7
|
+
* belongs to the third.
|
|
8
|
+
*
|
|
9
|
+
* 1. **Storage and arithmetic** — plain data plus free functions: {@link Rational}
|
|
10
|
+
* with `ratAdd`/`ratMul`/…, `IeeeBinaryUnpacked` with `sfAdd`/`sfMul`/…,
|
|
11
|
+
* `bigint` with `bigIntDivmod`/`bigIntGcd`/…. A function appears at this
|
|
12
|
+
* layer only when it does real work. There is no `bigIntAdd(a, b)` returning
|
|
13
|
+
* `a + b`; forwarding to an operator costs a call and earns nothing.
|
|
14
|
+
* 2. **Evidence** — the operations gathered into a record, so a generic algorithm
|
|
15
|
+
* can take the structure as an argument: `Ring<T>`, `Field<T>`,
|
|
16
|
+
* `EuclideanDomain<T>` in `@ac-kit/math-algebra`. This is what `gcd` and the
|
|
17
|
+
* law checks constrain on.
|
|
18
|
+
* 3. **Contract** — the interfaces in this package, and the classes that implement
|
|
19
|
+
* them. A class here is a worthwhile wrapper over a built-in because it
|
|
20
|
+
* carries something the built-in cannot: a uniform contract, a declared
|
|
21
|
+
* {@link AlgebraicStructure}, a precision kind, a radix and a promotion tag.
|
|
22
|
+
* It carries no arithmetic of its own — every method delegates to layer 1.
|
|
23
|
+
*
|
|
24
|
+
* Which algebraic laws a type obeys is **not** stated here. It is data on the
|
|
25
|
+
* concrete type — `static readonly STRUCTURE` — because TypeScript cannot
|
|
26
|
+
* express associativity, and an interface that claims it enforces nothing.
|
|
27
|
+
* `BinaryFp` and `Fraction` both implement {@link IRealNum}; only one of them
|
|
28
|
+
* is a field, and only the structure says so.
|
|
29
|
+
*
|
|
30
|
+
* ## What this interface requires
|
|
31
|
+
*
|
|
32
|
+
* Conversion to string and number, and value-level decimal-digit precision
|
|
33
|
+
* queries.
|
|
34
|
+
*/
|
|
35
|
+
export interface INum {
|
|
36
|
+
/**
|
|
37
|
+
* The canonical numeral for this value, spelled the way the language spells
|
|
38
|
+
* one — `"NaN"`, `"Infinity"`, `"-Infinity"`, `"0"` for either zero — and in
|
|
39
|
+
* `radix` when one is given, exactly as `Number.prototype.toString` does.
|
|
40
|
+
*
|
|
41
|
+
* Locale-neutral and round-trippable, so this is the form to write to a file
|
|
42
|
+
* or a wire. {@link format} is the localized counterpart.
|
|
43
|
+
*
|
|
44
|
+
* @param radix The base, from 2 to 36. Defaults to 10. A type that cannot
|
|
45
|
+
* render a non-decimal radix without a digit budget throws `RangeError`.
|
|
46
|
+
*/
|
|
47
|
+
toString(radix?: number): string;
|
|
48
|
+
/**
|
|
49
|
+
* Fixed-point notation with exactly `fractionDigits` places, padded with
|
|
50
|
+
* zeros where the value has fewer — `Number.prototype.toFixed`, without its
|
|
51
|
+
* cap of 100. A type that can hold more places can show them.
|
|
52
|
+
*/
|
|
53
|
+
toFixed(fractionDigits?: number): string;
|
|
54
|
+
/**
|
|
55
|
+
* Exponential notation: one digit before the point, `fractionDigits` after,
|
|
56
|
+
* and an `e±` exponent. Omitting the count shows as many as the value has,
|
|
57
|
+
* matching `Number.prototype.toExponential`.
|
|
58
|
+
*/
|
|
59
|
+
toExponential(fractionDigits?: number): string;
|
|
60
|
+
/**
|
|
61
|
+
* `precision` significant digits, switching to exponential notation at the
|
|
62
|
+
* same thresholds `Number.prototype.toPrecision` does.
|
|
63
|
+
*/
|
|
64
|
+
toPrecision(precision: number): string;
|
|
65
|
+
/**
|
|
66
|
+
* This value rendered for a human, by `Intl.NumberFormat`.
|
|
67
|
+
*
|
|
68
|
+
* The parameters are `new Intl.NumberFormat(locales, options)`'s own,
|
|
69
|
+
* unchanged — including the default, which is the ambient locale. Ask for
|
|
70
|
+
* `"en-US"` with `useGrouping: false` when the output has to be
|
|
71
|
+
* machine-readable.
|
|
72
|
+
*/
|
|
73
|
+
format(locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions): string;
|
|
74
|
+
/**
|
|
75
|
+
* Returns the nearest IEEE 754 double-precision approximation. May lose
|
|
76
|
+
* precision for values with more than ~15 significant digits.
|
|
77
|
+
*/
|
|
78
|
+
valueOf(): number;
|
|
79
|
+
/**
|
|
80
|
+
* Coerces this value to a JS primitive: - `'number'` → same as `valueOf()` -
|
|
81
|
+
* `'string'` → same as `toString()` - `'default'` → same as `valueOf()`
|
|
82
|
+
*/
|
|
83
|
+
[Symbol.toPrimitive](hint: "number" | "string" | "default"): number | string | bigint;
|
|
84
|
+
/**
|
|
85
|
+
* Total number of significant decimal digits needed to exactly represent this
|
|
86
|
+
* value.
|
|
87
|
+
*
|
|
88
|
+
* Returns `Number.POSITIVE_INFINITY` for values with non-terminating decimal
|
|
89
|
+
* expansions (e.g. `Fraction(1, 3)`, `√2`).
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* Integer.from(12345n).decimalPrecision; // → 5
|
|
94
|
+
* Decimal.from("3.14").decimalPrecision; // → 3
|
|
95
|
+
* Fraction.from(1n, 3n).decimalPrecision; // → Infinity
|
|
96
|
+
* ```;
|
|
97
|
+
*/
|
|
98
|
+
readonly decimalPrecision: number;
|
|
99
|
+
/**
|
|
100
|
+
* Number of decimal digits in the integer (integral) part of `|value|`.
|
|
101
|
+
* Always at least `1` (the digit `0` for values with `|value| < 1`).
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* Integer.from(123n).integralPrecision; // → 3
|
|
106
|
+
* Decimal.from("0.5").integralPrecision; // → 1 (the leading '0')
|
|
107
|
+
* Decimal.from("3.14").integralPrecision; // → 1
|
|
108
|
+
* ```;
|
|
109
|
+
*/
|
|
110
|
+
readonly integralPrecision: number;
|
|
111
|
+
/**
|
|
112
|
+
* Number of decimal digits in the fractional part of `|value|`. `0` for exact
|
|
113
|
+
* integers. Returns `Number.POSITIVE_INFINITY` for non-terminating decimal
|
|
114
|
+
* expansions.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* Integer.from(42n).fractionalPrecision; // → 0
|
|
119
|
+
* Decimal.from("3.14").fractionalPrecision; // → 2
|
|
120
|
+
* Fraction.from(1n, 3n).fractionalPrecision; // → Infinity
|
|
121
|
+
* ```;
|
|
122
|
+
*/
|
|
123
|
+
readonly fractionalPrecision: number;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=inum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inum.d.ts","sourceRoot":"","sources":["../../src/num/inum.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,WAAW,IAAI;IACpB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEjC;;;;OAIG;IACH,OAAO,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzC;;;;OAIG;IACH,aAAa,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAE/C;;;OAGG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAEvC;;;;;;;OAOG;IACH,MAAM,CACL,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,EAC9B,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAChC,MAAM,CAAC;IAEV;;;OAGG;IACH,OAAO,IAAI,MAAM,CAAC;IAElB;;;OAGG;IACH,CAAC,MAAM,CAAC,WAAW,CAAC,CACnB,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GACnC,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAM5B;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAElC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAEnC;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;CACrC"}
|
package/dist/num/inum.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inum.js","sourceRoot":"","sources":["../../src/num/inum.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Behaviour of a fixed-precision type when the exact result of an operation
|
|
3
|
+
* falls outside its representable range.
|
|
4
|
+
*/
|
|
5
|
+
export type OverflowMode =
|
|
6
|
+
/** Two's-complement wrap-around, matching hardware integer arithmetic. */
|
|
7
|
+
"wrap"
|
|
8
|
+
/** Saturate at the minimum or maximum representable value. */
|
|
9
|
+
| "clamp"
|
|
10
|
+
/** Throw {@link OverflowError}. */
|
|
11
|
+
| "abort";
|
|
12
|
+
/** Raised by an operation performed under the `abort` overflow mode. */
|
|
13
|
+
export declare class OverflowError extends RangeError {
|
|
14
|
+
readonly name = "OverflowError";
|
|
15
|
+
constructor(message: string, options?: ErrorOptions);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=overflow-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overflow-mode.d.ts","sourceRoot":"","sources":["../src/overflow-mode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,YAAY;AACvB,0EAA0E;AACxE,MAAM;AACR,8DAA8D;GAC5D,OAAO;AACT,mCAAmC;GACjC,OAAO,CAAC;AAEX,wEAAwE;AACxE,qBAAa,aAAc,SAAQ,UAAU;IAC5C,SAAkB,IAAI,mBAAmB;IAEzC,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAElD;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overflow-mode.js","sourceRoot":"","sources":["../src/overflow-mode.ts"],"names":[],"mappings":"AAYA,wEAAwE;AACxE,MAAM,OAAO,aAAc,SAAQ,UAAU;IAC1B,IAAI,GAAG,eAAe,CAAC;IAEzC,YAAY,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzB,CAAC;CACD"}
|