Boost logo

Boost :

From: Alexander Grund (alexander.grund_at_[hidden])
Date: 2024-01-17 12:56:28


>> Is strtod operating in non-C locale required to correctly parse a number
>> that was formatted using C locale? For example, what if it expects a
>> fractional digits separator other than dot?
> I see your point. I'll open an issue. I believe that strtold will do the wrong thing, and frankly I don't know what strtoflt128 out of <quadmath> does but I assume it's the same.

I was just about to write that: "1.000" is valid in the "C"-locale but
e.g. in a German locale is equal to 1000, not 1.
And I was actually able to come up with a test (I checked where/how to
trigger `std::strto*` and picked a random example):

> #include <locale>
> #include <iostream>
> #include <cassert>
> #include <boost/charconv.hpp>
>
> int main(){
>     const char buffer[] = "1.189731495357231765e+4932";
>     std::locale::global(std::locale("de_DE.UTF-8"));
>     long double v = 0;
>     auto r = boost::charconv::from_chars( buffer,
> buffer+sizeof(buffer), v );
>     assert(r);
>     std::locale::global(std::locale::classic());
>     long double v2 = 0;
>     auto r2 = boost::charconv::from_chars( buffer,
> buffer+sizeof(buffer), v2 );
>     assert(r2);
>
>     std::cerr << v << "==" << v2 << std::endl;
> }

This prints "1==1.18973e+4932", i.e. stops parsing after the first char.
As only decimal points but not thousand separators are accepted it might
be possible to replace the dot by the current locales decimal point as a
workaround. Not sure you can easily get that though.

Alex




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk