tomwalters@0: /* tomwalters@0: calc.h tomwalters@0: ====== tomwalters@0: tomwalters@0: definitions to make model source portable across calculation type. tomwalters@0: Used fixed point representation for real numbers in integer machines. tomwalters@0: tomwalters@0: Type names: tomwalters@0: DataType - type used to pass results between modules tomwalters@0: EG. usually a short. tomwalters@0: StoreType - type used to store an intermediate result within a module tomwalters@0: ScalarType - type used to store fixed-point multipliers tomwalters@0: tomwalters@0: Integer arithmetic: tomwalters@0: tomwalters@0: SCALE - convert to fixed point tomwalters@0: SCALAR- float to fixed to fixed point multiplier tomwalters@0: (Used to create a value for a ScalarType). tomwalters@0: DESCALE - convert back to int (opposite of SCALE). tomwalters@0: tomwalters@0: UNSCALE - convert fixed point back to float. tomwalters@0: tomwalters@0: Use int instead float to get fixed point arithmetic, but shift tomwalters@0: numbers to preserve the significant digits, EG for multiplication: tomwalters@0: use SCALAR on one operand (which will then be a ScalarType) tomwalters@0: use DESCALE on the result tomwalters@0: */ tomwalters@0: tomwalters@0: #if 1 /* Switch to convert whole model to floating point */ tomwalters@0: #define FLOAT float /* version (default uses integer arithmetic) */ tomwalters@0: #endif tomwalters@0: tomwalters@0: #ifdef DSP32 tomwalters@0: #define FLOAT float tomwalters@0: #endif tomwalters@0: tomwalters@0: tomwalters@0: #ifdef FLOAT tomwalters@0: tomwalters@0: typedef FLOAT ScalarType ; tomwalters@0: typedef FLOAT StoreType ; tomwalters@0: typedef FLOAT DataType ; tomwalters@0: tomwalters@0: #define SCALE( _num ) ( _num ) tomwalters@0: #define SCALAR( _num ) ( _num ) tomwalters@0: #define DESCALE( _num ) ( _num ) tomwalters@0: #define UNSCALE( _num ) ( _num ) tomwalters@0: tomwalters@0: #else tomwalters@0: tomwalters@0: typedef long ScalarType ; tomwalters@0: typedef long StoreType ; tomwalters@0: typedef short DataType ; tomwalters@0: tomwalters@0: #define SCALE( _num ) ( (long) ( _num ) << 16l ) tomwalters@0: #define SCALAR( _num ) ( ( _num ) * ( 1l << 16l ) + 0.5 ) tomwalters@0: #define DESCALE( _num ) ( (long) ( _num ) >> 16l ) tomwalters@0: #define UNSCALE( _num ) ( ( _num ) / (float) ( 1l << 16l ) ) tomwalters@0: tomwalters@0: #endif