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