Skip to content

Update the double/single formatter to return the shortest roundtrippable string #11574

@tannergooding

Description

@tannergooding

This was broken out of https://github.com/dotnet/coreclr/issues/19802

Currently we, when using the R specifier, attempt to format to 15 digits, roundtrip back, and if the value does not equal, we reformat to 17 digits and return that value. This has a number of issues, including that it is less performant and is not always correct. The simplest fix is to always roundtrip to 17 digits, but this has the undesired side-effect of returning less user-friendly strings for some numbers.

A more ideal fix would be to instead return the shortest roundtrippable string for a given value. There are several whitepapers on the subject and our current formatting algorithms (Dragon4 and Grisu3) both have sections in their whitepapers that cover this. This provides a good balance between being "correct" and returning "user-friendly" strings.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions