Belle II Software development
Belle2::TrackFindingCDC::ESignUtil Namespace Reference

Namespace to hide the constants of the ESign enumeration. More...

Enumerations

enum  ESign : signed short {
  c_Plus = 1 ,
  c_Minus = -1 ,
  c_Zero = 0 ,
  c_Invalid = SHRT_MIN
}
 Enumeration for the distinct sign values of floating point variables. More...
 

Functions

ESign opposite (ESign s)
 Return the opposite sign. Leaves ESign::c_Invalid the same.
 
bool isValid (ESign s)
 Returns true if sign is ESign::c_Plus, ESign::c_Minus or ESign::c_Zero.
 
static ESign common (ESign n1, ESign n2)
 Check if two values have a common sign.
 
static ESign common (float n1, float n2)
 Check if two values have a common sign.
 
static ESign common (float n1, float n2, float n3, float n4)
 Check if four values have a common sign.
 
template<class FloatRange >
static ESign common (const FloatRange &as)
 Check if four values have a common sign.
 

Detailed Description

Namespace to hide the constants of the ESign enumeration.

Enumeration Type Documentation

◆ ESign

enum ESign : signed short

Enumeration for the distinct sign values of floating point variables.

Enumerator
c_Plus 

Constant for plus sign.

c_Minus 

Constant for minus sign.

c_Zero 

Constant for undefined sign.

c_Invalid 

Constant for invalid sign, e.g. the sign of NAN.

Definition at line 27 of file ESign.h.

27 : signed short {
29 c_Plus = 1,
30
32 c_Minus = -1,
33
35 c_Zero = 0,
36
38 c_Invalid = SHRT_MIN,
39 };
@ c_Zero
Constant for undefined sign.
Definition: ESign.h:35
@ c_Minus
Constant for minus sign.
Definition: ESign.h:32
@ c_Plus
Constant for plus sign.
Definition: ESign.h:29

Function Documentation

◆ common() [1/4]

static ESign common ( const FloatRange &  as)
inlinestatic

Check if four values have a common sign.

Ignores nan values. Returns ESign::c_Plus if all signs are positive. Returns ESign::c_Minus if all signs are negative. Returns ESign::c_Zero for mixed signs. Returns ESign::c_Invalid if all input are NaN.

Definition at line 104 of file ESign.h.

105 {
106 bool allNaN = std::all_of(as.begin(), as.end(), [](float a) { return std::isnan(a); });
107 if (allNaN) {
108 return ESign::c_Invalid;
109 } else {
110 return static_cast<ESign>(std::all_of(as.begin(), as.end(), [](float a) { return not(a <= 0); }) -
111 std::all_of(as.begin(), as.end(), [](float a) { return not(a >= 0); }));
112 }
113 }
ESign
Enumeration for the distinct sign values of floating point variables.
Definition: ESign.h:27

◆ common() [2/4]

static ESign common ( ESign  n1,
ESign  n2 
)
inlinestatic

Check if two values have a common sign.

Ignores ESign::c_Invalid values. Returns ESign::c_Plus if all signs are positive. Returns ESign::c_Minus if all signs are negative. Returns ESign::c_Zero for mixed signs. Returns ESign::c_Invalid if all input are c_Invalid

Definition at line 57 of file ESign.h.

58 {
59 return ((not isValid(n1) and not isValid(n2)) ?
60 ESign::c_Invalid :
61 static_cast<ESign>((not(n1 <= 0) and not(n2 <= 0)) - (not(n1 >= 0) and not(n2 >= 0))));
62 }

◆ common() [3/4]

static ESign common ( float  n1,
float  n2 
)
inlinestatic

Check if two values have a common sign.

Ignores nan values. Returns ESign::c_Plus if all signs are positive. Returns ESign::c_Minus if all signs are negative. Returns ESign::c_Zero for mixed signs. Returns ESign::c_Invalid if all input are NaN.

Definition at line 72 of file ESign.h.

73 {
74 return ((std::isnan(n1) and std::isnan(n2)) ?
75 ESign::c_Invalid :
76 static_cast<ESign>((not(n1 <= 0) and not(n2 <= 0)) - (not(n1 >= 0) and not(n2 >= 0))));
77 }

◆ common() [4/4]

static ESign common ( float  n1,
float  n2,
float  n3,
float  n4 
)
inlinestatic

Check if four values have a common sign.

Ignores nan values. Returns ESign::c_Plus if all signs are positive. Returns ESign::c_Minus if all signs are negative. Returns ESign::c_Zero for mixed signs. Returns ESign::c_Invalid if all input are NaN.

Definition at line 87 of file ESign.h.

88 {
89 return ((std::isnan(n1) and std::isnan(n2) and std::isnan(n3) and std::isnan(n4)) ?
90 ESign::c_Invalid :
91 static_cast<ESign>((not(n1 <= 0) and not(n2 <= 0) and not(n3 <= 0) and not(n4 <= 0)) -
92 (not(n1 >= 0) and not(n2 >= 0) and not(n3 >= 0) and not(n4 >= 0))));
93 }

◆ isValid()

bool isValid ( ESign  s)
inline

Returns true if sign is ESign::c_Plus, ESign::c_Minus or ESign::c_Zero.

Definition at line 46 of file ESign.h.

47 { return std::abs(s) <= 1; }

◆ opposite()

ESign opposite ( ESign  s)
inline

Return the opposite sign. Leaves ESign::c_Invalid the same.

Definition at line 42 of file ESign.h.

43 { return static_cast<ESign>(-s); }