mathlib.h (VectorNormalizeFast): Use a float/int union instead of type

punning to avoid strict aliasing violations. the compiler used to emit
a warning from rsprite.c:R_DrawSpriteModel() where the macro is used.


git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@153 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Ozkan Sezer 2010-04-26 14:11:48 +00:00
parent 4bc2b26e79
commit 04f7b1589a

View file

@ -56,15 +56,16 @@ extern int nanmask;
#define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
//johnfitz -- courtesy of lordhavoc
// QuakeSpasm: To avoid strict aliasing violations, use a float/int union instead of type punning.
#define VectorNormalizeFast(_v)\
{\
float _y, _number;\
_number = DotProduct(_v, _v);\
if (_number != 0.0)\
union { float f; int i; } _y, _number;\
_number.f = DotProduct(_v, _v);\
if (_number.f != 0.0)\
{\
*((int *)&_y) = 0x5f3759df - ((* (int *) &_number) >> 1);\
_y = _y * (1.5f - (_number * 0.5f * _y * _y));\
VectorScale(_v, _y, _v);\
_y.i = 0x5f3759df - (_number.i >> 1);\
_y.f = _y.f * (1.5f - (_number.f * 0.5f * _y.f * _y.f));\
VectorScale(_v, _y.f, _v);\
}\
}