google / google/double-conversion

DoubleToStringConverter::ToPrecision has poor (worse than sprintf) performance for a large set of numbers

Open
#83 1 comment 0 reactions 1 assignee Claimed by @floitsch View on GitHub
Dominant language
C++
Stars
1.2k
Forks
308
Avg merge
2d 9h
Merged PRs (30d)
12

Description

The problem lies in DigitGenCounted (in fast-dtoa.cc):
If the fraction is 0 after the first iteration generating the integrals, then the second iteration will be skipped, and less than the requested number of digits (will typically) have been generated, resulting in the method return false, which then leads to a fallback to bignum based conversion.

It's trivial to add a check for the fraction being exactly zero after the first iteration, and then padding with 0 up to the requested number of digits.

What I however can't (yet) answer with 100% certainty is whether this could generate wrong results for some input? (I don't really think so).

The performance issue is seen e.g. for any number in form N*10^M

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.