Skip to content

feat(minifier,ecmascript): fold exponentiation with exact results - #30001

Closed
camc314 wants to merge 1 commit into
mainfrom
c/minifier-exact-exponentiation
Closed

camc314 wants to merge 1 commit into
mainfrom
c/minifier-exact-exponentiation

Conversation

@camc314

@camc314 camc314 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

** only folded when both operands were integers, so 4 ** 0.5 and 0.5 ** -2 were kept. Outside its exactly specified cases, Number exponentiation is implementation-approximated, and the evaluator used the host powf, which can disagree with engines: Node evaluates 63.99218702310463 ** 2 to 4095.0000000000005, while powf returned 4095. That is also why #29994 had to skip nested ** in size-based folds.

Example

Input (playground for this example; the playground runs the released Oxc version, so it shows the before output):

use(4 ** 0.5, 0.5 ** -2, 16 ** 0.25, 4 ** 0.5 / 2, 2 ** 0.5, 63.99218702310463 ** 2 / 4095);

Before output (cargo run -p oxc_minifier --example minifier -- input.js --nospace, 66 bytes):

use(4**.5,.5**-2,16**.25,4**.5/2,2**.5,63.99218702310463**2/4095);

After output (same command, 45 bytes):

use(2,4,2,1,2**.5,63.99218702310463**2/4095);

2 ** 0.5 and 63.99218702310463 ** 2 are kept because their results are not exact.

  • The evaluator still uses powf for the exactly specified cases (NaN, infinities, zeros, and a negative base with a fractional exponent). Otherwise it computes the result from the operands' binary representation and only returns exact safe integers: fractional exponents need exact square roots (16 ** 0.25), and negative exponents need a power-of-two base (0.5 ** -2).
  • An exactly representable result is returned unchanged by any pow with less than one ulp of error, so the minifier drops its integer-operand guard for ** and counts nested ** in size-based folds again.
  • Overflowing and underflowing results in the approximated range, such as 10 ** 400, are no longer evaluated.

@camc314
camc314 requested a review from Dunqing as a code owner November 22, 2026 17:14
Copilot AI balanced review requested due to automatic review settings November 22, 2026 17:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T17:18:20.124169Z 41647fc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added A-minifier Area - Minification, compression and name mangling, oxc_minifier / oxc_mangler A-ecmascript Area - ECMAScript spec operations, oxc_ecmascript labels Nov 22, 2026
@camc314 camc314 closed this Nov 22, 2026
@codspeed

codspeed Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 91 untouched benchmarks
⏩ 19 skipped benchmarks1


Comparing c/minifier-exact-exponentiation (41647fc) with main (5f51bd3)

Open in CodSpeed

Footnotes

  1. 19 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

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

Labels

A-ecmascript Area - ECMAScript spec operations, oxc_ecmascript A-minifier Area - Minification, compression and name mangling, oxc_minifier / oxc_mangler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants