Mercurial > hg > aim92
view model/calc.h @ 0:5242703e91d3 tip
Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 15:19:45 +0100 |
parents | |
children |
line wrap: on
line source
/* calc.h ====== definitions to make model source portable across calculation type. Used fixed point representation for real numbers in integer machines. Type names: DataType - type used to pass results between modules EG. usually a short. StoreType - type used to store an intermediate result within a module ScalarType - type used to store fixed-point multipliers Integer arithmetic: SCALE - convert to fixed point SCALAR- float to fixed to fixed point multiplier (Used to create a value for a ScalarType). DESCALE - convert back to int (opposite of SCALE). UNSCALE - convert fixed point back to float. Use int instead float to get fixed point arithmetic, but shift numbers to preserve the significant digits, EG for multiplication: use SCALAR on one operand (which will then be a ScalarType) use DESCALE on the result */ #if 1 /* Switch to convert whole model to floating point */ #define FLOAT float /* version (default uses integer arithmetic) */ #endif #ifdef DSP32 #define FLOAT float #endif #ifdef FLOAT typedef FLOAT ScalarType ; typedef FLOAT StoreType ; typedef FLOAT DataType ; #define SCALE( _num ) ( _num ) #define SCALAR( _num ) ( _num ) #define DESCALE( _num ) ( _num ) #define UNSCALE( _num ) ( _num ) #else typedef long ScalarType ; typedef long StoreType ; typedef short DataType ; #define SCALE( _num ) ( (long) ( _num ) << 16l ) #define SCALAR( _num ) ( ( _num ) * ( 1l << 16l ) + 0.5 ) #define DESCALE( _num ) ( (long) ( _num ) >> 16l ) #define UNSCALE( _num ) ( ( _num ) / (float) ( 1l << 16l ) ) #endif