[dec128] Use 2-tier per-tenth sub-unit chunk constants to reduce ULP + Add from_decimal() method#239
Conversation
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves Decimal128.exp() accuracy/performance for sub-unit inputs by introducing a 2-tier fractional range-reduction scheme (per-tenth and per-hundredth chunks), and adds Decimal128.from_decimal(BigDecimal) to quantize high-precision BigDecimal results onto the Decimal128 grid (primarily for benchmark/reference plumbing).
Changes:
- Add per-tenth (
E0D1…E0D9, leveraging existingE0D5) and per-hundredth (E0D01…E0D09)exp()chunk constants. - Rewrite the
x_int < 1arm ofexp()to use 2-tier digit chunking before falling back to a much smaller Taylor-series residual. - Add
Decimal128.from_decimal()plus new creation tests and simplify the BigDecimal reference benchmark to use the new conversion.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/decimal128/test_decimal128_creation.mojo | Adds tests covering Decimal128.from_decimal() round-trip, rounding, and overflow behavior. |
| src/decimo/decimal128/exponential.mojo | Implements 2-tier sub-unit chunking logic in exp() for improved convergence and reduced accumulated error. |
| src/decimo/decimal128/decimal128.mojo | Adds Decimal128.from_decimal(BigDecimal) convenience constructor (string-based conversion). |
| src/decimo/decimal128/constants.mojo | Adds precomputed e^(k/10) and e^(k/100) constants used by the new exp() range reduction. |
| docs/readme_unreleased.md | Updates top-level README copy and adds a concise core-types table. |
| docs/plans/decimal128_enhancement.md | Documents the exp() 2-tier chunking follow-up and updates the open/retired items list. |
| benches/decimal128/mojo/bigdec_ref.mojo | Replaces custom rounding/fit logic with Decimal128.from_decimal() for the reference oracle output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves
Decimal128.exp()accuracy/performance for sub-unit inputs by introducing a 2-tier fractional range-reduction scheme (per-tenth and per-hundredth chunks), and addsDecimal128.from_decimal(BigDecimal)to quantize high-precision BigDecimal results onto the Decimal128 grid (primarily for benchmark/reference plumbing).Changes:
E0D1…E0D9, leveraging existingE0D5) and per-hundredth (E0D01…E0D09)exp()chunk constants.x_int < 1arm ofexp()to use 2-tier digit chunking before falling back to a much smaller Taylor-series residual.Decimal128.from_decimal()plus new creation tests and simplify the BigDecimal reference benchmark to use the new conversion.