framework icon indicating copy to clipboard operation
framework copied to clipboard

Unify and improve handling of float point values in 'builtInGetValue()'

Open grospelliergilles opened this issue 11 months ago • 0 comments

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 use std::strtod().
  • for Real2, Real3, Real2x2 and Real3x3 we use std::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 and long double:
    • [x] for Real2: #1918
    • [x] for Real3: #1949
  • use std::from_chars() instead of std::strtod() because it is locale independant : #1911

grospelliergilles avatar Jan 12 '25 10:01 grospelliergilles