Date: Tue, 29 Apr 2025 06:23:00 +0200
I feel like if we really wanted to provide a minimalistic interface in the
standard, we could narrow it down to
parse_float(string_view integer, string_view fraction, int exponent = 0);
parse_float_hex(string_view integer, string_view fraction, int exponent =
0);
The exponent can have leading sign symbols, and it's up to the user if
those are optional or not. The exponent is also a small integer, and the
user could have pre-parsed this. It's basically the least challenging part
of parsing floating-point numbers, but the one with the most variations.
That would leave just the integer and fraction part, both of which are pure
digit sequences with no additional characters like radix points or digit
separators. Passing the leading sign character as bool is unnecessary
because for floating-point numbers, it can be parsed separately and
attached to the result afterwards, with no loss of precision.
Anything beyond this is optional then, such as supporting simultaneous
parsing of the exponent, passing in the sign bit, etc.
standard, we could narrow it down to
parse_float(string_view integer, string_view fraction, int exponent = 0);
parse_float_hex(string_view integer, string_view fraction, int exponent =
0);
The exponent can have leading sign symbols, and it's up to the user if
those are optional or not. The exponent is also a small integer, and the
user could have pre-parsed this. It's basically the least challenging part
of parsing floating-point numbers, but the one with the most variations.
That would leave just the integer and fraction part, both of which are pure
digit sequences with no additional characters like radix points or digit
separators. Passing the leading sign character as bool is unnecessary
because for floating-point numbers, it can be parsed separately and
attached to the result afterwards, with no loss of precision.
Anything beyond this is optional then, such as supporting simultaneous
parsing of the exponent, passing in the sign bit, etc.
Received on 2025-04-29 04:23:13