Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

alan-baker
Copy link
Contributor

Fixes #709

  • Adds literal tokenization to support hex floats

Fixes gpuweb#709

* Adds literal tokenization to support hex floats
Copy link
Contributor

@litherum litherum left a 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?

@alan-baker
Copy link
Contributor Author

This is the hex float part:
0x([0-9a-fA-F]*.?[0-9a-fA-F]+ | [0-9a-fA-F]+.[0-9a-fA-F]*)(p|P)(+|-)?[0-9]+

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:
0x(_hex_digit_sequence_)(p|P)(+|-)?[0-9]+

Copy link
Contributor

@dneto0 dneto0 left a 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.

@dneto0
Copy link
Contributor

dneto0 commented Feb 16, 2021

Discussed in the WGSL meeting of 2021-02-16.

Consensus to approve the content of this on the understanding that it reuses C99 syntax.

@dj2 dj2 added the wgsl WebGPU Shading Language Issues label Feb 17, 2021
@dj2 dj2 added this to the MVP milestone Feb 17, 2021
* Split FLOAT_LITERAL into DECIMAL_FLOAT_LITERAL and HEX_FLOAT_LITERAL
  * replace uses of FLOAT_LITERAL with both new tokens
@github-actions
Copy link
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
9f4284f

* revert majority of the split of float literal
* Add a grammar for FLOAT_LITERAL composed of HEX_FLOAT_LITERAL and
  DECIMAL_FLOAT_LITERAL
@github-actions
Copy link
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
c07cab1

Copy link
Contributor

@dneto0 dneto0 left a 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]+`
Copy link
Contributor

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):

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

@dneto0 dneto0 merged commit e6b6d6a into gpuweb:main Feb 20, 2021
ben-clayton pushed a commit to ben-clayton/gpuweb that referenced this pull request Sep 6, 2022
This PR adds unimplemented stubs for the `textureSampleCompareLevel` builtin.

Issue gpuweb#1269
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wgsl WebGPU Shading Language Issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Support C99 hex float literals to accurately capture float values
4 participants