17#ifndef TF2__LINEARMATH__SCALAR_HPP_
18#define TF2__LINEARMATH__SCALAR_HPP_
20#ifdef TF2_MANAGED_CODE
32#if defined(DEBUG) || defined (_DEBUG)
39 #if defined(__MINGW32__) || defined(__CYGWIN__) || (defined (_MSC_VER) && _MSC_VER < 1300)
41 #define TF2SIMD_FORCE_INLINE inline
42 #define ATTRIBUTE_ALIGNED16(a) a
43 #define ATTRIBUTE_ALIGNED64(a) a
44 #define ATTRIBUTE_ALIGNED128(a) a
47 #pragma warning(disable : 4324)
52 #define TF2SIMD_FORCE_INLINE __forceinline
53 #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
54 #define ATTRIBUTE_ALIGNED64(a) __declspec(align(64)) a
55 #define ATTRIBUTE_ALIGNED128(a) __declspec (align(128)) a
57 #define TF2_USE_VMX128
59 #include <ppcintrinsics.h>
60 #define TF2_HAVE_NATIVE_FSEL
61 #define tf2Fsel(a,b,c) __fsel((a),(b),(c))
71 #define tf2Assert assert
76 #define tf2FullAssert(x)
78 #define tf2Likely(_c) _c
79 #define tf2Unlikely(_c) _c
83#if defined (__CELLOS_LV2__)
84 #define TF2SIMD_FORCE_INLINE inline
85 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
86 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
87 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
92 #define tf2Assert assert
97 #define tf2FullAssert(x)
99 #define tf2Likely(_c) _c
100 #define tf2Unlikely(_c) _c
106 #define TF2SIMD_FORCE_INLINE __inline
107 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
108 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
109 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
114 #define tf2Assert assert
119 #define tf2FullAssert(x)
122 #define tf2Likely(_c) __builtin_expect((_c), 1)
123 #define tf2Unlikely(_c) __builtin_expect((_c), 0)
129 #define TF2SIMD_FORCE_INLINE inline
134 #define ATTRIBUTE_ALIGNED16(a) a
135 #define ATTRIBUTE_ALIGNED64(a) a
136 #define ATTRIBUTE_ALIGNED128(a) a
141#if defined(DEBUG) || defined (_DEBUG)
142 #define tf2Assert assert
148 #define tf2FullAssert(x)
149 #define tf2Likely(_c) _c
150 #define tf2Unlikely(_c) _c
161#define TF2_LARGE_FLOAT 1e30
164#define TF2_DECLARE_ALIGNED_ALLOCATOR() \
165 TF2SIMD_FORCE_INLINE void* operator new(size_t sizeInBytes) { return tf2AlignedAlloc(sizeInBytes,16); } \
166 TF2SIMD_FORCE_INLINE void operator delete(void* ptr) { tf2AlignedFree(ptr); } \
167 TF2SIMD_FORCE_INLINE void* operator new(size_t, void* ptr) { return ptr; } \
168 TF2SIMD_FORCE_INLINE void operator delete(void*, void*) { } \
169 TF2SIMD_FORCE_INLINE void* operator new[](size_t sizeInBytes) { return tf2AlignedAlloc(sizeInBytes,16); } \
170 TF2SIMD_FORCE_INLINE void operator delete[](void* ptr) { tf2AlignedFree(ptr); } \
171 TF2SIMD_FORCE_INLINE void* operator new[](size_t, void* ptr) { return ptr; } \
172 TF2SIMD_FORCE_INLINE void operator delete[](void*, void*) { } \
192#define TF2SIMD_2_PI tf2Scalar(6.283185307179586232)
193#define TF2SIMD_PI (TF2SIMD_2_PI * tf2Scalar(0.5))
194#define TF2SIMD_HALF_PI (TF2SIMD_2_PI * tf2Scalar(0.25))
195#define TF2SIMD_RADS_PER_DEG (TF2SIMD_2_PI / tf2Scalar(360.0))
196#define TF2SIMD_DEGS_PER_RAD (tf2Scalar(360.0) / TF2SIMD_2_PI)
197#define TF2SIMDSQRT12 tf2Scalar(0.7071067811865475244008443621048490)
199#define tf2RecipSqrt(x) ((tf2Scalar)(tf2Scalar(1.0)/tf2Sqrt(tf2Scalar(x))))
202#define TF2SIMD_EPSILON DBL_EPSILON
203#define TF2SIMD_INFINITY DBL_MAX
213 angle = coeff_1 - coeff_1 * r;
216 angle = coeff_2 - coeff_1 * r;
218 return (y < 0.0f) ? -angle : angle;
224 return (((a) <= eps) && !((a) < -eps));
227 return (!((a) <= eps));
238#define TF2_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
243 return a >= 0 ? b : c;
246#define tf2Fsels(a,b,c) (tf2Scalar)tf2Fsel(a,b,c)
252 const char *p = (
const char *) &i;
269 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
270 unsigned testEqz = ~testNz;
271 return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
275 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
276 unsigned testEqz = ~testNz;
277 return static_cast<int>((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
281#ifdef TF2_HAVE_NATIVE_FSEL
284 return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero;
299 return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24));
304 return static_cast<unsigned short>(((val & 0xff00) >> 8) | ((val & 0x00ff) << 8));
326 unsigned char *dst = (
unsigned char *)&a;
327 unsigned char *src = (
unsigned char *)&d;
340 unsigned char *src = (
unsigned char *)&a;
341 unsigned char *dst = (
unsigned char *)&d;
355 unsigned char *src = (
unsigned char *)&d;
372 unsigned char *dst = (
unsigned char *)&d;
400 return angleInRadians;
bool tf2GreaterEqual(tf2Scalar a, tf2Scalar eps)
Definition Scalar.hpp:226
int tf2IsNegative(tf2Scalar x)
Definition Scalar.hpp:231
tf2Scalar tf2Sqrt(tf2Scalar x)
Definition Scalar.hpp:177
tf2Scalar tf2NormalizeAngle(tf2Scalar angleInRadians)
Definition Scalar.hpp:387
double tf2UnswapEndianDouble(const unsigned char *src)
Definition Scalar.hpp:369
tf2Scalar tf2Atan2Fast(tf2Scalar y, tf2Scalar x)
Definition Scalar.hpp:205
unsigned tf2SwapEndian(unsigned val)
Definition Scalar.hpp:297
float tf2UnswapEndianFloat(unsigned int a)
Definition Scalar.hpp:337
#define TF2SIMD_PI
Definition Scalar.hpp:193
unsigned int tf2SwapEndianFloat(float d)
tf2SwapFloat uses using char pointers to swap the endianness
Definition Scalar.hpp:323
void tf2SwapEndianDouble(double d, unsigned char *dst)
Definition Scalar.hpp:353
#define TF2SIMD_DEGS_PER_RAD
Definition Scalar.hpp:196
bool tf2FuzzyZero(tf2Scalar x)
Definition Scalar.hpp:221
#define TF2SIMD_EPSILON
Definition Scalar.hpp:202
tf2Scalar tf2Log(tf2Scalar x)
Definition Scalar.hpp:187
void tf2Swap(T &a, T &b)
Definition Scalar.hpp:288
bool tf2Equal(tf2Scalar a, tf2Scalar eps)
Definition Scalar.hpp:223
tf2Scalar tf2Degrees(tf2Scalar x)
Definition Scalar.hpp:236
tf2Scalar tf2Fmod(tf2Scalar x, tf2Scalar y)
Definition Scalar.hpp:189
tf2Scalar tf2Pow(tf2Scalar x, tf2Scalar y)
Definition Scalar.hpp:188
tf2Scalar tf2Tan(tf2Scalar x)
Definition Scalar.hpp:181
bool tf2MachineIsLittleEndian()
Definition Scalar.hpp:249
#define TF2SIMD_2_PI
Definition Scalar.hpp:192
tf2Scalar tf2Cos(tf2Scalar x)
Definition Scalar.hpp:179
tf2Scalar tf2Exp(tf2Scalar x)
Definition Scalar.hpp:186
unsigned tf2Select(unsigned condition, unsigned valueIfConditionNonZero, unsigned valueIfConditionZero)
Definition Scalar.hpp:263
tf2Scalar tf2Atan2(tf2Scalar x, tf2Scalar y)
Definition Scalar.hpp:185
tf2Scalar tf2Atan(tf2Scalar x)
Definition Scalar.hpp:184
tf2Scalar tf2Radians(tf2Scalar x)
Definition Scalar.hpp:235
tf2Scalar tf2Fsel(tf2Scalar a, tf2Scalar b, tf2Scalar c)
Definition Scalar.hpp:241
#define TF2SIMD_FORCE_INLINE
Definition Scalar.hpp:129
tf2Scalar tf2Fabs(tf2Scalar x)
Definition Scalar.hpp:178
tf2Scalar tf2Acos(tf2Scalar x)
Definition Scalar.hpp:182
#define TF2SIMD_RADS_PER_DEG
Definition Scalar.hpp:195
tf2Scalar tf2Asin(tf2Scalar x)
Definition Scalar.hpp:183
tf2Scalar tf2Sin(tf2Scalar x)
Definition Scalar.hpp:180
double tf2Scalar
The tf2Scalar type abstracts floating point numbers, to easily switch between double and single float...
Definition Scalar.hpp:159
rudimentary class to provide type info
Definition Scalar.hpp:406
tf2TypedObject(int objectType)
Definition Scalar.hpp:407
int getObjectType() const
Definition Scalar.hpp:412
int m_objectType
Definition Scalar.hpp:411