Tizen 2.1 base
[platform/upstream/libbullet.git] / Extras / vectormathlibrary / include / vectormath / scalar / cpp / floatInVec.h
1 /*\r
2    Copyright (C) 2006-2010 Sony Computer Entertainment Inc.\r
3    All rights reserved.\r
4 \r
5    Redistribution and use in source and binary forms,\r
6    with or without modification, are permitted provided that the\r
7    following conditions are met:\r
8     * Redistributions of source code must retain the above copyright\r
9       notice, this list of conditions and the following disclaimer.\r
10     * Redistributions in binary form must reproduce the above copyright\r
11       notice, this list of conditions and the following disclaimer in the\r
12       documentation and/or other materials provided with the distribution.\r
13     * Neither the name of the Sony Computer Entertainment Inc nor the names\r
14       of its contributors may be used to endorse or promote products derived\r
15       from this software without specific prior written permission.\r
16 \r
17    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
18    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
19    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
20    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
21    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
22    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
23    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
24    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
25    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
26    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
27    POSSIBILITY OF SUCH DAMAGE.\r
28 */\r
29 \r
30 #ifndef _FLOATINVEC__SCALAR_H\r
31 #define _FLOATINVEC__SCALAR_H\r
32 \r
33 #include <math.h>\r
34 namespace Vectormath {\r
35 \r
36 class boolInVec;\r
37 \r
38 //--------------------------------------------------------------------------------------------------\r
39 // floatInVec class\r
40 //\r
41 \r
42 // A class representing a scalar float value contained in a vector register\r
43 // This class does not support fastmath\r
44 class floatInVec\r
45 {\r
46 private:\r
47     float mData;\r
48 \r
49 public:\r
50     // Default constructor; does no initialization\r
51     //\r
52     inline floatInVec( ) { };\r
53 \r
54     // Construct from a value converted from bool\r
55     //\r
56     inline floatInVec(boolInVec vec);\r
57 \r
58     // Explicit cast from float\r
59     //\r
60     explicit inline floatInVec(float scalar);\r
61 \r
62     // Explicit cast to float\r
63     //\r
64     inline float getAsFloat() const;\r
65 \r
66 #ifndef _VECTORMATH_NO_SCALAR_CAST\r
67     // Implicit cast to float\r
68     //\r
69     inline operator float() const;\r
70 #endif\r
71 \r
72     // Post increment (add 1.0f)\r
73     //\r
74     inline const floatInVec operator ++ (int);\r
75 \r
76     // Post decrement (subtract 1.0f)\r
77     //\r
78     inline const floatInVec operator -- (int);\r
79 \r
80     // Pre increment (add 1.0f)\r
81     //\r
82     inline floatInVec& operator ++ ();\r
83 \r
84     // Pre decrement (subtract 1.0f)\r
85     //\r
86     inline floatInVec& operator -- ();\r
87 \r
88     // Negation operator\r
89     //\r
90     inline const floatInVec operator - () const;\r
91 \r
92     // Assignment operator\r
93     //\r
94     inline floatInVec& operator = (floatInVec vec);\r
95 \r
96     // Multiplication assignment operator\r
97     //\r
98     inline floatInVec& operator *= (floatInVec vec);\r
99 \r
100     // Division assignment operator\r
101     //\r
102     inline floatInVec& operator /= (floatInVec vec);\r
103 \r
104     // Addition assignment operator\r
105     //\r
106     inline floatInVec& operator += (floatInVec vec);\r
107 \r
108     // Subtraction assignment operator\r
109     //\r
110     inline floatInVec& operator -= (floatInVec vec);\r
111 \r
112 };\r
113 \r
114 // Multiplication operator\r
115 //\r
116 inline const floatInVec operator * (floatInVec vec0, floatInVec vec1);\r
117 \r
118 // Division operator\r
119 //\r
120 inline const floatInVec operator / (floatInVec vec0, floatInVec vec1);\r
121 \r
122 // Addition operator\r
123 //\r
124 inline const floatInVec operator + (floatInVec vec0, floatInVec vec1);\r
125 \r
126 // Subtraction operator\r
127 //\r
128 inline const floatInVec operator - (floatInVec vec0, floatInVec vec1);\r
129 \r
130 // Less than operator\r
131 //\r
132 inline const boolInVec operator < (floatInVec vec0, floatInVec vec1);\r
133 \r
134 // Less than or equal operator\r
135 //\r
136 inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1);\r
137 \r
138 // Greater than operator\r
139 //\r
140 inline const boolInVec operator > (floatInVec vec0, floatInVec vec1);\r
141 \r
142 // Greater than or equal operator\r
143 //\r
144 inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1);\r
145 \r
146 // Equal operator\r
147 //\r
148 inline const boolInVec operator == (floatInVec vec0, floatInVec vec1);\r
149 \r
150 // Not equal operator\r
151 //\r
152 inline const boolInVec operator != (floatInVec vec0, floatInVec vec1);\r
153 \r
154 // Conditionally select between two values\r
155 //\r
156 inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1);\r
157 \r
158 \r
159 } // namespace Vectormath\r
160 \r
161 \r
162 //--------------------------------------------------------------------------------------------------\r
163 // floatInVec implementation\r
164 //\r
165 \r
166 #include "boolInVec.h"\r
167 \r
168 namespace Vectormath {\r
169 \r
170 inline\r
171 floatInVec::floatInVec(boolInVec vec)\r
172 {\r
173     mData = float(vec.getAsBool());\r
174 }\r
175 \r
176 inline\r
177 floatInVec::floatInVec(float scalar)\r
178 {\r
179     mData = scalar;\r
180 }\r
181 \r
182 inline\r
183 float\r
184 floatInVec::getAsFloat() const\r
185 {\r
186     return mData;\r
187 }\r
188 \r
189 #ifndef _VECTORMATH_NO_SCALAR_CAST\r
190 inline\r
191 floatInVec::operator float() const\r
192 {\r
193     return getAsFloat();\r
194 }\r
195 #endif\r
196 \r
197 inline\r
198 const floatInVec\r
199 floatInVec::operator ++ (int)\r
200 {\r
201     float olddata = mData;\r
202     operator ++();\r
203     return floatInVec(olddata);\r
204 }\r
205 \r
206 inline\r
207 const floatInVec\r
208 floatInVec::operator -- (int)\r
209 {\r
210     float olddata = mData;\r
211     operator --();\r
212     return floatInVec(olddata);\r
213 }\r
214 \r
215 inline\r
216 floatInVec&\r
217 floatInVec::operator ++ ()\r
218 {\r
219     *this += floatInVec(1.0f);\r
220     return *this;\r
221 }\r
222 \r
223 inline\r
224 floatInVec&\r
225 floatInVec::operator -- ()\r
226 {\r
227     *this -= floatInVec(1.0f);\r
228     return *this;\r
229 }\r
230 \r
231 inline\r
232 const floatInVec\r
233 floatInVec::operator - () const\r
234 {\r
235     return floatInVec(-mData);\r
236 }\r
237 \r
238 inline\r
239 floatInVec&\r
240 floatInVec::operator = (floatInVec vec)\r
241 {\r
242     mData = vec.mData;\r
243     return *this;\r
244 }\r
245 \r
246 inline\r
247 floatInVec&\r
248 floatInVec::operator *= (floatInVec vec)\r
249 {\r
250     *this = *this * vec;\r
251     return *this;\r
252 }\r
253 \r
254 inline\r
255 floatInVec&\r
256 floatInVec::operator /= (floatInVec vec)\r
257 {\r
258     *this = *this / vec;\r
259     return *this;\r
260 }\r
261 \r
262 inline\r
263 floatInVec&\r
264 floatInVec::operator += (floatInVec vec)\r
265 {\r
266     *this = *this + vec;\r
267     return *this;\r
268 }\r
269 \r
270 inline\r
271 floatInVec&\r
272 floatInVec::operator -= (floatInVec vec)\r
273 {\r
274     *this = *this - vec;\r
275     return *this;\r
276 }\r
277 \r
278 inline\r
279 const floatInVec\r
280 operator * (floatInVec vec0, floatInVec vec1)\r
281 {\r
282     return floatInVec(vec0.getAsFloat() * vec1.getAsFloat());\r
283 }\r
284 \r
285 inline\r
286 const floatInVec\r
287 operator / (floatInVec num, floatInVec den)\r
288 {\r
289     return floatInVec(num.getAsFloat() / den.getAsFloat());\r
290 }\r
291 \r
292 inline\r
293 const floatInVec\r
294 operator + (floatInVec vec0, floatInVec vec1)\r
295 {\r
296     return floatInVec(vec0.getAsFloat() + vec1.getAsFloat());\r
297 }\r
298 \r
299 inline\r
300 const floatInVec\r
301 operator - (floatInVec vec0, floatInVec vec1)\r
302 {\r
303     return floatInVec(vec0.getAsFloat() - vec1.getAsFloat());\r
304 }\r
305 \r
306 inline\r
307 const boolInVec\r
308 operator < (floatInVec vec0, floatInVec vec1)\r
309 {\r
310     return boolInVec(vec0.getAsFloat() < vec1.getAsFloat());\r
311 }\r
312 \r
313 inline\r
314 const boolInVec\r
315 operator <= (floatInVec vec0, floatInVec vec1)\r
316 {\r
317     return !(vec0 > vec1);\r
318 }\r
319 \r
320 inline\r
321 const boolInVec\r
322 operator > (floatInVec vec0, floatInVec vec1)\r
323 {\r
324     return boolInVec(vec0.getAsFloat() > vec1.getAsFloat());\r
325 }\r
326 \r
327 inline\r
328 const boolInVec\r
329 operator >= (floatInVec vec0, floatInVec vec1)\r
330 {\r
331     return !(vec0 < vec1);\r
332 }\r
333 \r
334 inline\r
335 const boolInVec\r
336 operator == (floatInVec vec0, floatInVec vec1)\r
337 {\r
338     return boolInVec(vec0.getAsFloat() == vec1.getAsFloat());\r
339 }\r
340 \r
341 inline\r
342 const boolInVec\r
343 operator != (floatInVec vec0, floatInVec vec1)\r
344 {\r
345     return !(vec0 == vec1);\r
346 }\r
347 \r
348 inline\r
349 const floatInVec\r
350 select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1)\r
351 {\r
352     return (select_vec1.getAsBool() == 0) ? vec0 : vec1;\r
353 }\r
354 \r
355 } // namespace Vectormath\r
356 \r
357 #endif // floatInVec_h\r