-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add block formats #8
Conversation
src/gfloat/types.py
Outdated
@@ -201,7 +206,12 @@ def min(self) -> float: | |||
""" | |||
The smallest representable number, typically ``-max``. | |||
""" | |||
return -self.max | |||
if self.is_signed: | |||
return -self.max |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this true for format_info_ocp_int8? I can't find a test for it, and it can be asymmetric (max == 1.0 + 63.0 / 64, min == -2.0).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a test that code_of_min
decodes to min
, and code_of_min
is "self-evidently" 2**k-1, so it should be fine, but... I have now added a dense test to this PR which exhaustively enumerates all values and ensures min, max, etc are consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to mention: this PR does include OCP int8, but I let it decode 0x80 as a NaN, which is allowed by [at least one reading of] the spec...
"Integer data types use a 2’s complement encoding, but the maximum negative representation
(−2) may be left unused to maintain symmetry between the maximum positive and negative
representations and avoid introducing a negative bias."
But maybe that is to be read as "0x80 should decode to -2, and downstream users can choose not to use it...."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do it that way, as the spec says "N/A" for NaN, but presumably means "not available" rather than "not applicable".
Add block formats (e.g. OCP MX)
Add OCP E8M0 type. This is an unsigned format, so we add
is_signed
toFormatInfo
.Add OCP INT8 type. This represents the significand as twos-complement, so we add
is_twos_complement
toFormatInfo
.Docs preview at https://gfloat--8.org.readthedocs.build/en/8/