Debian Codegraph @

test/Bullet2/vectormath/scalar/floatInVec.h

raw symbols SCIP
1 /*
2 Copyright (C) 2009 Sony Computer Entertainment Inc.
3 All rights reserved.
4
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14
15 */
16 #ifndef _FLOATINVEC_H
17 #define _FLOATINVEC_H
18
19 #include <math.h>
20 namespace Vectormath
21 {
22 class boolInVec;
23
24 //--------------------------------------------------------------------------------------------------
25 // floatInVec class
26 //
27
28 // A class representing a scalar float value contained in a vector register
29 // This class does not support fastmath
30 class floatInVec
31 {
32 private:
33 float mData;
34
35 public:
36 // Default constructor; does no initialization
37 //
38 inline floatInVec(){};
39
40 // Construct from a value converted from bool
41 //
42 inline floatInVec(boolInVec vec);
43
44 // Explicit cast from float
45 //
46 explicit inline floatInVec(float scalar);
47
48 // Explicit cast to float
49 //
50 inline float getAsFloat() const;
51
52 #ifndef _VECTORMATH_NO_SCALAR_CAST
53 // Implicit cast to float
54 //
55 inline operator float() const;
56 #endif
57
58 // Post increment (add 1.0f)
59 //
60 inline const floatInVec operator++(int);
61
62 // Post decrement (subtract 1.0f)
63 //
64 inline const floatInVec operator--(int);
65
66 // Pre increment (add 1.0f)
67 //
68 inline floatInVec& operator++();
69
70 // Pre decrement (subtract 1.0f)
71 //
72 inline floatInVec& operator--();
73
74 // Negation operator
75 //
76 inline const floatInVec operator-() const;
77
78 // Assignment operator
79 //
80 inline floatInVec& operator=(floatInVec vec);
81
82 // Multiplication assignment operator
83 //
84 inline floatInVec& operator*=(floatInVec vec);
85
86 // Division assignment operator
87 //
88 inline floatInVec& operator/=(floatInVec vec);
89
90 // Addition assignment operator
91 //
92 inline floatInVec& operator+=(floatInVec vec);
93
94 // Subtraction assignment operator
95 //
96 inline floatInVec& operator-=(floatInVec vec);
97 };
98
99 // Multiplication operator
100 //
101 inline const floatInVec operator*(floatInVec vec0, floatInVec vec1);
102
103 // Division operator
104 //
105 inline const floatInVec operator/(floatInVec vec0, floatInVec vec1);
106
107 // Addition operator
108 //
109 inline const floatInVec operator+(floatInVec vec0, floatInVec vec1);
110
111 // Subtraction operator
112 //
113 inline const floatInVec operator-(floatInVec vec0, floatInVec vec1);
114
115 // Less than operator
116 //
117 inline const boolInVec operator<(floatInVec vec0, floatInVec vec1);
118
119 // Less than or equal operator
120 //
121 inline const boolInVec operator<=(floatInVec vec0, floatInVec vec1);
122
123 // Greater than operator
124 //
125 inline const boolInVec operator>(floatInVec vec0, floatInVec vec1);
126
127 // Greater than or equal operator
128 //
129 inline const boolInVec operator>=(floatInVec vec0, floatInVec vec1);
130
131 // Equal operator
132 //
133 inline const boolInVec operator==(floatInVec vec0, floatInVec vec1);
134
135 // Not equal operator
136 //
137 inline const boolInVec operator!=(floatInVec vec0, floatInVec vec1);
138
139 // Conditionally select between two values
140 //
141 inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1);
142
143 } // namespace Vectormath
144
145 //--------------------------------------------------------------------------------------------------
146 // floatInVec implementation
147 //
148
149 #include "boolInVec.h"
150
151 namespace Vectormath
152 {
153 inline floatInVec::floatInVec(boolInVec vec)
154 {
155 mData = float(vec.getAsBool());
156 }
157
158 inline floatInVec::floatInVec(float scalar)
159 {
160 mData = scalar;
161 }
162
163 inline float
164 floatInVec::getAsFloat() const
165 {
166 return mData;
167 }
168
169 #ifndef _VECTORMATH_NO_SCALAR_CAST
170 inline floatInVec::operator float() const
171 {
172 return getAsFloat();
173 }
174 #endif
175
176 inline const floatInVec
177 floatInVec::operator++(int)
178 {
179 float olddata = mData;
180 operator++();
181 return floatInVec(olddata);
182 }
183
184 inline const floatInVec
185 floatInVec::operator--(int)
186 {
187 float olddata = mData;
188 operator--();
189 return floatInVec(olddata);
190 }
191
192 inline floatInVec&
193 floatInVec::operator++()
194 {
195 *this += floatInVec(1.0f);
196 return *this;
197 }
198
199 inline floatInVec&
200 floatInVec::operator--()
201 {
202 *this -= floatInVec(1.0f);
203 return *this;
204 }
205
206 inline const floatInVec
207 floatInVec::operator-() const
208 {
209 return floatInVec(-mData);
210 }
211
212 inline floatInVec&
213 floatInVec::operator=(floatInVec vec)
214 {
215 mData = vec.mData;
216 return *this;
217 }
218
219 inline floatInVec&
220 floatInVec::operator*=(floatInVec vec)
221 {
222 *this = *this * vec;
223 return *this;
224 }
225
226 inline floatInVec&
227 floatInVec::operator/=(floatInVec vec)
228 {
229 *this = *this / vec;
230 return *this;
231 }
232
233 inline floatInVec&
234 floatInVec::operator+=(floatInVec vec)
235 {
236 *this = *this + vec;
237 return *this;
238 }
239
240 inline floatInVec&
241 floatInVec::operator-=(floatInVec vec)
242 {
243 *this = *this - vec;
244 return *this;
245 }
246
247 inline const floatInVec
248 operator*(floatInVec vec0, floatInVec vec1)
249 {
250 return floatInVec(vec0.getAsFloat() * vec1.getAsFloat());
251 }
252
253 inline const floatInVec
254 operator/(floatInVec num, floatInVec den)
255 {
256 return floatInVec(num.getAsFloat() / den.getAsFloat());
257 }
258
259 inline const floatInVec
260 operator+(floatInVec vec0, floatInVec vec1)
261 {
262 return floatInVec(vec0.getAsFloat() + vec1.getAsFloat());
263 }
264
265 inline const floatInVec
266 operator-(floatInVec vec0, floatInVec vec1)
267 {
268 return floatInVec(vec0.getAsFloat() - vec1.getAsFloat());
269 }
270
271 inline const boolInVec
272 operator<(floatInVec vec0, floatInVec vec1)
273 {
274 return boolInVec(vec0.getAsFloat() < vec1.getAsFloat());
275 }
276
277 inline const boolInVec
278 operator<=(floatInVec vec0, floatInVec vec1)
279 {
280 return !(vec0 > vec1);
281 }
282
283 inline const boolInVec
284 operator>(floatInVec vec0, floatInVec vec1)
285 {
286 return boolInVec(vec0.getAsFloat() > vec1.getAsFloat());
287 }
288
289 inline const boolInVec
290 operator>=(floatInVec vec0, floatInVec vec1)
291 {
292 return !(vec0 < vec1);
293 }
294
295 inline const boolInVec
296 operator==(floatInVec vec0, floatInVec vec1)
297 {
298 return boolInVec(vec0.getAsFloat() == vec1.getAsFloat());
299 }
300
301 inline const boolInVec
302 operator!=(floatInVec vec0, floatInVec vec1)
303 {
304 return !(vec0 == vec1);
305 }
306
307 inline const floatInVec
308 select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1)
309 {
310 return (select_vec1.getAsBool() == 0) ? vec0 : vec1;
311 }
312
313 } // namespace Vectormath
314
315 #endif // floatInVec_h