-
Notifications
You must be signed in to change notification settings - Fork 335
Add support for hex float literals #1420
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
Conversation
Fixes gpuweb#709 * Adds literal tokenization to support hex floats
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.
Looks like something that’s just 0x7 would be parsed as a float literal and not an int literal?
This is the hex float part: The exponent suffix is non-optional in this tokenization. The parentheses are matched such that the hex-digit-sequences are a combination that must be preceded by 0x and following by the exponent. Simplifying 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.
Please break FLOAT_LITERAL into two rules.
Discussed in the WGSL meeting of 2021-02-16. Consensus to approve the content of this on the understanding that it reuses C99 syntax. |
* Split FLOAT_LITERAL into DECIMAL_FLOAT_LITERAL and HEX_FLOAT_LITERAL * replace uses of FLOAT_LITERAL with both new tokens
* revert majority of the split of float literal * Add a grammar for FLOAT_LITERAL composed of HEX_FLOAT_LITERAL and DECIMAL_FLOAT_LITERAL
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.
Further fixes are already tracked elsewhere.
Approving as this meets the goal of adding hex float literals.
</thead> | ||
<tr><td>`FLOAT_LITERAL`<td>`(-?[0-9]*.[0-9]+ | -?[0-9]+.[0-9]*)((e|E)(+|-)?[0-9]+)?` | ||
<tr><td>`DECIMAL_FLOAT_LITERAL`<td>`(-?[0-9]*.[0-9]+ | -?[0-9]+.[0-9]*)((e|E)(+|-)?[0-9]+)?` | ||
<tr><td>`HEX_FLOAT_LITERAL`<td>`-?0x([0-9a-fA-F]*.?[0-9a-fA-F]+ | [0-9a-fA-F]+.[0-9a-fA-F]*)(p|P)(+|-)?[0-9]+` |
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.
Comparing to C99 draft (http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf 6.4.42):
-
should allow both 0x and 0X. This worth raising to the group in a new issue. I filed allow both 0x and 0X as hexadecimal literal prefix #1453
-
the significand expression can be simplified to:
([0-9a-fA-F]*.[0-9a-fA-F]+ | [0-9a-fA-F]+.)
In fact, the same simplification can be applied to the decimal float literal.
- C99 doesn't include the leading minus.
The last two points are already tracked in #775
This PR adds unimplemented stubs for the `textureSampleCompareLevel` builtin. Issue gpuweb#1269
Fixes #709