<charconv>: Can general shortest always use Ryu?
@StephanTLavavej is already working on this.
Since Nov 26, 2019.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
When to_chars() is formatting in general shortest mode, it runs Ryu and then switches between fixed and scientific according to the following criterion:
When scientific is selected, we directly print Ryu's result. When fixed is selected, we run additional code:
When _Can_use_ryu is true, we can use Ryu's result, with a suitably-placed decimal point and zero digits. When _Can_use_ryu is false, we're dealing with a large integer where Ryu rounds away some digits but we need to print all of them exactly, so we activate a fallback algorithm (long division for float, Ryu Printf for double).
When fixed shortest is originally requested, the fallback algorithm is absolutely necessary for some inputs. (The _Max_shifted_mantissa logic is an attempted performance optimization - it precisely detects cases where we can avoid the fallback algorithm. It would be equally correct, but perhaps slower or faster, to activate the fallback algorithm whenever if (_Ryu_exponent > 0) { // case "172900" is true.)
However, when general shortest is originally requested, that's different from unconditionally requesting fixed. I believe that the criterion _Scientific_exponent < 6 implies that we'll never need the fallback algorithm. We need to verify this and adjust the code accordingly.
(Note: plain shortest needs the fallback algorithm because its criterion inspects the Ryu exponent instead of the scientific exponent. For example, the exactly-representable integer 12345678901234567168 is 1.2345678901234567e+19 in scientific shortest. Fixed notation is fewer characters, so plain shortest must use the fallback algorithm for that value.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.