Skip to content

Commit

Permalink
[math] Support locales for which the decimal separator is ,
Browse files Browse the repository at this point in the history
  • Loading branch information
dpiparo committed Dec 20, 2024
1 parent 5cafbe8 commit c7a2716
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion hist/hist/src/TFormula.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,9 @@ void TFormula::ProcessFormula(TString &formula)
map<TString, Double_t>::iterator constIt = fConsts.find(fun.GetName());
if (constIt != fConsts.end()) {
TString pattern = TString::Format("{%s}", fun.GetName());
TString value = TString::Format("%lf", (*constIt).second);
// #17225: we take into account LC_LOCALE settings for which the decimal separator
// is , instead of ., e.g. de_AT.UTF-8
TString value = TString::Format("%lf", (*constIt).second).ReplaceAll(",", ".");
formula.ReplaceAll(pattern, value);
fun.fFound = true;
// std::cout << "constant with name " << fun.GetName() << " is found " << std::endl;
Expand Down
25 changes: 24 additions & 1 deletion hist/hist/test/test_TFormula.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,31 @@

#include "TFormula.h"

#include <locale.h>

#ifdef R__HAS_GEOM
// Test that autoloading works (ROOT-9840)
TEST(TFormula, Interp)
{
TFormula f("func", "TGeoBBox::DeclFileLine()");
TFormula f("func", "TGeoBBox::DeclFileLine()");
}
#endif

class localeRAII {
std::string fLocale;

public:
localeRAII() : fLocale(setlocale(LC_NUMERIC, nullptr)){};
~localeRAII() { setlocale(LC_NUMERIC, fLocale.c_str()); }
};

// #17225
TEST(TFormula, Locale)
{
localeRAII lraii;
setlocale(LC_NUMERIC, "de_AT.UTF-8");
TFormula f0("f0", "gausn(x)");
EXPECT_TRUE(f0.IsValid());
TFormula f1("f1", "landau(x)");
EXPECT_TRUE(f1.IsValid());
}

0 comments on commit c7a2716

Please sign in to comment.