Search code examples
mathcordic

multiply of cordic issue


this is cordic multiply function I got a code when I run across from internet. But It's quite a bit different from expected data. How to modify to have this code with correctness?

update code

 for (i=1; i=<8; i++)
 { 
  if (x > 0) {
   x = x - pow(2,-i);
   z = z + y*pow(2,-i);
   }
   else{
   x = x + pow(2,-i);
   z = z - y* pow(2,-i);
  }

If I do run with x=7, y=8 then z=7.000 not 56.

What is the wrong point?

update2

I got the right answer but Thnaks, I have checked the range it works. Bytheway, is there any extension range algorithm? How to make range extension?


Solution

  • It looks like you took this function from this paper (without attribution!). The code is full of obvious typos, but if you read the paragraph below the function it says:

    This calculation assumes that both x and y are fractional ranging from -1 to 1. The algorithm is valid for other ranges as long as the decimal point is allowed to float. With a few extensions, this algorithm would work well with floating point data.

    Take home message: always read the accompanying documentation for any code that you plan to use, especially if you don't understand how it works.