Skip to content

Apply RMS exponent without underflowing 2^exp first - #52

Merged
swgiacomelli merged 2 commits into
epic/36-surfaces-bakefrom
cursor/s4-rms-ldexp-03fb
Aug 25, 2026
Merged

swgiacomelli merged 2 commits into
epic/36-surfaces-bakefrom
cursor/s4-rms-ldexp-03fb

Conversation

@swgiacomelli

@swgiacomelli swgiacomelli commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Follow-up to merged #50. Rebased onto epic/36-surfaces-bake after #51 (S5 emit).

Codex P2 on 07c0575: when both BigInt limbs are truncated and the shift difference is -1075, 2.0.powi(exp) underflows to 0 before nf / df can lift the result into the representable subnormal range.

A later P2 on that same helper: multiplying by MIN_POSITIVE first can make a still-normal significand subnormal and round again on the leftover exponent.

Ratio::to_f64 applies 2^exp by taking the remainder while the significand is still normal, then multiplying by 2^-1022 once. That keeps a significand just above 2^-1075 as f64::from_bits(1), and converts the [0, 17] lerp residual to three minimum-subnormal units rather than four.

Proof:

  • nodes and off-knot sample f64::from_bits(0x0c70_0000_0000_0001) at scale f64::from_bits(0x3040_0000_0000_0001) quantize to a zero 2×2, MAX_ERR_LSB = 1, rms_lsb = 2^-1074 (not 0)
  • knots [0, 17], rows [0, 1] / [0, 1], off-knot x = f64::from_bits(0x0088_0000_0000_0000), y = 0.5, value = f64::from_bits(0x0046_9696_9696_9697): residual converts to three minimum-subnormal units, MAX_ERR_LSB = 1, five-sample rms_lsb = f64::from_bits(1) (not 2)

This is the operator RMS path, not the bound. This PR does not add S6–S7 work.

Verification

cargo xtask ci on 798d19b (full profile, not release): all runnable checks PASS; baker line budget 1725 / 1800. SKIP: secret scan (gitleaks not installed). A skip is not a pass. This is not release evidence.

PR base is epic/36-surfaces-bake.

Open in Web Open in Cursor 

@swgiacomelli
swgiacomelli marked this pull request as ready for review August 25, 2026 22:10

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d3c7fe15f8

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/surfaces-bake/src/bound.rs Outdated
cursoragent and others added 2 commits August 25, 2026 18:27
2.0.powi(-1075) is zero even when (nf/df)*2^-1075 is the smallest
subnormal. Apply MIN_POSITIVE in 1022-bit steps so a scaled sample just
above 2^-1075 still publishes rms_lsb = 2^-1074. This is not MAX_ERR_LSB.

Co-authored-by: Steven Giacomelli <swgiacomelli@users.noreply.github.com>
Multiplying by 2^-1022 first can make a still-normal significand
subnormal and round again on the leftover exponent, turning a
three-unit residual into four and the five-sample RMS into two
minimum-subnormal units.

Co-authored-by: Steven Giacomelli <swgiacomelli@users.noreply.github.com>
@swgiacomelli
swgiacomelli force-pushed the cursor/s4-rms-ldexp-03fb branch from 13b0fab to 798d19b Compare August 25, 2026 22:28
@swgiacomelli
swgiacomelli merged commit c4f7aa4 into epic/36-surfaces-bake Aug 25, 2026
1 check passed
@swgiacomelli
swgiacomelli deleted the cursor/s4-rms-ldexp-03fb branch August 25, 2026 22:31
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