Repository navigation
Ignore bits above a microfloat's width - #36
Merged
Merged
Conversation
`reinterpret(Float4_E2M1FN, 0x13)` sets bits above the format's four. Twiddles and lookups masked them, but `show` and `cvt_generic` indexed their tables with the whole byte (BoundsError), and `isnan`, `iszero`, `issubnormal`, `abs`, `nextfloat` and others read them as value bits. Every read now goes through `raw_bits`, which masks to `bitwidth(T)`, and every construction through `from_raw_bits`, so primitive types declared with their real width (Julia 1.14) would change only these two. Generated code is unchanged for valid values. `nextfloat` and `prevfloat` stepped past ±floatmax on types without Inf: into bits above the width (Float6_*), onto the sign bit (Float4_E2M1FN, giving -0.0), or to NaN (the FN types). They now stop there, as they stop at ±Inf on the others. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #36 +/- ##
==========================================
+ Coverage 86.03% 87.04% +1.00%
==========================================
Files 14 14
Lines 659 664 +5
==========================================
+ Hits 567 578 +11
+ Misses 92 86 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
reinterpret(Float4_E2M1FN, 0x13)sets bits above the format's four. Twiddles and table lookups already masked them, but other code read the whole byte:showandcvt_genericindexed the tables generated by@microfloatwith the whole byte, so they threwBoundsError.isnan,iszero,issubnormal,abs,nextfloat,==and others treated those bits as part of the value.Changes
raw_bits(x), which masks tobitwidth(T).reinterpret(Unsigned, x)returns the same.from_raw_bits(T, bits). These two helpers are the only places a later switch to primitive types declared with their real width (Julia 1.14, core: support odd-bit primitive integers, add Core.bitsizeof JuliaLang/julia#61359) would need to change.lane_bitswas the same mask, so it now usesraw_bits.Microfloatdocstring says the bits above the width are ignored. The exception is===, which still compares the whole byte.Behavior change:
nextfloat/prevfloatat ±floatmaxOn formats without Inf, these stepped past ±floatmax:
Float6_*);Float4_E2M1FN, sonextfloat(floatmax)was-0.0);They now stop at ±floatmax, the same way they stop at ±Inf on formats that have it. For the FN formats this changes a valid result (it was NaN, now floatmax), matching Base, where
nextfloatnever steps from a finite value to NaN.Testing
test/high_bits.jlcovers every sub-byte type in the suite:nextfloat/prevfloatstop at the ends.🤖 Generated with Claude Code