Skip to content

Consider implementing Grisu3 algorithm for double.ToString() #9122

@mazong1123

Description

@mazong1123

As we have implemented Dragon4 in dotnet/coreclr#12894 , we have a good start to improve the performance of double.ToString().

Although Dragon4 makes current double.ToString() much faster than previous implementation, we could do better. The algorithm Grisu3 introduced in this paper eliminated the big integer arithmetic so that it's much faster than Dragon4. However, not all numbers are applicable for using Grisu3. For those exclusive numbers, we can fall back to Dragon4. Quote from the paper:

As a consequence
Grisu3 is incomplete and will fail for some percentage of its input.
Given 11 extra bits roughly 99.5% are processed correctly and
are thus guaranteed to be optimal (with respect to shortness and
rounding). The remaining 0.5% are rejected and need to be printed
by another printing algorithm (like Dragon4).

Note Google's V8 engine has already adopted this algorithm. @tannergooding @tarekgh @jkotas I'm wondering is it a good timing for diving into this algorithm - I need sometime to do POC for it or in case of any concern from you guys.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions