Logo ROOT   6.14/05
Reference Guide
TMathBase.h
Go to the documentation of this file.
1 // @(#)root/base:
2 // Authors: Rene Brun, Fons Rademakers 29/07/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TMathBase
13 #define ROOT_TMathBase
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TMath Base functions //
19 // //
20 // Define the functions Min, Max, Abs, Sign, Range for all types. //
21 // NB: These functions are unfortunately not available in a portable //
22 // way in std::. //
23 // //
24 // More functions are defined in TMath.h. TMathBase.h is designed to be //
25 // a stable file and used in place of TMath.h in the ROOT miniCore. //
26 // //
27 //////////////////////////////////////////////////////////////////////////
28 
29 #include "Rtypes.h"
30 
31 #include <cstdlib>
32 #include <cmath>
33 
34 namespace TMath {
35 
36  // Abs
37  inline Short_t Abs(Short_t d);
38  inline Int_t Abs(Int_t d);
39  inline Long_t Abs(Long_t d);
40  inline Long64_t Abs(Long64_t d);
41  inline Float_t Abs(Float_t d);
42  inline Double_t Abs(Double_t d);
43  inline LongDouble_t Abs(LongDouble_t d);
44 
45  // Even/Odd
46  inline Bool_t Even(Long_t a);
47  inline Bool_t Odd(Long_t a);
48 
49  // SignBit
50  template<typename Integer>
51  inline Bool_t SignBit(Integer a);
52  inline Bool_t SignBit(Float_t a);
53  inline Bool_t SignBit(Double_t a);
54  inline Bool_t SignBit(LongDouble_t a);
55 
56  // Sign
57  template<typename T1, typename T2>
58  inline T1 Sign( T1 a, T2 b);
59  inline Float_t Sign(Float_t a, Float_t b);
60  inline Double_t Sign(Double_t a, Double_t b);
62 
63  // Min, Max of two scalars
64  inline Short_t Min(Short_t a, Short_t b);
65  inline UShort_t Min(UShort_t a, UShort_t b);
66  inline Int_t Min(Int_t a, Int_t b);
67  inline UInt_t Min(UInt_t a, UInt_t b);
68  inline Long_t Min(Long_t a, Long_t b);
69  inline ULong_t Min(ULong_t a, ULong_t b);
70  inline Long64_t Min(Long64_t a, Long64_t b);
71  inline ULong64_t Min(ULong64_t a, ULong64_t b);
72  inline Float_t Min(Float_t a, Float_t b);
73  inline Double_t Min(Double_t a, Double_t b);
74 
75  inline Short_t Max(Short_t a, Short_t b);
76  inline UShort_t Max(UShort_t a, UShort_t b);
77  inline Int_t Max(Int_t a, Int_t b);
78  inline UInt_t Max(UInt_t a, UInt_t b);
79  inline Long_t Max(Long_t a, Long_t b);
80  inline ULong_t Max(ULong_t a, ULong_t b);
81  inline Long64_t Max(Long64_t a, Long64_t b);
82  inline ULong64_t Max(ULong64_t a, ULong64_t b);
83  inline Float_t Max(Float_t a, Float_t b);
84  inline Double_t Max(Double_t a, Double_t b);
85 
86  // Range
87  inline Short_t Range(Short_t lb, Short_t ub, Short_t x);
88  inline Int_t Range(Int_t lb, Int_t ub, Int_t x);
89  inline Long_t Range(Long_t lb, Long_t ub, Long_t x);
90  inline ULong_t Range(ULong_t lb, ULong_t ub, ULong_t x);
91  inline Double_t Range(Double_t lb, Double_t ub, Double_t x);
92 
93  //NextPrime is used by the Core classes.
94  Long_t NextPrime(Long_t x); // Least prime number greater than x
95 }
96 
97 
98 //---- Even/odd ----------------------------------------------------------------
99 
101  { return ! (a & 1); }
102 
104  { return (a & 1); }
105 
106 //---- Abs ---------------------------------------------------------------------
107 
109 { return (d >= 0) ? d : Short_t(-d); }
110 
112 { return std::abs(d); }
113 
115 { return std::labs(d); }
116 
118 #if __cplusplus >= 201103
119 { return std::llabs(d); }
120 #else
121 { return (d >= 0) ? d : -d; }
122 #endif
123 
125 { return std::abs(d); }
126 
128 { return std::abs(d); }
129 
131 { return std::abs(d); }
132 
133 
134 //---- Sign Bit--------------------------------------------------------------------
135 
136 template<typename Integer>
137 inline Bool_t TMath::SignBit( Integer a)
138  { return (a < 0); }
139 
141  { return std::signbit(a); }
142 
144  { return std::signbit(a); }
145 
147  { return std::signbit(a); }
148 
149 
150 //---- Sign --------------------------------------------------------------------
151 
152 template<typename T1, typename T2>
153 inline T1 TMath::Sign( T1 a, T2 b)
154  { return (SignBit(b)) ? - Abs(a) : Abs(a); }
155 
157  { return std::copysign(a,b); }
158 
160  { return std::copysign(a,b); }
161 
163  { return std::copysign(a,b); }
164 
165 
166 //---- Min ---------------------------------------------------------------------
167 
169  { return a <= b ? a : b; }
170 
172  { return a <= b ? a : b; }
173 
175  { return a <= b ? a : b; }
176 
178  { return a <= b ? a : b; }
179 
181  { return a <= b ? a : b; }
182 
184  { return a <= b ? a : b; }
185 
187  { return a <= b ? a : b; }
188 
190  { return a <= b ? a : b; }
191 
193  { return a <= b ? a : b; }
194 
196  { return a <= b ? a : b; }
197 
198 //---- Max ---------------------------------------------------------------------
199 
201  { return a >= b ? a : b; }
202 
204  { return a >= b ? a : b; }
205 
207  { return a >= b ? a : b; }
208 
210  { return a >= b ? a : b; }
211 
213  { return a >= b ? a : b; }
214 
216  { return a >= b ? a : b; }
217 
219  { return a >= b ? a : b; }
220 
222  { return a >= b ? a : b; }
223 
225  { return a >= b ? a : b; }
226 
228  { return a >= b ? a : b; }
229 
230 //---- Range -------------------------------------------------------------------
231 
233  { return x < lb ? lb : (x > ub ? ub : x); }
234 
236  { return x < lb ? lb : (x > ub ? ub : x); }
237 
239  { return x < lb ? lb : (x > ub ? ub : x); }
240 
242  { return x < lb ? lb : (x > ub ? ub : x); }
243 
245  { return x < lb ? lb : (x > ub ? ub : x); }
246 
247 
248 #endif
long long Long64_t
Definition: RtypesCore.h:69
T1 Sign(T1 a, T2 b)
Definition: TMathBase.h:153
float Float_t
Definition: RtypesCore.h:53
unsigned short UShort_t
Definition: RtypesCore.h:36
Short_t Range(Short_t lb, Short_t ub, Short_t x)
Definition: TMathBase.h:232
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:168
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Short_t Abs(Short_t d)
Definition: TMathBase.h:108
Bool_t Odd(Long_t a)
Definition: TMathBase.h:103
Double_t x[n]
Definition: legend1.C:17
Bool_t Even(Long_t a)
Definition: TMathBase.h:100
auto * a
Definition: textangle.C:12
unsigned int UInt_t
Definition: RtypesCore.h:42
short Short_t
Definition: RtypesCore.h:35
long double LongDouble_t
Definition: RtypesCore.h:57
long Long_t
Definition: RtypesCore.h:50
#define d(i)
Definition: RSha256.hxx:102
double Double_t
Definition: RtypesCore.h:55
unsigned long long ULong64_t
Definition: RtypesCore.h:70
unsigned long ULong_t
Definition: RtypesCore.h:51
#define T2
Definition: md5.inl:146
Long_t NextPrime(Long_t x)
TMath Base functionsDefine the functions Min, Max, Abs, Sign, Range for all types.
Definition: TMathBase.cxx:30
#define T1
Definition: md5.inl:145
Bool_t SignBit(Integer a)
Definition: TMathBase.h:137
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:200
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
TMath.
Definition: TMathBase.h:34