QDP++
qdp_word.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// QDP data parallel interface
4//
5
6// NOT USING THIS CODE AT THE MOMENT
7
8#ifndef QDP_WORD_H
9#define QDP_WORD_H
10
11#include <cmath>
12
13namespace QDP {
14
15//-------------------------------------------------------------------------------------
17
21template<class T> class Word
22{
23public:
24 Word() {}
25 ~Word() {}
26
28 explicit Word(const T& rhs) : F(rhs) {}
29
30//private:
32 Word(const Word& a): F(a.F) {}
33
34public:
35 T& elem() {return F;}
36 const T& elem() const {return F;}
37
38private:
39 T F;
40};
41
42
43//-------------------------------------------------------------------------------------
45
49class Real32 : public Word<float>
50{
51public:
52 Real32() {}
54
56 explicit Real32(const float& rhs)
57 {
58// fprintf(stderr,"construct Real32(float): %f\n",rhs);
59 elem() = rhs;
60 }
61
63
64 inline
65 Real32& operator=(int rhs)
66 {
67// fprintf(stderr,"Real32 = int\n");
68 elem() = rhs;
69 return *this;
70 }
71
72};
73
74
76
80class Real64 : public Word<double>
81{
82public:
83};
84
85
87
91class Integer32 : public Word<int>
92{
93public:
95
96 inline
98 {
99// fprintf(stderr,"Integer32 = int\n");
100 elem() = rhs;
101 return *this;
102 }
103
104};
105
106
108
113{
114public:
115 bool& elem() {return d;}
116 const bool& elem() const {return d;}
117
118private:
119 bool d;
120};
121
122
123//-----------------------------------------------------------------------------
124// Traits classes
125//-----------------------------------------------------------------------------
126
127// Underlying word type
129{
130 typedef float Type_t;
131};
132
133// Underlying word type
135{
136 typedef double Type_t;
137};
138
139// Underlying word type
141{
142 typedef int Type_t;
143};
144
145// Underlying word type
146struct WordType<unsigned int>
147{
148 typedef unsigned int Type_t;
149};
150
151// Underlying word type
152struct WordType<unsigned long>
153{
154 typedef unsigned long Type_t;
155};
156
157// -------------------------------------------------------
158// Single precision types
159// -------------------------------------------------------
161{
162 typedef Real32 Type_t;
163};
164
166{
167 typedef Real32 Type_t;
168};
169
170struct SinglePrecType<float>
171{
172 typedef float Type_t;
173};
174
175struct SinglePrecType<double>
176{
177 typedef float Type_t;
178};
179
180// --------------------------------------------------------
181// Double Precision Types
182// ---------------------------------------------------------
184{
185 typedef Real64 Type_t;
186};
187
189{
190 typedef Real64 Type_t;
191};
192
193struct DoublePrecType<float>
194{
195 typedef double Type_t;
196};
197
198struct DoublePrecType<double>
199{
200 typedef double Type_t;
201};
202
203
204
205template<class Op>
207 typedef Real32 Type_t;
208};
209
210#if 1
212 typedef Real32& Type_t;
213};
214#endif
215
216
217//-----------------------------------------------------------------------------
218// Operators
219//-----------------------------------------------------------------------------
220
223{
224// fprintf(stderr,"negate a Real32\n");
225 Real32 d;
226 d.elem() = -l.elem();
227
228// fprintf(stderr,"return a -Real32\n");
229 return d;
230}
231
233operator+(const Real32 & l,const Real32 & r)
234{
235// fprintf(stderr,"add a Real32 + Real32\n");
236 Real32 d;
237 d.elem() = l.elem() + r.elem();
238
239// fprintf(stderr,"return a Real32 + Real32\n");
240 return d;
241}
242
244operator-(const Real32 & l,const Real32 & r)
245{
246// fprintf(stderr,"add a Real32 - Real32\n");
247 Real32 d;
248 d.elem() = l.elem() - r.elem();
249
250// fprintf(stderr,"return a Real32 - Real32\n");
251 return d;
252}
253
255operator*(const Real32 & l, const Real32 & r)
256{
257 Real32 d;
258 d.elem() = l.elem() * r.elem();
259 return d;
260}
261
262} // namespace QDP
263
264#endif
Integer32 word class - wrapper over builtin integer type.
Definition qdp_word.h:92
Integer32 & operator=(int rhs)
dest = int
Definition qdp_word.h:97
Logical class - wrapper over builtin boolean type.
Definition qdp_word.h:113
const bool & elem() const
Definition qdp_word.h:116
bool & elem()
Definition qdp_word.h:115
Real32 word class - builtin machine word type over flow.
Definition qdp_word.h:50
Real32(const float &rhs)
dest = float
Definition qdp_word.h:56
Real32 & operator=(int rhs)
dest = int
Definition qdp_word.h:65
Real64 word class - wrapper over builtin double type.
Definition qdp_word.h:81
Word(const T &rhs)
dest = float
Definition qdp_word.h:28
Word(const Word &a)
Definition qdp_word.h:32
T & elem()
Definition qdp_word.h:35
const T & elem() const
Definition qdp_word.h:36
Yet another random number generator.
MakeReturn< BinaryNode< OpMultiply, typenameCreateLeaf< QDPType< T1, C1 > >::Leaf_t, typenameCreateLeaf< QDPExpr< T2, C2 > >::Leaf_t >, typenameBinaryReturn< C1, C2, OpMultiply >::Type_t >::Expression_t operator*(const QDPType< T1, C1 > &l, const QDPExpr< T2, C2 > &r)
Definition qdp.h:2588
MakeReturn< BinaryNode< OpAdd, typenameCreateLeaf< QDPType< T1, C1 > >::Leaf_t, typenameCreateLeaf< QDPExpr< T2, C2 > >::Leaf_t >, typenameBinaryReturn< C1, C2, OpAdd >::Type_t >::Expression_t operator+(const QDPType< T1, C1 > &l, const QDPExpr< T2, C2 > &r)
Definition qdp.h:2556
MakeReturn< BinaryNode< OpSubtract, typenameCreateLeaf< QDPType< T1, C1 > >::Leaf_t, typenameCreateLeaf< QDPExpr< T2, C2 > >::Leaf_t >, typenameBinaryReturn< C1, C2, OpSubtract >::Type_t >::Expression_t operator-(const QDPType< T1, C1 > &l, const QDPExpr< T2, C2 > &r)
Definition qdp.h:2572
Promote< T1, T2 >::Type_t Type_t
Find the underlying word type of a field.
Definition qdp_traits.h:29