Skip to content

Textual format: floating-point representation #292

@jfbastien

Description

@jfbastien

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:

  • Currently we support f32 and f64.
  • We'll eventually support vectors of these types.
  • Must support NaN properly.
    • Do we support a leading sign?
    • We don't differentiate between different NaN types at the moment. Do we allow n-char-sequence after NaN as printf does?
    • How do we capitalize NaN (if we represent it as text at all)? nan NaN NAN.
  • Must support ±infinity.
    • How do we spell it (if we represent it as text at all)? infinity INFINITY inf INF .
  • Must support ±0.
  • Must support denormals, but that's likely a non-issue.
  • Not all numbers are accurately representable as f32 or f64: decimal (e.g. 3.141592) and exponential (e.g. 6.022140e23) often have such non-representable numbers that need to be rounded somehow.
  • We can support multiple inputs for programmer's convenience, but then we're making the text format parser more complex (which doesn't really matter).

A few ideas:

  • little-endian hexadecimal representation of the IEEE-754 number (e.g. 0x7FF8000000000000 is positive NaN with 0 bits). This is effectively a reinterpret_cast from integer to floating-point.
  • C99 hexadecimal floating-point (e.g. 0x1p1 is 2.0).
  • Precisely-representable decimal and exponential notations only.
  • Any decimal and exponential notation, with a spec-mandated rounding.

Or a combination of the above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions