-
Notifications
You must be signed in to change notification settings - Fork 17
Description
With version 3.14 of Arcane and before, the handling of conversion from String
to Real
types (Real
, Real2
, Real3
, Real2x2
and Real3x3
) is done like this:
- for
Real
, we usestd::strtod()
. - for
Real2
,Real3
,Real2x2
andReal3x3
we usestd::istream::operator>>
.
This leads to several inconsistencies because std::istream
and std::strtod()
does not have the same rules for conversions. std::strtod()
allows values like nan
or infinity
and raw floating point values (like 0x43p-2
) but this is not the case for std::istream
. So in Arcane we are allowed to use nan
in a file when we read a Real
but not if we read a Real2
for example.
std::strtod()
also have issues because it is locale dependant. If the default locale is not C
, then the behavior for reading floating point values may change because the decimal separator may change (for example in french it is ',' instead of '.').
So, to have a consistant behavior, we have to do the following:
- use the same mechanism to read all floating point values :
Real
,Real2
,Real3
,Real2x2
,Real3x3
,float
andlong double
: - use
std::from_chars()
instead ofstd::strtod()
because it is locale independant : Usestd::from_chars()
instead ofstd::strtod()
to convert strings to double if C++20 is enabled #1911