Skip to content
Snippets Groups Projects
Commit 64a89e3d authored by Lorenzo Moneta's avatar Lorenzo Moneta
Browse files

Change TMath::Sign for inter types to be a templated T1 Math::Sign(T1, T2)....

Change TMath::Sign for inter types to be a templated T1 Math::Sign(T1, T2). This fixes problem of Sign(1,double(x)) observed in TFormula.
ROOT-7375.
Add also an overload of TMath::Sign for LongDouble
parent 70623a93
No related branches found
No related tags found
No related merge requests found
......@@ -49,13 +49,12 @@ namespace TMath {
inline Bool_t Odd(Long_t a);
// Sign
inline Short_t Sign(Short_t a, Short_t b);
inline Int_t Sign(Int_t a, Int_t b);
inline Long_t Sign(Long_t a, Long_t b);
inline Long64_t Sign(Long64_t a, Long64_t b);
template<typename T1, typename T2>
inline T1 Sign( T1 a, T2 b);
inline Float_t Sign(Float_t a, Float_t b);
inline Double_t Sign(Double_t a, Double_t b);
inline Double_t Sign(LongDouble_t a, LongDouble_t b);
// Min, Max of two scalars
inline Short_t Min(Short_t a, Short_t b);
inline UShort_t Min(UShort_t a, UShort_t b);
......@@ -128,17 +127,9 @@ inline LongDouble_t TMath::Abs(LongDouble_t d)
//---- Sign --------------------------------------------------------------------
inline Short_t TMath::Sign(Short_t a, Short_t b)
{ return (b >= 0) ? Abs(a) : Short_t(-Abs(a)); }
inline Int_t TMath::Sign(Int_t a, Int_t b)
{ return (b >= 0) ? Abs(a) : -Abs(a); }
inline Long_t TMath::Sign(Long_t a, Long_t b)
{ return (b >= 0) ? Abs(a) : -Abs(a); }
inline Long64_t TMath::Sign(Long64_t a, Long64_t b)
{ return (b >= 0) ? Abs(a) : -Abs(a); }
template<typename T1, typename T2>
inline T1 TMath::Sign( T1 a, T2 b)
{ return (b >= 0) ? Abs(a) : -Abs(a); }
inline Float_t TMath::Sign(Float_t a, Float_t b)
{ return std::copysign(a,b); }
......@@ -146,6 +137,10 @@ inline Float_t TMath::Sign(Float_t a, Float_t b)
inline Double_t TMath::Sign(Double_t a, Double_t b)
{ return std::copysign(a,b); }
inline Double_t TMath::Sign(LongDouble_t a, LongDouble_t b)
{ return std::copysign(a,b); }
//---- Min ---------------------------------------------------------------------
inline Short_t TMath::Min(Short_t a, Short_t b)
......
......@@ -425,8 +425,13 @@ bool test26() {
ok &= (f.Eval(2) == 2);
ok &= (f.Eval(-1) == -1);
ok &= (f.Eval(-3) == 3);
TF1 f2("f2","x*TMath::Sign(1,x+2)");
ok &= (f2.Eval(2) == 2);
ok &= (f2.Eval(-1) == -1);
ok &= (f2.Eval(-3) == 3);
return ok;
}
bool test27() {
// test ssq function
bool ok = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment