Re: Fall back to fast_float when C++ stdlib doesn't provide from_chars for floats

2024-08-08 Thread Dimitry Andric
On 8 Aug 2024, at 19:56, Daniel Tameling  wrote:
> 
> On Tue, Aug 06, 2024 at 11:26:26AM +0100, Nuno Teixeira wrote:
>> 
>> As I don't have skills to understand why this fix works, I'd like to have
>> some expert opinion on this fix since I don't know if this will be
>> supported in the future.
> 
> Not an expert, but here is my opinion: the workaround uses the strtod
> function instead of the from_chars function. The latter got added in
> c++17 and the former is still in the latest standard, and I don't
> think it will be removed any time soon. So as long as it is supported
> by upstream, it should be save to use the workaround.
> 
> You might want to raise the issue with toolch...@freebsd.org to get a
> reaction from the real experts. Maybe there is a better solution to
> your problem.

At the moment, from_chars is only implemented for integers, in libc++.
I'm unsure what the reason is for not implementing it for floating point
types.

So for now, just use strtod() or the equivalent.

-Dimitry




Re: Fall back to fast_float when C++ stdlib doesn't provide from_chars for floats

2024-08-08 Thread Daniel Tameling
On Tue, Aug 06, 2024 at 11:26:26AM +0100, Nuno Teixeira wrote:
> 
> As I don't have skills to understand why this fix works, I'd like to have
> some expert opinion on this fix since I don't know if this will be
> supported in the future.

Not an expert, but here is my opinion: the workaround uses the strtod
function instead of the from_chars function. The latter got added in
c++17 and the former is still in the latest standard, and I don't
think it will be removed any time soon. So as long as it is supported
by upstream, it should be save to use the workaround.

You might want to raise the issue with toolch...@freebsd.org to get a
reaction from the real experts. Maybe there is a better solution to
your problem.

--
Best regards,
Daniel



Fall back to fast_float when C++ stdlib doesn't provide from_chars for floats

2024-08-06 Thread Nuno Teixeira
Hello all,

On deskutils/treesheets port, upstream did some updated that broke build.
After investigating it upstream says we are building with an outdated C++
standard lib.

To fix it, I'm using a fall back to fast_float as we see in main PR:

https://github.com/aardappel/treesheets/issues/686

As I don't have skills to understand why this fix works, I'd like to have
some expert opinion on this fix since I don't know if this will be
supported in the furure.

Resuming we added __FreeBSD__ to fall back in code already present:


template T parse_float(string_view sv, const char **end =
nullptr) {
// FIXME: Upgrade compilers for these platforms on CI.
-#if defined(__APPLE__) || defined(__ANDROID__) ||
defined(__EMSCRIPTEN__)
+#if defined(__APPLE__) || defined(__ANDROID__) ||
defined(__EMSCRIPTEN__) || defined(__FreeBSD__)
auto &term = *(char *)(sv.data() + sv.size());
auto orig = term;
term = 0;
auto v = (T)strtod(sv.data(), (char **)end);
term = orig;
return v;
#else
T val = 0;
auto res = from_chars(sv.data(), sv.data() + sv.size(), val);
if (end) *end = res.ptr;
return val;
#endif
}


Commit is
https://cgit.freebsd.org/ports/commit/?id=4ffd449f0cfdbef7d1c78442ad3ea0be9ab12ea3

Thanks,

-- 
Nuno Teixeira
FreeBSD UNIX: Web:  https://FreeBSD.org