Skip to content
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

Invalid NaN literal #28

Closed
jfbastien opened this issue Jan 28, 2016 · 12 comments
Closed

Invalid NaN literal #28

jfbastien opened this issue Jan 28, 2016 · 12 comments
Assignees

Comments

@jfbastien
Copy link
Member

I'm testing a program which encounters the following sexpr-wasm error:

invalid literal "nan:0x7ff8000000000000"
invalid literal "nan:0x7fc00000"
invalid literal "nan:0x7ff8000000000000"
invalid literal "nan:0x7fc00000"
invalid literal "nan:0x7ff8000000000000"
invalid literal "nan:0x7fc00000"
invalid literal "nan:0x7ff8000000000000"
invalid literal "nan:0x7fc00000"

This was generated by binaryen's s2wasm, and seems to be in line with the spec repo. @binji could you confirm?

/cc @kripken @rossberg-chromium

@binji
Copy link
Member

binji commented Jan 28, 2016

spec repo gives a clearer error (for nan:0x7ff8000000000000):

test6.wast:2.41-2.63: constant out of range: nan payload must not overlap with exponent bits

basically, nan:0x<hexdigits> should only be the nan tag of the float, not its entire bit pattern.

@jfbastien
Copy link
Member Author

Hmm, that's a problem: it's unspecified by IEEE-754 what the NaN encoding means. Encoding the payload makes more sense honestly, but then how do we encode the sign?

We could just fix binaryen, but I'd like us to figure out how exactly.

@ghost
Copy link

ghost commented Jan 28, 2016

When looking at parsing these it did occur that it would be convenient and clear in some contexts to be able to just specify the raw bits. Is there a good reason this is not allowed. For example, change nan:... to raw:... or bits:...

@jfbastien
Copy link
Member Author

Hexadecimal floating-point is the way to go for this... except for NaNs.

@binji
Copy link
Member

binji commented Jan 28, 2016

@jfbastien
Copy link
Member Author

Right, what I mean is that the hexadecimal floating-point specification handles all values precisely, but NaNs aren't a value and they're not handled by hexfloat.

@ghost
Copy link

ghost commented Jan 28, 2016

A producer might not even want to mess with hexfloat, just reliably emit the raw bit, and could do so using the same method as for nan:... It would not seem to complicate the consumer, perhaps even avoid a few tests.

@jfbastien
Copy link
Member Author

@JSStats discussed here: WebAssembly/design#292

@sunfishcode
Copy link
Member

To address one specific detail here: IEEE 754 defines unary negation as a purely bitwise operation with behavior defined even on NaNs: it just sets the sign bit. Consequently, it's reasonably consistent to use -nan... for NaNs with the sign bit set.

@jfbastien
Copy link
Member Author

@sunfishcode ooh cute! I like :)

jfbastien added a commit to WebAssembly/binaryen that referenced this issue Jan 28, 2016
@jfbastien
Copy link
Member Author

See WebAssembly/binaryen#151

@jfbastien
Copy link
Member Author

I'll call this bug fixed by the binaryen PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants