/********************************************************************\ ** _________________________________ ** ** A n t h o n y |________ __ __ _________| ** ** | |o_| |o_| | ** ** T h y s s e n __| __ __ |__ ** ** __| __| | | |__ |__ ** ** `` Dragon Computing! '' __| __| | | |__ |__ ** ** |_____| |__| |_____| ** ** ** \********************************************************************/ /* Fixed point math routines - with separate routines for trig functions */ /* definitions for normal fixpoint math */ #define fixpoint LONG #define PLACE 8 /* binary point digits to provide */ #define fix1 256 /* 1 << PLACE - a value of one */ #define HPLACE 4 /* place divided by two */ /* interger conversions */ #define inttofix(i) ((i) << PLACE) #define fixtoint(f) ((f) >> PLACE) /* floating to fix point - floats can't handle bit operations */ #define flttofix(F) ( (fixpoint) ((F) * fix1) ) #define fixtoflt(F) ( ((float)(F)) / fix1 ) /* fixpoint multiplys and divides */ #define fixmul(f1,f2) ( ((f1) * (f2)) >> PLACE ) #define fixdiv(f1,f2) ( ((f1) << PLACE) / (f2) ) /* this multiply has a larger maximum result without overflow but with loss of precision of values multiplied */ #define fixmul2(f1,f2) ( ((f1) >> HPLACE) * ((f2) >> HPLACE) ) /* definitions for unit values ** These definitions provide greater precision for fixpoint numbers ** of the range 0 to 1, as is the case for the result of SIN() and COS() ** say from table lookup, or for unit vectors and matrix rotations ** as in vector graphics / calculations. The multiply provided below ** can be used for any fixpoint number to return a number in the same ** scale. IE (if u = unitpoint and f = any fixpoint type ) ** f = unitmul( f , u ) => i = unitmul( i , u ) ** => u = unitmul( u , u ) ** Largest result possible for unitpoint * fixpoint = ** 2^( 31 - UNIT_PLACE - PLACE ) ** => 2^( 31 - 15 - 8 ) => 2 ^ 8 => 256.0 fixpoint */ #define UNIT_PLACE 15 #define unit1 32768 #define flttounit(F) ( (fixpoint) ((F) * unit1) ) #define unitmul(f1,f2) ( ((f1) * (f2)) >> UNIT_PLACE )