Fix underflow rounding for formats without subnormals - #66
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
round_floatandround_ndarraycan 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.