Skip to content

fix(javascript): underflow tiny float16 magnitudes to signed zero - #4004

Merged
chaokunyang merged 1 commit into
apache:mainfrom
ayush00git:fix/float16-garbage
Aug 31, 2026
Merged

fix(javascript): underflow tiny float16 magnitudes to signed zero#4004
chaokunyang merged 1 commit into
apache:mainfrom
ayush00git:fix/float16-garbage

Conversation

@ayush00git

@ayush00git ayush00git commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Why?

toFloat16Bits shifted the significand by (-1 - exponent) for subnormals; for magnitudes below 2^-32 the shift count reaches 32 and JS masks it with & 31, leaving garbage bits (1e-10 encoded as -15352, 1e-11 as NaN). Underflow values below the smallest float16 subnormal to signed zero.

What does this PR do?

Related issues

AI Contribution Checklist

  • Substantial AI assistance was used in this PR: yes / no
  • If yes, I included a completed AI Contribution Checklist in this PR description and the required AI Usage Disclosure.
  • If yes, my PR description includes the required ai_review summary and screenshot evidence or equivalent persisted links of the final clean AI review results from both fresh reviewers described in AI_POLICY.md, the Fory-guided reviewer and the independent general reviewer, on the current PR diff or current HEAD after the latest code changes.

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

toFloat16Bits shifted the significand by (-1 - exponent) for subnormals;
for magnitudes below 2^-32 the shift count reaches 32 and JS masks it
with & 31, leaving garbage bits (1e-10 encoded as -15352, 1e-11 as NaN).
Underflow values below the smallest float16 subnormal to signed zero.
@ayush00git
ayush00git force-pushed the fix/float16-garbage branch from 6d45e11 to 3c05afc Compare August 30, 2026 17:35

@chaokunyang chaokunyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@chaokunyang
chaokunyang merged commit 05c6914 into apache:main Aug 31, 2026
64 checks passed
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