Skip to content

Fix underflow rounding for formats without subnormals - #66

Merged
awf merged 1 commit into
graphcore-research:mainfrom
awf:issue-62-fix
Sep 19, 2026
Merged

awf merged 1 commit into
graphcore-research:mainfrom
awf:issue-62-fix

Conversation

@awf

@awf awf commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

round_float and round_ndarray can return values below E8M0's smallest representable value, which subsequently encode as NaN. Clamp finite underflows (including zero) to the smallest magnitude when the target has no zero, preserving sign for signed formats. This applies independently of rounding mode and saturation. This follows CUDA behaviour:
https://docs.nvidia.com/cuda/cuda-math-api/cuda_math_api/group__CUDA__MATH__FP8__MISC.html

For custom formats that have zero but no subnormals, round across the actual gap between zero and the smallest positive value, using the requested rounding mode. Also fix scalar encoding of exact zero in these formats: select its code directly instead of deriving an exponent from zero.

Add regression coverage for all rounding modes, both saturation settings, stochastic endpoints, positive and negative zero, signed custom formats, tiny inputs, mixed/empty arrays, and the strict Array API backend. Check that rounded values belong to the decoded value set and survive encoding/decoding. Document the lower-clamp policy in both rounding APIs.

Fixes #62.

@awf
awf merged commit caea0b1 into graphcore-research:main Sep 19, 2026
3 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.

E8M0 round_float() returns values the format cannot represent

1 participant