Skip to content

perf(patch): O(1) fast path for pow(10, n) via lookup table#1

Merged
hassila merged 3 commits intomainfrom
pow10-optimized
Mar 27, 2026
Merged

perf(patch): O(1) fast path for pow(10, n) via lookup table#1
hassila merged 3 commits intomainfrom
pow10-optimized

Conversation

@hassila
Copy link
Copy Markdown
Contributor

@hassila hassila commented Mar 27, 2026

Description

pow(10, n) now uses _pow10Table directly instead of n-1 repeated multiplications through Int128 banker's rounding division. Only triggers for base 10; all other bases use the existing general path unchanged.

How Has This Been Tested?

Benchmark: 1.96 ns (52 instructions) vs 48 ns (613 instructions) for the general path — 25x faster.

Minimal checklist:

  • I have performed a self-review of my own code
  • I have added DocC code-level documentation for any public interfaces exported by the package
  • I have added unit and/or integration tests that prove my fix is effective or that my feature works
    • 5 new tests: positive exponents (0–10), negative exponents (-1 to -8), sub-precision (-9 → zero), overflow (11 → NaN), parity with general path
    • All 554 tests pass

pow(10, n) now uses _pow10Table directly instead of n-1 repeated
multiplications through Int128 banker's rounding division.

Benchmark: 1.96 ns (52 instructions) vs 48 ns (613 instructions)
for the general path — 25x faster.

Adds 5 test cases covering positive/negative exponents, overflow,
sub-precision, and parity with the general path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

Disable number_separator rule and allow underscore in identifier names
to resolve all remaining warnings and errors in Sources/ and Tests/.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hassila hassila changed the title perf: O(1) fast path for pow(10, n) via lookup table perf(patch): O(1) fast path for pow(10, n) via lookup table Mar 27, 2026
@hassila hassila merged commit f33510e into main Mar 27, 2026
9 of 11 checks passed
@hassila hassila deleted the pow10-optimized branch March 27, 2026 10:41
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants