2 Copyright (C) 2009 Sony Computer Entertainment Inc.
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:
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.
20 namespace Vectormath {
24 //--------------------------------------------------------------------------------------------------
28 // A class representing a scalar float value contained in a vector register
29 // This class does not support fastmath
36 // Default constructor; does no initialization
38 inline floatInVec( ) { };
40 // Construct from a value converted from bool
42 inline floatInVec(boolInVec vec);
44 // Explicit cast from float
46 explicit inline floatInVec(float scalar);
48 // Explicit cast to float
50 inline float getAsFloat() const;
52 #ifndef _VECTORMATH_NO_SCALAR_CAST
53 // Implicit cast to float
55 inline operator float() const;
58 // Post increment (add 1.0f)
60 inline const floatInVec operator ++ (int);
62 // Post decrement (subtract 1.0f)
64 inline const floatInVec operator -- (int);
66 // Pre increment (add 1.0f)
68 inline floatInVec& operator ++ ();
70 // Pre decrement (subtract 1.0f)
72 inline floatInVec& operator -- ();
76 inline const floatInVec operator - () const;
78 // Assignment operator
80 inline floatInVec& operator = (floatInVec vec);
82 // Multiplication assignment operator
84 inline floatInVec& operator *= (floatInVec vec);
86 // Division assignment operator
88 inline floatInVec& operator /= (floatInVec vec);
90 // Addition assignment operator
92 inline floatInVec& operator += (floatInVec vec);
94 // Subtraction assignment operator
96 inline floatInVec& operator -= (floatInVec vec);
100 // Multiplication operator
102 inline const floatInVec operator * (floatInVec vec0, floatInVec vec1);
106 inline const floatInVec operator / (floatInVec vec0, floatInVec vec1);
110 inline const floatInVec operator + (floatInVec vec0, floatInVec vec1);
112 // Subtraction operator
114 inline const floatInVec operator - (floatInVec vec0, floatInVec vec1);
116 // Less than operator
118 inline const boolInVec operator < (floatInVec vec0, floatInVec vec1);
120 // Less than or equal operator
122 inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1);
124 // Greater than operator
126 inline const boolInVec operator > (floatInVec vec0, floatInVec vec1);
128 // Greater than or equal operator
130 inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1);
134 inline const boolInVec operator == (floatInVec vec0, floatInVec vec1);
136 // Not equal operator
138 inline const boolInVec operator != (floatInVec vec0, floatInVec vec1);
140 // Conditionally select between two values
142 inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1);
145 } // namespace Vectormath
148 //--------------------------------------------------------------------------------------------------
149 // floatInVec implementation
152 #include "boolInVec.h"
154 namespace Vectormath {
157 floatInVec::floatInVec(boolInVec vec)
159 mData = float(vec.getAsBool());
163 floatInVec::floatInVec(float scalar)
170 floatInVec::getAsFloat() const
175 #ifndef _VECTORMATH_NO_SCALAR_CAST
177 floatInVec::operator float() const
185 floatInVec::operator ++ (int)
187 float olddata = mData;
189 return floatInVec(olddata);
194 floatInVec::operator -- (int)
196 float olddata = mData;
198 return floatInVec(olddata);
203 floatInVec::operator ++ ()
205 *this += floatInVec(1.0f);
211 floatInVec::operator -- ()
213 *this -= floatInVec(1.0f);
219 floatInVec::operator - () const
221 return floatInVec(-mData);
226 floatInVec::operator = (floatInVec vec)
234 floatInVec::operator *= (floatInVec vec)
242 floatInVec::operator /= (floatInVec vec)
250 floatInVec::operator += (floatInVec vec)
258 floatInVec::operator -= (floatInVec vec)
266 operator * (floatInVec vec0, floatInVec vec1)
268 return floatInVec(vec0.getAsFloat() * vec1.getAsFloat());
273 operator / (floatInVec num, floatInVec den)
275 return floatInVec(num.getAsFloat() / den.getAsFloat());
280 operator + (floatInVec vec0, floatInVec vec1)
282 return floatInVec(vec0.getAsFloat() + vec1.getAsFloat());
287 operator - (floatInVec vec0, floatInVec vec1)
289 return floatInVec(vec0.getAsFloat() - vec1.getAsFloat());
294 operator < (floatInVec vec0, floatInVec vec1)
296 return boolInVec(vec0.getAsFloat() < vec1.getAsFloat());
301 operator <= (floatInVec vec0, floatInVec vec1)
303 return !(vec0 > vec1);
308 operator > (floatInVec vec0, floatInVec vec1)
310 return boolInVec(vec0.getAsFloat() > vec1.getAsFloat());
315 operator >= (floatInVec vec0, floatInVec vec1)
317 return !(vec0 < vec1);
322 operator == (floatInVec vec0, floatInVec vec1)
324 return boolInVec(vec0.getAsFloat() == vec1.getAsFloat());
329 operator != (floatInVec vec0, floatInVec vec1)
331 return !(vec0 == vec1);
336 select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1)
338 return (select_vec1.getAsBool() == 0) ? vec0 : vec1;
341 } // namespace Vectormath
343 #endif // floatInVec_h