Skip to content

Make converting a double/float to a string (or vice-versa) IEEE compliant #11024

@tannergooding

Description

@tannergooding

This tracks essentially all the IEEE 754:2008 requirements:

Positive Zero

  • Produce a recoverable string from Positive Zero
  • Recover a string from Positive Zero

Negative Zero

  • Produce a recoverable string from Negative Zero
  • Recover a string from Negative Zero

Positive Infinity

  • Produce a recoverable string from Positive Infinity
  • Recover a string from Positive Infinity
  • Produce a string matching one of "inf" or "infinity" (case-insensitive) with an optional preceding '+'
  • Recover a string matching one of "inf" or "infinity" (case-insensitive) with an optional preceding '+'

Negative Infinity

  • Produce a recoverable string from Negative Infinity
  • Recover a string from Negative Infinity
  • Produce a string matching one of "-inf" or "-infinity" (case-insensitive)
  • Recover a string matching one of "-inf" or "-infinity" (case-insensitive)

Quiet NaN

  • Produce a recoverable string from quiet NaN
  • Recover a string from quiet NaN
  • Produce a string matching "nan" (case-insensitive), with an optional preceding sign
  • Recover a string matching "nan" (case-insensitive), with an optional preceding sign
  • Optionally, produce and recover quiet NaN which appends the NaN payload

Signalling NaN

  • Produce a recoverable string from signalling NaN
  • Recover a string from signalling NaN (recovery to quiet NaN is allowed)
  • Produce a string matching "nan" or "snan" (case-insensitive), with an optional preceding sign
  • Recover a string matching "snan" (case-insensitive), with an optional preceding sign (recovery to quiet NaN is allowed)
  • Optionally, produce and recover signalling NaN which appends the NaN payload

Finite (non-zero) Numbers

  • Optionally, provide a means to specify the number of digits output
  • Must preserve the sign
  • Round-tripping should behave correctly under the default rounding mode ("tiesToEven")
  • Round-tripping requires M digits, where M=17 for double and M=9 for single
  • The lower limit for significant digits converted should be 1
  • The upper limit H, if any, on significant digits converted must be >= M + 3 (20 for double and 12 for single)
  • Conversions for which more than H digits are requested must be padded with zeros
  • Conversions from a string of more than H digits must be correctly rounded to H digits and then converted

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Runtimebreaking-changeIssue or PR that represents a breaking API or functional change over a previous release.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions