annotate 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
rev   line source
tomwalters@0 1 /*
tomwalters@0 2 calc.h
tomwalters@0 3 ======
tomwalters@0 4
tomwalters@0 5 definitions to make model source portable across calculation type.
tomwalters@0 6 Used fixed point representation for real numbers in integer machines.
tomwalters@0 7
tomwalters@0 8 Type names:
tomwalters@0 9 DataType - type used to pass results between modules
tomwalters@0 10 EG. usually a short.
tomwalters@0 11 StoreType - type used to store an intermediate result within a module
tomwalters@0 12 ScalarType - type used to store fixed-point multipliers
tomwalters@0 13
tomwalters@0 14 Integer arithmetic:
tomwalters@0 15
tomwalters@0 16 SCALE - convert to fixed point
tomwalters@0 17 SCALAR- float to fixed to fixed point multiplier
tomwalters@0 18 (Used to create a value for a ScalarType).
tomwalters@0 19 DESCALE - convert back to int (opposite of SCALE).
tomwalters@0 20
tomwalters@0 21 UNSCALE - convert fixed point back to float.
tomwalters@0 22
tomwalters@0 23 Use int instead float to get fixed point arithmetic, but shift
tomwalters@0 24 numbers to preserve the significant digits, EG for multiplication:
tomwalters@0 25 use SCALAR on one operand (which will then be a ScalarType)
tomwalters@0 26 use DESCALE on the result
tomwalters@0 27 */
tomwalters@0 28
tomwalters@0 29 #if 1 /* Switch to convert whole model to floating point */
tomwalters@0 30 #define FLOAT float /* version (default uses integer arithmetic) */
tomwalters@0 31 #endif
tomwalters@0 32
tomwalters@0 33 #ifdef DSP32
tomwalters@0 34 #define FLOAT float
tomwalters@0 35 #endif
tomwalters@0 36
tomwalters@0 37
tomwalters@0 38 #ifdef FLOAT
tomwalters@0 39
tomwalters@0 40 typedef FLOAT ScalarType ;
tomwalters@0 41 typedef FLOAT StoreType ;
tomwalters@0 42 typedef FLOAT DataType ;
tomwalters@0 43
tomwalters@0 44 #define SCALE( _num ) ( _num )
tomwalters@0 45 #define SCALAR( _num ) ( _num )
tomwalters@0 46 #define DESCALE( _num ) ( _num )
tomwalters@0 47 #define UNSCALE( _num ) ( _num )
tomwalters@0 48
tomwalters@0 49 #else
tomwalters@0 50
tomwalters@0 51 typedef long ScalarType ;
tomwalters@0 52 typedef long StoreType ;
tomwalters@0 53 typedef short DataType ;
tomwalters@0 54
tomwalters@0 55 #define SCALE( _num ) ( (long) ( _num ) << 16l )
tomwalters@0 56 #define SCALAR( _num ) ( ( _num ) * ( 1l << 16l ) + 0.5 )
tomwalters@0 57 #define DESCALE( _num ) ( (long) ( _num ) >> 16l )
tomwalters@0 58 #define UNSCALE( _num ) ( ( _num ) / (float) ( 1l << 16l ) )
tomwalters@0 59
tomwalters@0 60 #endif