microsoft / microsoft/STL

`<xlocnum>`: Consider accumulating all digits when parsing floating-point numbers

Open
#3,666 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

The current approach for parsing floating-point numbers discards some digits when the input is lengthy, because we use a stack-allocated array for recording the text representation. The approach requires carefully handling the last accumulated digit and the discarded digits (see https://github.com/microsoft/STL/issues/3375#issuecomment-1413089553 and https://github.com/microsoft/STL/pull/3364#discussion_r1170192746), and adjustment for the exponent part (see #1582).

It might be nice to accumulate the whole representation (in a dynamically allocated buffer) and then send it to strtof/strtod, which should theoretically avoid the aforementioned complexity (as said by @StephanTLavavej in https://github.com/microsoft/STL/pull/3364#issuecomment-1440939821).

However, there're some bugs in UCRT's strtof/strtod (reported in DevCom-10293606 and DevCom-10345852). If we switch to accumulating the whole representation, then these bugs seem unavoidable. Note that the approach in #3364 gives incomplete workarounds.

On the other hand, using a dynamically allocated buffer might slightly slow down the parsing.

IMO it'd be better to consider switching to the new approach after the bugs of strtof/strtod get fixed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the current floating-point parsing implementation and the referenced discussions in #3375, #1582, and #3364. Verify the reported UCRT strtof/strtod issues before choosing an approach. Done would require resolving whether whole-representation accumulation is safe and implementing a tested solution that preserves all digits without unacceptable parsing regressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.