Mercurial > hg > aim92
comparison filter/imb.c @ 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 imb.c | |
3 ===== | |
4 | |
5 integer version of logarithms using units of milliBells. | |
6 | |
7 */ | |
8 | |
9 #include <math.h> | |
10 | |
11 #include "stitch.h" | |
12 | |
13 #define LOG_ZERO (-10) | |
14 | |
15 int imB( number ) | |
16 long number ; | |
17 { | |
18 register int i, out ; | |
19 register long in ; | |
20 static int precision = 12 ; | |
21 static int *table = { ( int * ) 0 } ; | |
22 static unsigned table_size ; | |
23 static int inc ; | |
24 double k ; | |
25 | |
26 if( table == ( int * ) 0 ) { | |
27 | |
28 table_size = 1 << precision ; | |
29 | |
30 k = 2000. / log( 10. ) ; | |
31 inc = k * log( 2. ) + 0.5 ; | |
32 | |
33 table = (int *) stitch_malloc( table_size * sizeof( *table ), "imb.c for log table" ) ; | |
34 | |
35 for( i=0 ; i < table_size ; i++ ) | |
36 table[ i ] = log( (double) ( table_size + i ) / table_size ) * k + 0.5 ; | |
37 } | |
38 | |
39 if( number > 0 ) { | |
40 | |
41 in = number ; | |
42 | |
43 out = precision * inc ; | |
44 | |
45 if( number < table_size ) | |
46 do { | |
47 in <<= 1 ; | |
48 out -= inc ; | |
49 } | |
50 while( in < table_size ) ; | |
51 else | |
52 while( in - table_size >= table_size ) { | |
53 in >>= 1 ; | |
54 out += inc ; | |
55 } | |
56 | |
57 return( out + table[ in - table_size ] ) ; | |
58 } | |
59 else | |
60 return ( LOG_ZERO ) ; | |
61 } | |
62 |