C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Low-level float parsing functions

From: Jan Schultke <janschultke_at_[hidden]>
Date: Mon, 28 Apr 2025 21:41:17 +0200
> Is this going far enough? What about thousand separators?
> If your locale has / wants them, you need to parse and reallocate
> even with your "new" interface.

The functionality to parse integral, fractional, and exponent parts is
already embedded in std::from_chars, and we may as well expose it to the
outside. I don't think this is particularly controversial. It would be more
controversial to also add novel support for parsing a digit separator of
choice. I don't see a strong argument in favor or against it, but a very
strong argument to provide a lower-level function in general.

Keep in mind that std::from_chars for integers also draws the line there.
Unlike std::from_chars for floats, it doesn't require you to use
decorations like "0x". It supports any base, but no separators, and that
may be a good point to draw the line.

Also you don't need to reallocate in any case. There is a relatively small
upper limit to how many characters a float could need to be represented
with no loss of information, although it's not easy to determine that upper
bound without pessimizing.

Received on 2025-04-28 19:41:30