From c7a27167e2dfcdf62d6c4d096bbbe68a758e7e24 Mon Sep 17 00:00:00 2001 From: Danilo Piparo Date: Fri, 20 Dec 2024 14:14:11 +0100 Subject: [PATCH] [math] Support locales for which the decimal separator is , fixes #17225 --- hist/hist/src/TFormula.cxx | 4 +++- hist/hist/test/test_TFormula.cxx | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/hist/hist/src/TFormula.cxx b/hist/hist/src/TFormula.cxx index 972aed876a9e2..ba0e2cc1ee5b1 100644 --- a/hist/hist/src/TFormula.cxx +++ b/hist/hist/src/TFormula.cxx @@ -2263,7 +2263,9 @@ void TFormula::ProcessFormula(TString &formula) map::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; diff --git a/hist/hist/test/test_TFormula.cxx b/hist/hist/test/test_TFormula.cxx index ca284cee33c21..834505abf447e 100644 --- a/hist/hist/test/test_TFormula.cxx +++ b/hist/hist/test/test_TFormula.cxx @@ -2,8 +2,31 @@ #include "TFormula.h" +#include + +#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()); }