Skip to content

[dec128] Use 2-tier per-tenth sub-unit chunk constants to reduce ULP + Add from_decimal() method#239

Merged
forfudan merged 6 commits into
mainfrom
dev
May 4, 2026
Merged

[dec128] Use 2-tier per-tenth sub-unit chunk constants to reduce ULP + Add from_decimal() method#239
forfudan merged 6 commits into
mainfrom
dev

Conversation

@forfudan
Copy link
Copy Markdown
Owner

@forfudan forfudan commented May 3, 2026

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 (E0D1E0D9, leveraging existing E0D5) and per-hundredth (E0D01E0D09) exp() chunk constants.
  • Rewrite the x_int < 1 arm of exp() 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.

forfudan and others added 4 commits May 3, 2026 23:55
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (E0D1E0D9, leveraging existing E0D5) and per-hundredth (E0D01E0D09) exp() chunk constants.
  • Rewrite the x_int < 1 arm of exp() 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.

Comment thread src/decimo/decimal128/decimal128.mojo
Comment thread tests/decimal128/test_decimal128_creation.mojo Outdated
forfudan and others added 2 commits May 4, 2026 12:49
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@forfudan forfudan merged commit ce95116 into main May 4, 2026
11 checks passed
@forfudan forfudan deleted the dev branch May 4, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants