C++ Logo

std-proposals

Advanced search

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

From: Tiago Freire <tmiguelf_at_[hidden]>
Date: Wed, 30 Apr 2025 20:59:10 +0000
In any case there are only 3 main numerical bases that you want to use for floats: decimal, hexadecimal, binary. The algorithms used for those 3 are all different. There's not going to be floating point conversion to a generic base.
I see no point in passing in Ints to represent the digits, that is not going to be efficient. It is just better to pass in a span of individual digits (because that is probably the form that they are going to be in anyway).
This can be done by either having the digits mapped to ASCII (which is form the data will most likely be in anyways) or transcoded to binary digit representation.
 
Just because you can do something, it doesn't always mean it's a good idea, and in this case it is premature pessimization.
The only reason we do this is because humans can't understand binary. So, we have to transform back and forward to a form that monkeys can read with their eyes, that is the problem space.


-----Original Message-----
From: Std-Proposals <std-proposals-bounces_at_[hidden]p.org> On Behalf Of Jan Schultke via Std-Proposals
Sent: Wednesday, April 30, 2025 9:42 PM
To: Zhihao Yuan <zy_at_miator.net>
Cc: Jan Schultke <janschultke_at_[hidden]>; std-proposals_at_lists.isocpp.org
Subject: Re: [std-proposals] Low-level float parsing functions

> We will reference C23 soon, so it is.

There seems to be a misunderstanding here. Just because C++26 is based on C23 doesn't mean that it inherits every language feature from C23.
It just means that the references to the document are updated, which is purely editorial, and that more stuff from the C standard library is acknowledged to exist in C++.

By the same logic, C++ should have compound literals, but I'm not seeing those in C++ despite us being based on C99 for quite some time.

That being said, I am working on getting _BitInt into the C++ standard, but that is a ton of effort.

I also think that _BitInt may be essential to this proposal, unfortunately. It's hard to see how parse_float could be constexpr if it operated on std::span<const std::byte>. This would require reinterpret_cast. On the other hand, _BitInt(128) would be enough mantissa bits even for std::float128_t.
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-04-30 20:59:13