STYLE: use std::ostringstream instead of std::to_string for complex

- std::to_string(double) is locale sensitive.
This commit is contained in:
Mark Olesen
2023-01-31 15:55:21 +01:00
parent 1471d292bf
commit 8b63f64503
3 changed files with 10 additions and 2 deletions

View File

@ -44,8 +44,10 @@ Description
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define CAPITALIZE_bool Bool
#define CAPITALIZE_label Label
#define CAPITALIZE_scalar Scalar
#define CAPITALIZE_complex Complex
#define CAPITALIZE_vector Vector
#define CAPITALIZE_sphericalTensor SphericalTensor
#define CAPITALIZE_symmTensor SymmTensor

View File

@ -57,6 +57,7 @@ pTraits<Scalar>::pTraits(Istream& is)
word name(const Scalar val)
{
// Caution std::to_string(double) is locale sensitive!
std::ostringstream buf;
buf << val;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,6 +28,7 @@ License
#include "complex.H"
#include "IOstreams.H"
#include <sstream>
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -69,7 +70,11 @@ Foam::complex::complex(Istream& is)
Foam::word Foam::name(const complex& c)
{
return '(' + std::to_string(c.Re()) + ',' + std::to_string(c.Im()) + ')';
// Caution std::to_string(double) is locale sensitive!
std::ostringstream buf;
buf << '(' << c.real() << ',' << c.imag() << ')';
return word(buf.str(), false); // Needs no stripping
}