Date: Wed, 30 Apr 2025 11:48:09 +0200
>
> If you have already found the boundaries of the integer part and
> fractional part, represented as sequence of digits, isn't converting those
> digits to integers also easy for the user to do efficiently? Does that part
> belong in the lowest level interface?
The lowest-level interface could be taking byte spans containing the bits
of the integer part and of the fraction. I suppose, the true level zero
function would look like:
parse_float_result
parse_float(std::span<const unsigned char> integer, std::span<const
unsigned char> fraction, int exponent, int base);
If the user is a clever cookie, they can still avoid dynamic allocations in
all cases. There is only a finite window of relevant decimal digits,
shifted by the exponent. Digits to the left of that produce infinity, and
digits to the right are ignored.
I'm not sure if the int base parameter is still needed. It might be needed
because a decimal exponent like E+3 does not directly correspond to any
binary exponent. 100 falls between 64 and 128.
Also note that byte spans are needed because integers may not be large
enough. For example, the architecture may have 128-bit floats, which
require over 30 decimal digits, far more than a 64-bit integer could
provide.
> If you have already found the boundaries of the integer part and
> fractional part, represented as sequence of digits, isn't converting those
> digits to integers also easy for the user to do efficiently? Does that part
> belong in the lowest level interface?
The lowest-level interface could be taking byte spans containing the bits
of the integer part and of the fraction. I suppose, the true level zero
function would look like:
parse_float_result
parse_float(std::span<const unsigned char> integer, std::span<const
unsigned char> fraction, int exponent, int base);
If the user is a clever cookie, they can still avoid dynamic allocations in
all cases. There is only a finite window of relevant decimal digits,
shifted by the exponent. Digits to the left of that produce infinity, and
digits to the right are ignored.
I'm not sure if the int base parameter is still needed. It might be needed
because a decimal exponent like E+3 does not directly correspond to any
binary exponent. 100 falls between 64 and 128.
Also note that byte spans are needed because integers may not be large
enough. For example, the architecture may have 128-bit floats, which
require over 30 decimal digits, far more than a 64-bit integer could
provide.
Received on 2025-04-30 09:48:26