summaryrefslogtreecommitdiff
path: root/generate_table.c
blob: c7a9d0cd62f12376ee083dfc5f1c1a11c049d5ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

// s(-1) n(14) off(+1)   x =   x - ( x >> 14 )
// s( 1) n(-4) off( 0)   x =       ( x <<  4 )
// s( 1) n( 8) off(-1)   x = - x + ( x <<  8 )

int main() {
  int n, m, nsign;

  // loop over all constructs in the form +-1*x^+-2n, n=-31..+31
  for (n=-31; n<= 31; ++n )
    for ( nsign=-1; nsign<=1; nsign+=2 )
    {
      // The one term only case
      double v = (double)nsign * pow( 2.f, (double)n );
      if( v > 0.f )
          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!" );

      // Loop over second term
      for (m=-31; m<=31; ++m )
      {
        double v = pow( 2.f, (double)m ) + (double)nsign * pow( 2.f, (double)n );
        if( v > 0.f ) {
          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!" );
          if( v < 1.f )
              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) );
        }
      }
    }

  return 0;
}