summaryrefslogtreecommitdiff
path: root/generate_table.c
diff options
context:
space:
mode:
Diffstat (limited to 'generate_table.c')
-rw-r--r--generate_table.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/generate_table.c b/generate_table.c
new file mode 100644
index 0000000..c7a9d0c
--- /dev/null
+++ b/generate_table.c
@@ -0,0 +1,34 @@
1#include <math.h>
2#include <stdio.h>
3#include <stdlib.h>
4
5// s(-1) n(14) off(+1) x = x - ( x >> 14 )
6// s( 1) n(-4) off( 0) x = ( x << 4 )
7// s( 1) n( 8) off(-1) x = - x + ( x << 8 )
8
9int main() {
10 int n, m, nsign;
11
12 // loop over all constructs in the form +-1*x^+-2n, n=-31..+31
13 for (n=-31; n<= 31; ++n )
14 for ( nsign=-1; nsign<=1; nsign+=2 )
15 {
16 // The one term only case
17 double v = (double)nsign * pow( 2.f, (double)n );
18 if( v > 0.f )
19 printf( "%0+25.21lf %08X x = %s ( x %s %2d )%s\n", log(v), abs((int)(67108864.f*log(v))), nsign==-1?"-":" ", n>=0?"<<":">>", (int)abs(n), " !RECOMMENDED!" );
20
21 // Loop over second term
22 for (m=-31; m<=31; ++m )
23 {
24 double v = pow( 2.f, (double)m ) + (double)nsign * pow( 2.f, (double)n );
25 if( v > 0.f ) {
26 printf( "%0+25.21lf %08X x = ( x %s %2d ) %s ( x %s %2d )%s\n", log(v), abs((int)(67108864.f*log(v))), m>=0?"<<":">>", (int)abs(m), nsign==-1?"-":"+", n>=0?"<<":">>", (int)abs(n), n*m?"":" !RECOMMENDED!" );
27 if( v < 1.f )
28 printf( "%0+25.21lf %08X x-= ( x %s %2d ) %s ( x %s %2d )\n", log(1.0f - v), abs((int)(67108864.f*log(1.0f - v))), m>=0?"<<":">>", (int)abs(m), nsign==-1?"-":"+", n>=0?"<<":">>", (int)abs(n) );
29 }
30 }
31 }
32
33 return 0;
34}