Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JZero.hh
Go to the documentation of this file.
1#ifndef __JMATH__JZERO__
2#define __JMATH__JZERO__
3
4/**
5 * \file
6 *
7 * Definition of zero value for any class.
8 * \author mdejong
9 */
10namespace JMATH {}
11namespace JPP { using namespace JMATH; }
12
13namespace JMATH {
14
15 /**
16 * Get zero value for a given data type.
17 *
18 * The default implementation of this method returns an object which
19 * is created with the default constructor.
20 * This method should be specialised if this value does not correspond
21 * to the equivalent of a zero result.
22 *
23 * \return zero
24 */
25 template<class T>
26 inline T getZero()
27 {
28 return T();
29 }
30
31
32 /**
33 * Get zero value for <tt>bool</tt>.
34 *
35 * \return false
36 */
37 template<> inline bool getZero<bool>()
38 {
39 return false;
40 }
41
42
43 /**
44 * Get zero value for <tt>float</tt>.
45 *
46 * \return zero
47 */
48 template<> inline float getZero<float>()
49 {
50 return float(0.0);
51 }
52
53
54 /**
55 * Get zero value for <tt>double</tt>.
56 *
57 * \return zero
58 */
59 template<>
60 inline double getZero<double>()
61 {
62 return double(0.0);
63 }
64
65
66 /**
67 * Get zero value for <tt>long double</tt>.
68 *
69 * \return zero
70 */
71 template<>
72 inline long double getZero<long double>()
73 {
74 return (long double)(0.0);
75 }
76
77
78 /**
79 * Auxiliary class to assign zero value.
80 */
81 struct JZero {
82 /**
83 * Default constructor.
84 */
86 {}
87
88
89 /**
90 * Type conversion operator.
91 *
92 * \return zero
93 */
94 template<class T>
95 operator T() const
96 {
97 return getZero<T>();
98 }
99 };
100
101
102 /**
103 * Function object to assign zero value.
104 */
105 static const JZero zero;
106}
107
108#endif
Auxiliary classes and methods for mathematical operations.
Definition JEigen3D.hh:88
T getZero()
Get zero value for a given data type.
Definition JZero.hh:26
bool getZero< bool >()
Get zero value for bool.
Definition JZero.hh:37
long double getZero< long double >()
Get zero value for long double.
Definition JZero.hh:72
static const JZero zero
Function object to assign zero value.
Definition JZero.hh:105
double getZero< double >()
Get zero value for double.
Definition JZero.hh:60
float getZero< float >()
Get zero value for float.
Definition JZero.hh:48
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class to assign zero value.
Definition JZero.hh:81
JZero()
Default constructor.
Definition JZero.hh:85