51 template<
typename Integer>
58 template<
typename T1,
typename T2>
100 template <
typename Iterator,
typename Element> Iterator
BinarySearch(Iterator first, Iterator last, Element
value)
104 template <typename Element, typename Index>
105 void Sort(Index n, const Element* a, Index* index, Bool_t down=kTRUE);
106 template <typename Iterator, typename IndexIterator>
107 void SortItr(Iterator first, Iterator last, IndexIterator index, Bool_t down=kTRUE);
111//---- Even/odd ----------------------------------------------------------------
114inline Bool_t TMath::Even(Long_t a)
115 { return ! (a & 1); }
118inline Bool_t TMath::Odd(Long_t a)
121//---- Abs ---------------------------------------------------------------------
124inline Short_t TMath::Abs(Short_t d)
125{ return (d >= 0) ? d : Short_t(-d); }
128inline Int_t TMath::Abs(Int_t d)
129{ return std::abs(d); }
132inline Long_t TMath::Abs(Long_t d)
133{ return std::labs(d); }
136inline Long64_t TMath::Abs(Long64_t d)
137{ return std::llabs(d); }
140inline Float_t TMath::Abs(Float_t d)
141{ return std::abs(d); }
144inline Double_t TMath::Abs(Double_t d)
145{ return std::abs(d); }
148inline LongDouble_t TMath::Abs(LongDouble_t d)
149{ return std::abs(d); }
152//---- Sign Bit--------------------------------------------------------------------
155template<typename Integer>
156inline Bool_t TMath::SignBit( Integer a)
160inline Bool_t TMath::SignBit(Float_t a)
161 { return std::signbit(a); }
164inline Bool_t TMath::SignBit(Double_t a)
165 { return std::signbit(a); }
168inline Bool_t TMath::SignBit(LongDouble_t a)
169 { return std::signbit(a); }
172//---- Sign --------------------------------------------------------------------
175template<typename T1, typename T2>
176inline T1 TMath::Sign( T1 a, T2 b)
177 { return (SignBit(b)) ? - Abs(a) : Abs(a); }
181inline Float_t TMath::Sign(Float_t a, Float_t b)
182 { return std::copysign(a,b); }
186inline Double_t TMath::Sign(Double_t a, Double_t b)
187 { return std::copysign(a,b); }
191inline LongDouble_t TMath::Sign(LongDouble_t a, LongDouble_t b)
192 { return std::copysign(a,b); }
195//---- Min ---------------------------------------------------------------------
199inline Short_t TMath::Min(Short_t a, Short_t b)
200 { return a <= b ? a : b; }
204inline UShort_t TMath::Min(UShort_t a, UShort_t b)
205 { return a <= b ? a : b; }
209inline Int_t TMath::Min(Int_t a, Int_t b)
210 { return a <= b ? a : b; }
214inline UInt_t TMath::Min(UInt_t a, UInt_t b)
215 { return a <= b ? a : b; }
219inline Long_t TMath::Min(Long_t a, Long_t b)
220 { return a <= b ? a : b; }
224inline ULong_t TMath::Min(ULong_t a, ULong_t b)
225 { return a <= b ? a : b; }
229inline Long64_t TMath::Min(Long64_t a, Long64_t b)
230 { return a <= b ? a : b; }
234inline ULong64_t TMath::Min(ULong64_t a, ULong64_t b)
235 { return a <= b ? a : b; }
239inline Float_t TMath::Min(Float_t a, Float_t b)
240 { return a <= b ? a : b; }
244inline Double_t TMath::Min(Double_t a, Double_t b)
245 { return a <= b ? a : b; }
247//---- Max ---------------------------------------------------------------------
251inline Short_t TMath::Max(Short_t a, Short_t b)
252 { return a >= b ? a : b; }
256inline UShort_t TMath::Max(UShort_t a, UShort_t b)
257 { return a >= b ? a : b; }
261inline Int_t TMath::Max(Int_t a, Int_t b)
262 { return a >= b ? a : b; }
266inline UInt_t TMath::Max(UInt_t a, UInt_t b)
267 { return a >= b ? a : b; }
271inline Long_t TMath::Max(Long_t a, Long_t b)
272 { return a >= b ? a : b; }
276inline ULong_t TMath::Max(ULong_t a, ULong_t b)
277 { return a >= b ? a : b; }
281inline Long64_t TMath::Max(Long64_t a, Long64_t b)
282 { return a >= b ? a : b; }
286inline ULong64_t TMath::Max(ULong64_t a, ULong64_t b)
287 { return a >= b ? a : b; }
291inline Float_t TMath::Max(Float_t a, Float_t b)
292 { return a >= b ? a : b; }
296inline Double_t TMath::Max(Double_t a, Double_t b)
297 { return a >= b ? a : b; }
299//---- Range -------------------------------------------------------------------
303inline Short_t TMath::Range(Short_t lb, Short_t ub, Short_t x)
304 { return x < lb ? lb : (x > ub ? ub : x); }
308inline Int_t TMath::Range(Int_t lb, Int_t ub, Int_t x)
309 { return x < lb ? lb : (x > ub ? ub : x); }
313inline Long_t TMath::Range(Long_t lb, Long_t ub, Long_t x)
314 { return x < lb ? lb : (x > ub ? ub : x); }
318inline ULong_t TMath::Range(ULong_t lb, ULong_t ub, ULong_t x)
319 { return x < lb ? lb : (x > ub ? ub : x); }
323inline Double_t TMath::Range(Double_t lb, Double_t ub, Double_t x)
324 { return x < lb ? lb : (x > ub ? ub : x); }
332template <typename Iterator, typename Element>
333Iterator TMath::BinarySearch(Iterator first, Iterator last, Element value)
336 pind = std::lower_bound(first, last, value);
337 if ( (pind != last) && (*pind == value) )
348template <typename T> Long64_t TMath::BinarySearch(Long64_t n, const T *array, T value)
351 pind = std::lower_bound(array, array + n, value);
352 if ( (pind != array + n) && (*pind == value) )
353 return (pind - array);
355 return ( pind - array - 1);
363template <typename T> Long64_t TMath::BinarySearch(Long64_t n, const T **array, T value)
366 pind = std::lower_bound(*array, *array + n, value);
367 if ( (pind != *array + n) && (*pind == value) )
368 return (pind - *array);
370 return ( pind - *array - 1);
376 CompareDesc(T d) : fData(d) {}
378 template<typename Index>
379 bool operator()(Index i1, Index i2) {
380 return *(fData + i1) > *(fData + i2);
389 CompareAsc(T d) : fData(d) {}
391 template<typename Index>
392 bool operator()(Index i1, Index i2) {
393 return *(fData + i1) < *(fData + i2);
406template <typename Iterator, typename IndexIterator>
407void TMath::SortItr(Iterator first, Iterator last, IndexIterator index, Bool_t down)
411 IndexIterator cindex = index;
412 for ( Iterator cfirst = first; cfirst != last; ++cfirst )
419 std::sort(index, cindex, CompareDesc<Iterator>(first) );
421 std::sort(index, cindex, CompareAsc<Iterator>(first) );
432template <typename Element, typename Index> void TMath::Sort(Index n, const Element* a, Index* index, Bool_t down)
434 for(Index i = 0; i < n; i++) { index[i] = i; }
436 std::sort(index, index + n, CompareDesc<const Element*>(a) );
438 std::sort(index, index + n, CompareAsc<const Element*>(a) );
#define R__DEPRECATED(MAJOR, MINOR, REASON)
unsigned long long ULong64_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Long_t NextPrime(Long_t x)
T1 Sign(T1 a, T2 b)
Returns a value with the magnitude of a and the sign of b.
Short_t Range(Short_t lb, Short_t ub, Short_t x)
Returns x if lb < x < up, lb if x < lb and ub if x > ub.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Iterator Undefined behavior in case value is smaller than the first element Use STL algorithms instead
Bool_t Odd(Long_t a)
Returns true if a is odd.
Bool_t SignBit(Integer a)
Returns whether the sign of Integer a is negative.
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Binary search in an array of n values to locate value.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Bool_t Even(Long_t a)
Returns true if a is even.