-
Notifications
You must be signed in to change notification settings - Fork 695
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
Textual format: floating-point representation #292
Comments
Some thoughts:
|
I really like the idea of directly encoding the ieee754 bits directly; this aligns with the goal that the text format isn't doing any "interesting" transformations. |
C99 hexadecimal float syntax is great because it also directly corresponds to the value encoding without any "interesting" transformations. And, it splits out the fields (sign bit, significand, exponent) clearly instead of just lumping them all together as opaque bits, so it's even somewhat readable. For example, the bit pattern 0x7fefffffffffffff prints in C99 hexadecimal format as |
I believe LLVM assembly has a combination of those, which makes sense: you want to encode the bits directly for things you can't represent well in text, but that is rare, and you don't want the common case of |
I should have put a decent reference for hexadecimal floating-point. |
Hmm, even |
@kripken LLVM tries to support nice representations and precise ones, which leads to code such as: |
0x1p-1 is much less painful than 0x3fe0000000000000 or any other bit/byte-wise representation :). |
(I should point out when I said "encoding the ieee754 bits directly", I was advocating for a simple, precise, non-decimal representation, not literal sequence of bits; e.g., C99 hex floats sound good.) |
@jfbastien: yes, I agree it takes a little more work to get human-readable numbers. I think it's worth it; it's not that much work. |
It sounds like we have a good consensus for hexadecimal floating-point since it's precise and mildly readable. I just added support for this to LLVM:
|
Canonicalizing nans isn't correct; WebAssembly can have NaN payload values (even though WebAssembly doesn't currently provide NaN bitpattern propagation). If we're going the C99 hexadecimal float route, the obvious thing to do for nan is to let nans have a [+-] prefix and to use the |
@sunfishcode is correct, I've updated LLVM to simply assert on SNaN and NaNs with payloads. It currently handles |
Correction to my last post: the traditional strtod-style Fortunately, the present need here is just to have something to put in SExprs to get some basic things working, not to design what will go in the ultimate text format, so it's best to just do something simple for now. Having LLVM assert on NaN values that can't be represented easily is fine for now. |
Did this issue result in any design doc PRs? I don't see anything in TextFormat.md and this seems like the type of thing we should record. |
Addresses the conclusion reached in #292.
ಠ_ಠ at self for not doing so. Thanks @lukewagner for calling me out on it! :-) |
I'm opening up a can of bikeshed: how should the textual WebAssembly format represent floating-point numbers?
This has nothing to do with the binary format.
Keep in mind:
f32
andf64
.printf
does?nan
NaN
NAN
.±infinity
.infinity
INFINITY
inf
INF
∞
.±0
.f32
orf64
: decimal (e.g.3.141592
) and exponential (e.g.6.022140e23
) often have such non-representable numbers that need to be rounded somehow.A few ideas:
0x7FF8000000000000
is positive NaN with0
bits). This is effectively areinterpret_cast
from integer to floating-point.0x1p1
is 2.0).Or a combination of the above.
The text was updated successfully, but these errors were encountered: