CORDIC3C.ODE.TXT

From paul@torch.UUCP Tue May 31 09:30:22 1988
Path: beowulf!steinmetz!uunet!mcvax!ukc!stc!datlog!torch!paul
From: paul@torch.co.uk (Paul Andrews)
Newsgroups: comp.graphics
Subject: Re: Request for CORDIC algorithm info
Message-ID: <198@torch.co.uk>
Date: 31 May 88 13:30:22 GMT
References: <354@abvax.UUCP>
Reply-To: paul@torch.UUCP (Paul Andrews)
Organization: TORCH Computers Ltd., Cambridge, United Kingdom
Lines: 86

In article <354@abvax.UUCP> gfs@abvax.UUCP (Greg F. Shay) writes:
>Ok, I'm interested.  In reply to my sin(x) in integer posting, a couple
>	Could someone either thumbnail sketch the CORDIC algorithm for me
>or give a reference?  Many Thanks.
>
>		Greg Shay
>...

I looked through my references and discovered that they were fairly useless.
Instead, here's some source that does ONE of the CORDIC transformations
i.e. the original one, the coordinate rotation. Note that the same method
generalises to do the following transformations also:

sin, cos, tan, atan, sinh, cosh, tanh, atanh, exp, ln, root.

The author of the best paper I know on this is J.S.Walther, unfortunately
I can't give you the reference.

I would've mailed this but we've yet to sort our mail out...

- Paul.

-------- Cut here ---------

/* -------Forward declarations-----------------------*/

/* -------Constants and macros-----------------------*/

#define KR   107922      /* constant */

/* -------Exported variables/functions---------------*/

/* -------Imported variables/functions---------------*/

/* -------Static variables---------------------------*/

static int arctan [] =  /* Table of atans in degrees << 16 */
{
   2949120, 1740967, 919879, 466945,
   234378, 117303, 58666, 29335,
   14668, 7334, 3667, 1833,
   918, 458, 229, 115
};

/*                                                                *************
                                                                  *           *
                                                                  *  CORDIC   *
                                                                  *           *
                                                                  *************
-------------------------------------------------------------------------------
| Perform a cordic transformation on the arguments                            |
| The value returned is b*cos(theta) + a*sin(theta).                          |
| theta is an angle in the range 0 - 90 degrees.                              |
-------------------------------------------------------------------------------
*/
Cordic(a, b, theta)
register int a, b, theta;
{
   register int olda, i;

   a <<= 8;
   b <<= 8;
   theta <<= 16;
   for (i = 0; i < 16; i++)   /* do this to 16 bits */
   {
      olda = a >> i;
      if (theta < 0)
      {
         a += (b >> i);
         b -= olda;
         theta += arctan [i];
      }
      else 
      {
         a -= (b >> i);
         b += olda;
         theta -= arctan [i];
      }
   }
      /* The value returned is b*cos(theta) + a*sin(theta) */
      /* a*sin(theta) if initial b was 0 */
      /* b*cos(theta) if initial a was 0 */
   return ((b << 8) / KR);
      /* We are throwing a away, though it contains : */
      /* a*cos(theta) - b*sin(theta) */
}


�