@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,76 @@
|
|
|
1
|
+
declare const NAN_SYM: unique symbol;
|
|
2
|
+
declare const POS_INF_SYM: unique symbol;
|
|
3
|
+
declare const NEG_INF_SYM: unique symbol;
|
|
4
|
+
/** The type of the not-a-number sentinel `MATH_NAN`. */
|
|
5
|
+
export type MathNaN = typeof NAN_SYM;
|
|
6
|
+
/** The type of the positive-infinity sentinel `POS_INF`. */
|
|
7
|
+
export type PosInfinity = typeof POS_INF_SYM;
|
|
8
|
+
/** The type of the negative-infinity sentinel `NEG_INF`. */
|
|
9
|
+
export type NegInfinity = typeof NEG_INF_SYM;
|
|
10
|
+
/** A non-finite sentinel: one of `MATH_NAN`, `POS_INF`, or `NEG_INF`. */
|
|
11
|
+
export type SpecialValue = MathNaN | PosInfinity | NegInfinity;
|
|
12
|
+
/**
|
|
13
|
+
* Not-a-number: the result of an indeterminate operation such as `0/0` or
|
|
14
|
+
* `∞−∞`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const MATH_NAN: MathNaN;
|
|
17
|
+
/** Positive infinity: the result of operations such as `x/0` for `x > 0`. */
|
|
18
|
+
export declare const POS_INF: PosInfinity;
|
|
19
|
+
/** Negative infinity: the result of operations such as `x/0` for `x < 0`. */
|
|
20
|
+
export declare const NEG_INF: NegInfinity;
|
|
21
|
+
/** Returns `true` if `v` is any non-finite sentinel (`NaN`, `+∞`, or `−∞`). */
|
|
22
|
+
export declare function isSpecialValue(v: unknown): v is SpecialValue;
|
|
23
|
+
/** Returns `true` if `v` is the not-a-number sentinel. */
|
|
24
|
+
export declare function isMathNaN(v: unknown): v is MathNaN;
|
|
25
|
+
/** Returns `true` if `v` is a positive or negative infinity sentinel. */
|
|
26
|
+
export declare function isInfinity(v: unknown): v is PosInfinity | NegInfinity;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the `SpecialValue` result of an addition when at least one operand is
|
|
29
|
+
* non-finite. `null` represents a finite operand.
|
|
30
|
+
*
|
|
31
|
+
* | a | b | result |
|
|
32
|
+
* | ---- | ---- | ------ |
|
|
33
|
+
* | NaN | * | NaN |
|
|
34
|
+
* | * | NaN | NaN |
|
|
35
|
+
* | +∞ | +∞ | +∞ |
|
|
36
|
+
* | −∞ | −∞ | −∞ |
|
|
37
|
+
* | +∞ | −∞ | NaN |
|
|
38
|
+
* | ±∞ | null | ±∞ |
|
|
39
|
+
* | null | ±∞ | ±∞ |
|
|
40
|
+
*/
|
|
41
|
+
export declare function specialAdd(a: SpecialValue | null, b: SpecialValue | null): SpecialValue;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the `SpecialValue` result of a subtraction when at least one operand
|
|
44
|
+
* is non-finite, derived from {@link specialAdd} by negating `b`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function specialSub(a: SpecialValue | null, b: SpecialValue | null): SpecialValue;
|
|
47
|
+
/**
|
|
48
|
+
* Returns the `SpecialValue` result of a multiplication when at least one
|
|
49
|
+
* operand is non-finite. `null` represents a non-zero finite operand. Pass
|
|
50
|
+
* `MATH_NAN` for an indeterminate operand (`0 × ∞`).
|
|
51
|
+
*
|
|
52
|
+
* | a | b | result (magnitude) |
|
|
53
|
+
* | ---- | ---- | ------------------ |
|
|
54
|
+
* | NaN | * | NaN |
|
|
55
|
+
* | * | NaN | NaN |
|
|
56
|
+
* | +∞ | +∞ | +∞ |
|
|
57
|
+
* | +∞ | −∞ | −∞ |
|
|
58
|
+
* | ∞ | null | ∞ (sign from `a`) |
|
|
59
|
+
* | null | ∞ | ∞ (sign from `b`) |
|
|
60
|
+
*/
|
|
61
|
+
export declare function specialMul(a: SpecialValue | null, b: SpecialValue | null): SpecialValue;
|
|
62
|
+
/**
|
|
63
|
+
* Returns the `SpecialValue` result of a division when at least one operand is
|
|
64
|
+
* non-finite. `null` represents a finite operand. `finite / ∞` equals zero
|
|
65
|
+
* (finite) and does not reach this function.
|
|
66
|
+
*
|
|
67
|
+
* | a | b | result |
|
|
68
|
+
* | --- | ---- | ------ |
|
|
69
|
+
* | NaN | * | NaN |
|
|
70
|
+
* | * | NaN | NaN |
|
|
71
|
+
* | ∞ | ∞ | NaN |
|
|
72
|
+
* | ∞ | null | ∞ |
|
|
73
|
+
*/
|
|
74
|
+
export declare function specialDiv(a: SpecialValue | null, b: SpecialValue | null): SpecialValue;
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=_special-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_special-value.d.ts","sourceRoot":"","sources":["../../src/num/_special-value.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,OAAO,EAAE,OAAO,MAA0B,CAAC;AACjD,QAAA,MAAM,WAAW,EAAE,OAAO,MAA8B,CAAC;AACzD,QAAA,MAAM,WAAW,EAAE,OAAO,MAA8B,CAAC;AAEzD,wDAAwD;AACxD,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC;AACrC,4DAA4D;AAC5D,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC;AAC7C,4DAA4D;AAC5D,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC;AAE7C,yEAAyE;AACzE,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,WAAW,GAAG,WAAW,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,OAAiB,CAAC;AACzC,6EAA6E;AAC7E,eAAO,MAAM,OAAO,EAAE,WAAyB,CAAC;AAChD,6EAA6E;AAC7E,eAAO,MAAM,OAAO,EAAE,WAAyB,CAAC;AAEhD,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,YAAY,CAE5D;AAED,0DAA0D;AAC1D,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,OAAO,CAElD;AAED,yEAAyE;AACzE,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,WAAW,GAAG,WAAW,CAErE;AAKD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CACzB,CAAC,EAAE,YAAY,GAAG,IAAI,EACtB,CAAC,EAAE,YAAY,GAAG,IAAI,GACpB,YAAY,CAMd;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACzB,CAAC,EAAE,YAAY,GAAG,IAAI,EACtB,CAAC,EAAE,YAAY,GAAG,IAAI,GACpB,YAAY,CAMd;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CACzB,CAAC,EAAE,YAAY,GAAG,IAAI,EACtB,CAAC,EAAE,YAAY,GAAG,IAAI,GACpB,YAAY,CAKd;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CACzB,CAAC,EAAE,YAAY,GAAG,IAAI,EACtB,CAAC,EAAE,YAAY,GAAG,IAAI,GACpB,YAAY,CAMd"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Internal module — not exported from numbers/index.ts.
|
|
2
|
+
// Sentinel types and IEEE 754-like arithmetic helpers for the Extended<T> wrapper.
|
|
3
|
+
const NAN_SYM = Symbol("MathNaN");
|
|
4
|
+
const POS_INF_SYM = Symbol("PosInfinity");
|
|
5
|
+
const NEG_INF_SYM = Symbol("NegInfinity");
|
|
6
|
+
/**
|
|
7
|
+
* Not-a-number: the result of an indeterminate operation such as `0/0` or
|
|
8
|
+
* `∞−∞`.
|
|
9
|
+
*/
|
|
10
|
+
export const MATH_NAN = NAN_SYM;
|
|
11
|
+
/** Positive infinity: the result of operations such as `x/0` for `x > 0`. */
|
|
12
|
+
export const POS_INF = POS_INF_SYM;
|
|
13
|
+
/** Negative infinity: the result of operations such as `x/0` for `x < 0`. */
|
|
14
|
+
export const NEG_INF = NEG_INF_SYM;
|
|
15
|
+
/** Returns `true` if `v` is any non-finite sentinel (`NaN`, `+∞`, or `−∞`). */
|
|
16
|
+
export function isSpecialValue(v) {
|
|
17
|
+
return v === MATH_NAN || v === POS_INF || v === NEG_INF;
|
|
18
|
+
}
|
|
19
|
+
/** Returns `true` if `v` is the not-a-number sentinel. */
|
|
20
|
+
export function isMathNaN(v) {
|
|
21
|
+
return v === MATH_NAN;
|
|
22
|
+
}
|
|
23
|
+
/** Returns `true` if `v` is a positive or negative infinity sentinel. */
|
|
24
|
+
export function isInfinity(v) {
|
|
25
|
+
return v === POS_INF || v === NEG_INF;
|
|
26
|
+
}
|
|
27
|
+
// IEEE 754-like arithmetic helpers used by the Extended<T> wrapper.
|
|
28
|
+
// `null` represents a finite, non-zero operand whose exact value is handled externally.
|
|
29
|
+
/**
|
|
30
|
+
* Returns the `SpecialValue` result of an addition when at least one operand is
|
|
31
|
+
* non-finite. `null` represents a finite operand.
|
|
32
|
+
*
|
|
33
|
+
* | a | b | result |
|
|
34
|
+
* | ---- | ---- | ------ |
|
|
35
|
+
* | NaN | * | NaN |
|
|
36
|
+
* | * | NaN | NaN |
|
|
37
|
+
* | +∞ | +∞ | +∞ |
|
|
38
|
+
* | −∞ | −∞ | −∞ |
|
|
39
|
+
* | +∞ | −∞ | NaN |
|
|
40
|
+
* | ±∞ | null | ±∞ |
|
|
41
|
+
* | null | ±∞ | ±∞ |
|
|
42
|
+
*/
|
|
43
|
+
export function specialAdd(a, b) {
|
|
44
|
+
if (a === MATH_NAN || b === MATH_NAN)
|
|
45
|
+
return MATH_NAN;
|
|
46
|
+
if (a === null)
|
|
47
|
+
return b; // finite + ∞ = ∞
|
|
48
|
+
if (b === null)
|
|
49
|
+
return a; // ∞ + finite = ∞
|
|
50
|
+
if (a === b)
|
|
51
|
+
return a; // +∞ + +∞ = +∞, −∞ + −∞ = −∞
|
|
52
|
+
return MATH_NAN; // +∞ + (−∞) = NaN
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the `SpecialValue` result of a subtraction when at least one operand
|
|
56
|
+
* is non-finite, derived from {@link specialAdd} by negating `b`.
|
|
57
|
+
*/
|
|
58
|
+
export function specialSub(a, b) {
|
|
59
|
+
// Negate b: +∞ → −∞, −∞ → +∞, null → null (sign of finite handled by caller)
|
|
60
|
+
const negB = b === POS_INF ? NEG_INF : b === NEG_INF ? POS_INF : b;
|
|
61
|
+
return specialAdd(a, negB);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns the `SpecialValue` result of a multiplication when at least one
|
|
65
|
+
* operand is non-finite. `null` represents a non-zero finite operand. Pass
|
|
66
|
+
* `MATH_NAN` for an indeterminate operand (`0 × ∞`).
|
|
67
|
+
*
|
|
68
|
+
* | a | b | result (magnitude) |
|
|
69
|
+
* | ---- | ---- | ------------------ |
|
|
70
|
+
* | NaN | * | NaN |
|
|
71
|
+
* | * | NaN | NaN |
|
|
72
|
+
* | +∞ | +∞ | +∞ |
|
|
73
|
+
* | +∞ | −∞ | −∞ |
|
|
74
|
+
* | ∞ | null | ∞ (sign from `a`) |
|
|
75
|
+
* | null | ∞ | ∞ (sign from `b`) |
|
|
76
|
+
*/
|
|
77
|
+
export function specialMul(a, b) {
|
|
78
|
+
if (a === MATH_NAN || b === MATH_NAN)
|
|
79
|
+
return MATH_NAN;
|
|
80
|
+
if (a === null)
|
|
81
|
+
return b;
|
|
82
|
+
if (b === null)
|
|
83
|
+
return a;
|
|
84
|
+
return a === b ? POS_INF : NEG_INF;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns the `SpecialValue` result of a division when at least one operand is
|
|
88
|
+
* non-finite. `null` represents a finite operand. `finite / ∞` equals zero
|
|
89
|
+
* (finite) and does not reach this function.
|
|
90
|
+
*
|
|
91
|
+
* | a | b | result |
|
|
92
|
+
* | --- | ---- | ------ |
|
|
93
|
+
* | NaN | * | NaN |
|
|
94
|
+
* | * | NaN | NaN |
|
|
95
|
+
* | ∞ | ∞ | NaN |
|
|
96
|
+
* | ∞ | null | ∞ |
|
|
97
|
+
*/
|
|
98
|
+
export function specialDiv(a, b) {
|
|
99
|
+
if (a === MATH_NAN || b === MATH_NAN)
|
|
100
|
+
return MATH_NAN;
|
|
101
|
+
if (a !== null && b !== null)
|
|
102
|
+
return MATH_NAN; // ∞ / ∞ = NaN
|
|
103
|
+
if (a !== null)
|
|
104
|
+
return a; // ∞ / finite — caller adjusts sign
|
|
105
|
+
// a is null → finite / ∞: callers must not reach here (result is finite zero).
|
|
106
|
+
return MATH_NAN;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=_special-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_special-value.js","sourceRoot":"","sources":["../../src/num/_special-value.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,mFAAmF;AAEnF,MAAM,OAAO,GAAkB,MAAM,CAAC,SAAS,CAAC,CAAC;AACjD,MAAM,WAAW,GAAkB,MAAM,CAAC,aAAa,CAAC,CAAC;AACzD,MAAM,WAAW,GAAkB,MAAM,CAAC,aAAa,CAAC,CAAC;AAYzD;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAY,OAAO,CAAC;AACzC,6EAA6E;AAC7E,MAAM,CAAC,MAAM,OAAO,GAAgB,WAAW,CAAC;AAChD,6EAA6E;AAC7E,MAAM,CAAC,MAAM,OAAO,GAAgB,WAAW,CAAC;AAEhD,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAAC,CAAU;IACxC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,OAAO,CAAC;AACzD,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,SAAS,CAAC,CAAU;IACnC,OAAO,CAAC,KAAK,QAAQ,CAAC;AACvB,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,UAAU,CAAC,CAAU;IACpC,OAAO,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,OAAO,CAAC;AACvC,CAAC;AAED,oEAAoE;AACpE,wFAAwF;AAExF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CACzB,CAAsB,EACtB,CAAsB;IAEtB,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IACtD,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,CAAiB,CAAC,CAAC,iBAAiB;IAC3D,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC,CAAC,iBAAiB;IAC3C,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC,6BAA6B;IACpD,OAAO,QAAQ,CAAC,CAAC,kBAAkB;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CACzB,CAAsB,EACtB,CAAsB;IAEtB,6EAA6E;IAC7E,MAAM,IAAI,GACT,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAEvD,OAAO,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CACzB,CAAsB,EACtB,CAAsB;IAEtB,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IACtD,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,CAAiB,CAAC;IACzC,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC;IACzB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;AACpC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CACzB,CAAsB,EACtB,CAAsB;IAEtB,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IACtD,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,QAAQ,CAAC,CAAC,cAAc;IAC7D,IAAI,CAAC,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC,CAAC,mCAAmC;IAC7D,+EAA+E;IAC/E,OAAO,QAAQ,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Sign } from "@ac-kit/math-algebra";
|
|
2
|
+
import { IeeeBinary } from "../ieee754/binary/ieee-binary-types.js";
|
|
3
|
+
import { IeeeFormat } from "../ieee754/ieee-format.js";
|
|
4
|
+
import { FixedPrecisionInfo, IBinaryEncoded, IFixedPrecision } from "../precision-kind.js";
|
|
5
|
+
import { BinaryFpBase } from "./_binary-fp-base.js";
|
|
6
|
+
import { INum } from "./inum.js";
|
|
7
|
+
/**
|
|
8
|
+
* IEEE 754 binary floating-point number, fully configured at construction by an
|
|
9
|
+
* {@link IeeeFormat} descriptor.
|
|
10
|
+
*
|
|
11
|
+
* **Backing store:** The primary backing is the `IeeeBinaryUnpacked`
|
|
12
|
+
* discriminated union (unpacked sign, biased exponent, `bigint` significand).
|
|
13
|
+
* The packed `Uint32Array` IEEE 754 bit pattern is computed lazily on first
|
|
14
|
+
* access and cached for `bitAt()`, `valueOf()`, and related read operations.
|
|
15
|
+
*
|
|
16
|
+
* **Arithmetic** goes through whichever {@link SoftFloatKernel} is installed.
|
|
17
|
+
* The default is the portable JS one; `createWasmSoftFloatKernel` swaps in the
|
|
18
|
+
* compiled Rust module. Installation is synchronous, so an accelerated build
|
|
19
|
+
* and a portable one have the same API — there is no `await` in front of
|
|
20
|
+
* arithmetic and no second public type to choose between.
|
|
21
|
+
*
|
|
22
|
+
* **Role in the type hierarchy:**
|
|
23
|
+
*
|
|
24
|
+
* - `BinaryFp64` is backed by the native JS `number` (binary64 hardware).
|
|
25
|
+
* - `BinaryFp16` and `BinaryFp32` are backed by a `number`, rounding the result
|
|
26
|
+
* of each operation back to their declared precision.
|
|
27
|
+
* - `BinaryFp128` (and future wide formats) are backed by an instance of this
|
|
28
|
+
* class, configured with the appropriate `Ieee754Parameters`.
|
|
29
|
+
*
|
|
30
|
+
* **Note on `valueOf()`:** it returns a JS `number`, so for a format wider than
|
|
31
|
+
* binary64 the result is a binary64 approximation (≤ ~15 significant decimal
|
|
32
|
+
* digits). The string forms are not: `toString`, `toFixed`, `toExponential` and
|
|
33
|
+
* `toPrecision` all go through the exact decimal expansion, so reach for one of
|
|
34
|
+
* those when the extra precision is the point.
|
|
35
|
+
*
|
|
36
|
+
* References:
|
|
37
|
+
*
|
|
38
|
+
* - IEEE 754-2019: https://en.wikipedia.org/wiki/IEEE_754
|
|
39
|
+
* - Quadruple precision:
|
|
40
|
+
* https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format
|
|
41
|
+
*/
|
|
42
|
+
export declare class BinaryFp extends BinaryFpBase<BinaryFp> implements INum, IFixedPrecision, IBinaryEncoded {
|
|
43
|
+
#private;
|
|
44
|
+
get bitWidth(): number;
|
|
45
|
+
/** IEEE 754 format descriptor */
|
|
46
|
+
readonly ieeeFormat: IeeeFormat;
|
|
47
|
+
/** Unique type tag used by the converter registry. */
|
|
48
|
+
static readonly TAG: unique symbol;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new `BinaryFp` value for the given IEEE 754 format.
|
|
51
|
+
*
|
|
52
|
+
* @param format - Format descriptor (use one of the `IEEE_FORMAT_BINARY*`
|
|
53
|
+
* constants).
|
|
54
|
+
* @param value - Initial value as a JS `number`, parseable string, or an
|
|
55
|
+
* already-decoded `IeeeBinary` (internal use by `_wrapSf`).
|
|
56
|
+
*/
|
|
57
|
+
constructor(format: IeeeFormat, value: number | string | IeeeBinary);
|
|
58
|
+
/** `true` if this value is IEEE 754 NaN. */
|
|
59
|
+
get isNaN(): boolean;
|
|
60
|
+
/** `true` if this value is finite (not NaN and not ±∞). */
|
|
61
|
+
get isFinite(): boolean;
|
|
62
|
+
/** `true` if this value is +∞ or −∞. */
|
|
63
|
+
get isInfinite(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The shortest round-tripping numeral for a format the engine can hold, and
|
|
66
|
+
* the exact expansion for one it cannot — see {@link ieeeBinaryToString}.
|
|
67
|
+
*/
|
|
68
|
+
toString(radix?: number): string;
|
|
69
|
+
toFixed(fractionDigits?: number): string;
|
|
70
|
+
toExponential(fractionDigits?: number): string;
|
|
71
|
+
toPrecision(precision: number): string;
|
|
72
|
+
format(locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions): string;
|
|
73
|
+
/** Returns the value as a JS `number` (binary64 approximation). */
|
|
74
|
+
valueOf(): number;
|
|
75
|
+
/** Coerces to a JS primitive. */
|
|
76
|
+
[Symbol.toPrimitive](hint: "number" | "string" | "default"): number | string | bigint;
|
|
77
|
+
/** Number of significant decimal digits in the binary64 approximation. */
|
|
78
|
+
get decimalPrecision(): number;
|
|
79
|
+
/** Number of decimal digits in the integer part of `|value|`. */
|
|
80
|
+
get integralPrecision(): number;
|
|
81
|
+
/** Number of decimal digits in the fractional part. */
|
|
82
|
+
get fractionalPrecision(): number;
|
|
83
|
+
/** Returns `this × other`. */
|
|
84
|
+
mul(other: BinaryFp): BinaryFp;
|
|
85
|
+
/** Returns the multiplicative identity `1.0`. */
|
|
86
|
+
identity(): BinaryFp;
|
|
87
|
+
/** Returns `this + other`. */
|
|
88
|
+
add(other: BinaryFp): BinaryFp;
|
|
89
|
+
/** Returns the additive identity `0.0`. */
|
|
90
|
+
zero(): BinaryFp;
|
|
91
|
+
/** Returns `−this`. */
|
|
92
|
+
neg(): BinaryFp;
|
|
93
|
+
/** Returns `this − other`. */
|
|
94
|
+
sub(other: BinaryFp): BinaryFp;
|
|
95
|
+
/** Returns `1 / this` (IEEE 754 semantics; ±∞ for zero). */
|
|
96
|
+
inv(): BinaryFp;
|
|
97
|
+
/** Returns `this / other` (IEEE 754 semantics). */
|
|
98
|
+
div(other: BinaryFp): BinaryFp;
|
|
99
|
+
/**
|
|
100
|
+
* Three-way comparison.
|
|
101
|
+
*
|
|
102
|
+
* @throws {RangeError} When either value is NaN.
|
|
103
|
+
*/
|
|
104
|
+
cmp(other: BinaryFp): Sign;
|
|
105
|
+
/** Absolute value `|x|`. */
|
|
106
|
+
abs(): BinaryFp;
|
|
107
|
+
/** Returns −1 for negative, 0 for zero/NaN, +1 for positive. */
|
|
108
|
+
sign(): Sign;
|
|
109
|
+
/** Principal square root `√x`. Returns NaN for negative inputs. */
|
|
110
|
+
sqrt(): BinaryFp;
|
|
111
|
+
/**
|
|
112
|
+
* Fixed-precision format descriptor for this value's IEEE 754 format.
|
|
113
|
+
*
|
|
114
|
+
* The limit values are computed from the format parameters: - `minPositive`:
|
|
115
|
+
* smallest positive normal (`2^emin`) - `maxPositive`: largest finite (`(2 −
|
|
116
|
+
* 2^(1−p)) × 2^emax`)
|
|
117
|
+
*/
|
|
118
|
+
get formatInfo(): FixedPrecisionInfo<BinaryFp>;
|
|
119
|
+
/**
|
|
120
|
+
* Returns the bit at `position` in the packed IEEE 754 bit pattern. Position
|
|
121
|
+
* `0` is the LSB; position `k − 1` is the sign bit.
|
|
122
|
+
*
|
|
123
|
+
* @throws {RangeError} When `position` is outside `[0, k − 1]`.
|
|
124
|
+
*/
|
|
125
|
+
bitAt(position: number): 0 | 1;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Constructs a `BinaryFp` for the given IEEE 754 format.
|
|
129
|
+
*
|
|
130
|
+
* @internal Use `BinaryFp128.from()` etc. in user code.
|
|
131
|
+
*/
|
|
132
|
+
export declare function _newBinaryFp(ieee754: Omit<IeeeFormat, "b"> & {
|
|
133
|
+
b: 2;
|
|
134
|
+
}, value: number | string): BinaryFp;
|
|
135
|
+
//# sourceMappingURL=binary-fp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary-fp.d.ts","sourceRoot":"","sources":["../../src/num/binary-fp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AA0B5C,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAKpE,OAAO,EAAwB,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAO7E,OAAO,EACN,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAMjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBAAa,QACZ,SAAQ,YAAY,CAAC,QAAQ,CAC7B,YAAW,IAAI,EAAE,eAAe,EAAE,cAAc;;IAEhD,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,iCAAiC;IACjC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAQhC,sDAAsD;IACtD,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,MAAM,CAAsB;IAExD;;;;;;;OAOG;IACH,YAAY,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,EAUlE;IAMD,4CAA4C;IAC5C,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,2DAA2D;IAC3D,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,wCAAwC;IACxC,IAAI,UAAU,IAAI,OAAO,CAExB;IAMD;;;OAGG;IACM,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAExC;IAEQ,OAAO,CAAC,cAAc,SAAI,GAAG,MAAM,CAE3C;IAEQ,aAAa,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtD;IAEQ,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE9C;IASQ,MAAM,CACd,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,EAC9B,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAChC,MAAM,CAMR;IAED,mEAAmE;IAC1D,OAAO,IAAI,MAAM,CAEzB;IAED,iCAAiC;IACxB,CAAC,MAAM,CAAC,WAAW,CAAC,CAC5B,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GACnC,MAAM,GAAG,MAAM,GAAG,MAAM,CAG1B;IAMD,0EAA0E;IAC1E,IAAa,gBAAgB,IAAI,MAAM,CAMtC;IAED,iEAAiE;IACjE,IAAa,iBAAiB,IAAI,MAAM,CAMvC;IAED,uDAAuD;IACvD,IAAa,mBAAmB,IAAI,MAAM,CAMzC;IAMD,8BAA8B;IACrB,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAKtC;IAED,iDAAiD;IACxC,QAAQ,IAAI,QAAQ,CAE5B;IAMD,8BAA8B;IACrB,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAKtC;IAED,2CAA2C;IAClC,IAAI,IAAI,QAAQ,CAExB;IAED,uBAAuB;IACd,GAAG,IAAI,QAAQ,CAEvB;IAED,8BAA8B;IACrB,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAKtC;IAMD,4DAA4D;IACnD,GAAG,IAAI,QAAQ,CAEvB;IAED,mDAAmD;IAC1C,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAKtC;IAMD;;;;OAIG;IACM,GAAG,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAElC;IAMD,4BAA4B;IACnB,GAAG,IAAI,QAAQ,CAEvB;IAED,gEAAgE;IACvD,IAAI,IAAI,IAAI,CAEpB;IAED,mEAAmE;IAC1D,IAAI,IAAI,QAAQ,CAKxB;IAMD;;;;;;OAMG;IACH,IAAa,UAAU,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAwCtD;IAMD;;;;;OAKG;IACM,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,GAAG,CAAC,CAUtC;CACD;AAMD;;;;GAIG;AACH,wBAAgB,YAAY,CAC3B,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,GAAG;IAAE,CAAC,EAAE,CAAC,CAAA;CAAE,EACzC,KAAK,EAAE,MAAM,GAAG,MAAM,GACpB,QAAQ,CAEV"}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { decimalFromNumber } from "../decimal/decimal-from-number.js";
|
|
2
|
+
import { decimalFromString } from "../decimal/decimal-from-string.js";
|
|
3
|
+
import { decimalToExponential } from "../decimal/decimal-to-exponential.js";
|
|
4
|
+
import { decimalToFixed } from "../decimal/decimal-to-fixed.js";
|
|
5
|
+
import { decimalToPrecision } from "../decimal/decimal-to-precision.js";
|
|
6
|
+
import { formatNumeral } from "../format-numeral.js";
|
|
7
|
+
import { narrowToBigInt } from "../ieee754/binary/_narrow-to-big-int.js";
|
|
8
|
+
import { packFromBigInt } from "../ieee754/binary/_pack-from-big-int.js";
|
|
9
|
+
import { ieeeBinaryAbs } from "../ieee754/binary/ieee-binary-abs.js";
|
|
10
|
+
import { ieeeBinaryAdd } from "../ieee754/binary/ieee-binary-add.js";
|
|
11
|
+
import { ieeeBinaryCmp } from "../ieee754/binary/ieee-binary-cmp.js";
|
|
12
|
+
import { ieeeBinaryFromDecimal } from "../ieee754/binary/ieee-binary-from-decimal.js";
|
|
13
|
+
import { ieeeBinaryFromNumber } from "../ieee754/binary/ieee-binary-from-number.js";
|
|
14
|
+
import { ieeeBinaryIsFinite } from "../ieee754/binary/ieee-binary-is-finite.js";
|
|
15
|
+
import { ieeeBinaryIsInfinite } from "../ieee754/binary/ieee-binary-is-infinite.js";
|
|
16
|
+
import { ieeeBinaryIsNaN } from "../ieee754/binary/ieee-binary-is-nan.js";
|
|
17
|
+
import { ieeeBinaryNeg } from "../ieee754/binary/ieee-binary-neg.js";
|
|
18
|
+
import { ieeeBinarySign } from "../ieee754/binary/ieee-binary-sign.js";
|
|
19
|
+
import { ieeeBinarySqrt } from "../ieee754/binary/ieee-binary-sqrt.js";
|
|
20
|
+
import { ieeeBinarySub } from "../ieee754/binary/ieee-binary-sub.js";
|
|
21
|
+
import { ieeeBinaryToDecimal } from "../ieee754/binary/ieee-binary-to-decimal.js";
|
|
22
|
+
import { ieeeBinaryToNumber } from "../ieee754/binary/ieee-binary-to-number.js";
|
|
23
|
+
import { ieeeBinaryToString } from "../ieee754/binary/ieee-binary-to-string.js";
|
|
24
|
+
import { ieeeBinaryDiv, ieeeBinaryMul, } from "../ieee754/binary/kernels/kernel.js";
|
|
25
|
+
import { IEEE_FORMAT_BINARY64 } from "../ieee754/ieee-format.js";
|
|
26
|
+
import { integralFractionalFracPrecision, integralFractionalFromNumber, integralFractionalIntegralPrecision, integralFractionalPrecision, } from "../integral-fractional.js";
|
|
27
|
+
import { BinaryFpBase } from "./_binary-fp-base.js";
|
|
28
|
+
import { registerConverter } from "./_factory.js";
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// BinaryFp — IEEE 754 software-float, configured by Ieee754Parameters
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
/**
|
|
33
|
+
* IEEE 754 binary floating-point number, fully configured at construction by an
|
|
34
|
+
* {@link IeeeFormat} descriptor.
|
|
35
|
+
*
|
|
36
|
+
* **Backing store:** The primary backing is the `IeeeBinaryUnpacked`
|
|
37
|
+
* discriminated union (unpacked sign, biased exponent, `bigint` significand).
|
|
38
|
+
* The packed `Uint32Array` IEEE 754 bit pattern is computed lazily on first
|
|
39
|
+
* access and cached for `bitAt()`, `valueOf()`, and related read operations.
|
|
40
|
+
*
|
|
41
|
+
* **Arithmetic** goes through whichever {@link SoftFloatKernel} is installed.
|
|
42
|
+
* The default is the portable JS one; `createWasmSoftFloatKernel` swaps in the
|
|
43
|
+
* compiled Rust module. Installation is synchronous, so an accelerated build
|
|
44
|
+
* and a portable one have the same API — there is no `await` in front of
|
|
45
|
+
* arithmetic and no second public type to choose between.
|
|
46
|
+
*
|
|
47
|
+
* **Role in the type hierarchy:**
|
|
48
|
+
*
|
|
49
|
+
* - `BinaryFp64` is backed by the native JS `number` (binary64 hardware).
|
|
50
|
+
* - `BinaryFp16` and `BinaryFp32` are backed by a `number`, rounding the result
|
|
51
|
+
* of each operation back to their declared precision.
|
|
52
|
+
* - `BinaryFp128` (and future wide formats) are backed by an instance of this
|
|
53
|
+
* class, configured with the appropriate `Ieee754Parameters`.
|
|
54
|
+
*
|
|
55
|
+
* **Note on `valueOf()`:** it returns a JS `number`, so for a format wider than
|
|
56
|
+
* binary64 the result is a binary64 approximation (≤ ~15 significant decimal
|
|
57
|
+
* digits). The string forms are not: `toString`, `toFixed`, `toExponential` and
|
|
58
|
+
* `toPrecision` all go through the exact decimal expansion, so reach for one of
|
|
59
|
+
* those when the extra precision is the point.
|
|
60
|
+
*
|
|
61
|
+
* References:
|
|
62
|
+
*
|
|
63
|
+
* - IEEE 754-2019: https://en.wikipedia.org/wiki/IEEE_754
|
|
64
|
+
* - Quadruple precision:
|
|
65
|
+
* https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format
|
|
66
|
+
*/
|
|
67
|
+
export class BinaryFp extends BinaryFpBase {
|
|
68
|
+
get bitWidth() {
|
|
69
|
+
return this.ieeeFormat.k;
|
|
70
|
+
}
|
|
71
|
+
/** IEEE 754 format descriptor */
|
|
72
|
+
ieeeFormat;
|
|
73
|
+
/**
|
|
74
|
+
* Unpacked soft-float value — primary backing store. All arithmetic
|
|
75
|
+
* operations read and write this field exclusively.
|
|
76
|
+
*/
|
|
77
|
+
#value;
|
|
78
|
+
/** Unique type tag used by the converter registry. */
|
|
79
|
+
static TAG = Symbol("BinaryFp");
|
|
80
|
+
/**
|
|
81
|
+
* Creates a new `BinaryFp` value for the given IEEE 754 format.
|
|
82
|
+
*
|
|
83
|
+
* @param format - Format descriptor (use one of the `IEEE_FORMAT_BINARY*`
|
|
84
|
+
* constants).
|
|
85
|
+
* @param value - Initial value as a JS `number`, parseable string, or an
|
|
86
|
+
* already-decoded `IeeeBinary` (internal use by `_wrapSf`).
|
|
87
|
+
*/
|
|
88
|
+
constructor(format, value) {
|
|
89
|
+
super();
|
|
90
|
+
this.ieeeFormat = format;
|
|
91
|
+
if (typeof value === "object" && value !== null) {
|
|
92
|
+
this.#value = value;
|
|
93
|
+
}
|
|
94
|
+
else if (typeof value === "string") {
|
|
95
|
+
this.#value = ieeeBinaryFromDecimal(decimalFromString(value), format);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this.#value = ieeeBinaryFromNumber(value, format);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// Special-value predicates
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
/** `true` if this value is IEEE 754 NaN. */
|
|
105
|
+
get isNaN() {
|
|
106
|
+
return ieeeBinaryIsNaN(this.#value);
|
|
107
|
+
}
|
|
108
|
+
/** `true` if this value is finite (not NaN and not ±∞). */
|
|
109
|
+
get isFinite() {
|
|
110
|
+
return ieeeBinaryIsFinite(this.#value);
|
|
111
|
+
}
|
|
112
|
+
/** `true` if this value is +∞ or −∞. */
|
|
113
|
+
get isInfinite() {
|
|
114
|
+
return ieeeBinaryIsInfinite(this.#value);
|
|
115
|
+
}
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// INum — format & coercion
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
/**
|
|
120
|
+
* The shortest round-tripping numeral for a format the engine can hold, and
|
|
121
|
+
* the exact expansion for one it cannot — see {@link ieeeBinaryToString}.
|
|
122
|
+
*/
|
|
123
|
+
toString(radix) {
|
|
124
|
+
return ieeeBinaryToString(this.#value, this.ieeeFormat, radix);
|
|
125
|
+
}
|
|
126
|
+
toFixed(fractionDigits = 0) {
|
|
127
|
+
return decimalToFixed(this.#toDecimal(), fractionDigits);
|
|
128
|
+
}
|
|
129
|
+
toExponential(fractionDigits) {
|
|
130
|
+
return decimalToExponential(this.#toDecimal(), fractionDigits);
|
|
131
|
+
}
|
|
132
|
+
toPrecision(precision) {
|
|
133
|
+
return decimalToPrecision(this.#toDecimal(), precision);
|
|
134
|
+
}
|
|
135
|
+
/** The exact decimal, so a wide format is not capped at binary64 first. */
|
|
136
|
+
#toDecimal() {
|
|
137
|
+
return this.#value.kind === "finite"
|
|
138
|
+
? ieeeBinaryToDecimal(this.#value, this.ieeeFormat)
|
|
139
|
+
: decimalFromNumber(ieeeBinaryToNumber(this.#value, this.ieeeFormat));
|
|
140
|
+
}
|
|
141
|
+
format(locales, options) {
|
|
142
|
+
return formatNumeral(this.toString(), locales, options);
|
|
143
|
+
}
|
|
144
|
+
/** Returns the value as a JS `number` (binary64 approximation). */
|
|
145
|
+
valueOf() {
|
|
146
|
+
return ieeeBinaryToNumber(this.#value, this.ieeeFormat);
|
|
147
|
+
}
|
|
148
|
+
/** Coerces to a JS primitive. */
|
|
149
|
+
[Symbol.toPrimitive](hint) {
|
|
150
|
+
if (hint === "string")
|
|
151
|
+
return this.format();
|
|
152
|
+
return ieeeBinaryToNumber(this.#value, this.ieeeFormat);
|
|
153
|
+
}
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
// INum — precision queries
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
/** Number of significant decimal digits in the binary64 approximation. */
|
|
158
|
+
get decimalPrecision() {
|
|
159
|
+
const value = ieeeBinaryToNumber(this.#value, this.ieeeFormat);
|
|
160
|
+
return Number.isFinite(value)
|
|
161
|
+
? integralFractionalPrecision(integralFractionalFromNumber(value))
|
|
162
|
+
: this.ieeeFormat.p;
|
|
163
|
+
}
|
|
164
|
+
/** Number of decimal digits in the integer part of `|value|`. */
|
|
165
|
+
get integralPrecision() {
|
|
166
|
+
const value = ieeeBinaryToNumber(this.#value, this.ieeeFormat);
|
|
167
|
+
return Number.isFinite(value)
|
|
168
|
+
? integralFractionalIntegralPrecision(integralFractionalFromNumber(value))
|
|
169
|
+
: 1;
|
|
170
|
+
}
|
|
171
|
+
/** Number of decimal digits in the fractional part. */
|
|
172
|
+
get fractionalPrecision() {
|
|
173
|
+
const value = ieeeBinaryToNumber(this.#value, this.ieeeFormat);
|
|
174
|
+
return Number.isFinite(value)
|
|
175
|
+
? integralFractionalFracPrecision(integralFractionalFromNumber(value))
|
|
176
|
+
: 0;
|
|
177
|
+
}
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
// IMultiplicative (multiplicative)
|
|
180
|
+
// ---------------------------------------------------------------------------
|
|
181
|
+
/** Returns `this × other`. */
|
|
182
|
+
mul(other) {
|
|
183
|
+
return new BinaryFp(this.ieeeFormat, ieeeBinaryMul(this.#value, other.#value, this.ieeeFormat));
|
|
184
|
+
}
|
|
185
|
+
/** Returns the multiplicative identity `1.0`. */
|
|
186
|
+
identity() {
|
|
187
|
+
return new BinaryFp(this.ieeeFormat, 1);
|
|
188
|
+
}
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
// IAdditiveGroup
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
/** Returns `this + other`. */
|
|
193
|
+
add(other) {
|
|
194
|
+
return new BinaryFp(this.ieeeFormat, ieeeBinaryAdd(this.#value, other.#value, this.ieeeFormat));
|
|
195
|
+
}
|
|
196
|
+
/** Returns the additive identity `0.0`. */
|
|
197
|
+
zero() {
|
|
198
|
+
return new BinaryFp(this.ieeeFormat, 0);
|
|
199
|
+
}
|
|
200
|
+
/** Returns `−this`. */
|
|
201
|
+
neg() {
|
|
202
|
+
return new BinaryFp(this.ieeeFormat, ieeeBinaryNeg(this.#value));
|
|
203
|
+
}
|
|
204
|
+
/** Returns `this − other`. */
|
|
205
|
+
sub(other) {
|
|
206
|
+
return new BinaryFp(this.ieeeFormat, ieeeBinarySub(this.#value, other.#value, this.ieeeFormat));
|
|
207
|
+
}
|
|
208
|
+
// ---------------------------------------------------------------------------
|
|
209
|
+
// IField
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
/** Returns `1 / this` (IEEE 754 semantics; ±∞ for zero). */
|
|
212
|
+
inv() {
|
|
213
|
+
return this.identity().div(this);
|
|
214
|
+
}
|
|
215
|
+
/** Returns `this / other` (IEEE 754 semantics). */
|
|
216
|
+
div(other) {
|
|
217
|
+
return new BinaryFp(this.ieeeFormat, ieeeBinaryDiv(this.#value, other.#value, this.ieeeFormat));
|
|
218
|
+
}
|
|
219
|
+
// ---------------------------------------------------------------------------
|
|
220
|
+
// IOrdered
|
|
221
|
+
// ---------------------------------------------------------------------------
|
|
222
|
+
/**
|
|
223
|
+
* Three-way comparison.
|
|
224
|
+
*
|
|
225
|
+
* @throws {RangeError} When either value is NaN.
|
|
226
|
+
*/
|
|
227
|
+
cmp(other) {
|
|
228
|
+
return ieeeBinaryCmp(this.#value, other.#value);
|
|
229
|
+
}
|
|
230
|
+
// ---------------------------------------------------------------------------
|
|
231
|
+
// Real operations
|
|
232
|
+
// ---------------------------------------------------------------------------
|
|
233
|
+
/** Absolute value `|x|`. */
|
|
234
|
+
abs() {
|
|
235
|
+
return new BinaryFp(this.ieeeFormat, ieeeBinaryAbs(this.#value));
|
|
236
|
+
}
|
|
237
|
+
/** Returns −1 for negative, 0 for zero/NaN, +1 for positive. */
|
|
238
|
+
sign() {
|
|
239
|
+
return ieeeBinarySign(this.#value);
|
|
240
|
+
}
|
|
241
|
+
/** Principal square root `√x`. Returns NaN for negative inputs. */
|
|
242
|
+
sqrt() {
|
|
243
|
+
return new BinaryFp(this.ieeeFormat, ieeeBinarySqrt(this.#value, this.ieeeFormat));
|
|
244
|
+
}
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
// IFixedPrecision
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
/**
|
|
249
|
+
* Fixed-precision format descriptor for this value's IEEE 754 format.
|
|
250
|
+
*
|
|
251
|
+
* The limit values are computed from the format parameters: - `minPositive`:
|
|
252
|
+
* smallest positive normal (`2^emin`) - `maxPositive`: largest finite (`(2 −
|
|
253
|
+
* 2^(1−p)) × 2^emax`)
|
|
254
|
+
*/
|
|
255
|
+
get formatInfo() {
|
|
256
|
+
const { p, emax } = this.ieeeFormat;
|
|
257
|
+
const emin = 1 - emax;
|
|
258
|
+
const format = this.ieeeFormat;
|
|
259
|
+
// Smallest positive normal: sig = 2^(p-1), exp = emin
|
|
260
|
+
const minPosSig = 1n << BigInt(p - 1);
|
|
261
|
+
const minPos = new BinaryFp(format, {
|
|
262
|
+
kind: "finite",
|
|
263
|
+
sign: 0,
|
|
264
|
+
exp: emin,
|
|
265
|
+
sig: minPosSig,
|
|
266
|
+
});
|
|
267
|
+
// Largest finite: sig = 2^p − 1 (all bits set), exp = emax
|
|
268
|
+
const maxPosSig = (1n << BigInt(p)) - 1n;
|
|
269
|
+
const maxPos = new BinaryFp(format, {
|
|
270
|
+
kind: "finite",
|
|
271
|
+
sign: 0,
|
|
272
|
+
exp: emax,
|
|
273
|
+
sig: maxPosSig,
|
|
274
|
+
});
|
|
275
|
+
return {
|
|
276
|
+
minPositive: minPos,
|
|
277
|
+
maxPositive: maxPos,
|
|
278
|
+
minNegative: new BinaryFp(format, {
|
|
279
|
+
kind: "finite",
|
|
280
|
+
sign: 1,
|
|
281
|
+
exp: emax,
|
|
282
|
+
sig: maxPosSig,
|
|
283
|
+
}),
|
|
284
|
+
maxNegative: new BinaryFp(format, {
|
|
285
|
+
kind: "finite",
|
|
286
|
+
sign: 1,
|
|
287
|
+
exp: emin,
|
|
288
|
+
sig: minPosSig,
|
|
289
|
+
}),
|
|
290
|
+
maxDecimalPrecision: Math.floor((format.p - 1) * Math.log10(2)),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
// ---------------------------------------------------------------------------
|
|
294
|
+
// IBinaryEncoded
|
|
295
|
+
// ---------------------------------------------------------------------------
|
|
296
|
+
/**
|
|
297
|
+
* Returns the bit at `position` in the packed IEEE 754 bit pattern. Position
|
|
298
|
+
* `0` is the LSB; position `k − 1` is the sign bit.
|
|
299
|
+
*
|
|
300
|
+
* @throws {RangeError} When `position` is outside `[0, k − 1]`.
|
|
301
|
+
*/
|
|
302
|
+
bitAt(position) {
|
|
303
|
+
const k = this.ieeeFormat.k;
|
|
304
|
+
if (position < 0 || position >= k) {
|
|
305
|
+
throw new RangeError(`bitAt: position ${position} out of range [0, ${k - 1}]`);
|
|
306
|
+
}
|
|
307
|
+
const words = packFromBigInt(narrowToBigInt(this.#value), this.ieeeFormat);
|
|
308
|
+
return ((words[position >>> 5] >>> (position & 31)) & 1);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// ---------------------------------------------------------------------------
|
|
312
|
+
// Package-internal factory
|
|
313
|
+
// ---------------------------------------------------------------------------
|
|
314
|
+
/**
|
|
315
|
+
* Constructs a `BinaryFp` for the given IEEE 754 format.
|
|
316
|
+
*
|
|
317
|
+
* @internal Use `BinaryFp128.from()` etc. in user code.
|
|
318
|
+
*/
|
|
319
|
+
export function _newBinaryFp(ieee754, value) {
|
|
320
|
+
return new BinaryFp(ieee754, value);
|
|
321
|
+
}
|
|
322
|
+
// Register the default BinaryFp (software-float) converter.
|
|
323
|
+
// BinaryFp64 registers its own separate converter under BinaryFp64.TAG.
|
|
324
|
+
registerConverter(BinaryFp.TAG, (value) => {
|
|
325
|
+
if (typeof value === "number" || typeof value === "string") {
|
|
326
|
+
return new BinaryFp(IEEE_FORMAT_BINARY64, value);
|
|
327
|
+
}
|
|
328
|
+
return null;
|
|
329
|
+
});
|
|
330
|
+
//# sourceMappingURL=binary-fp.js.map
|