Floating point cosine

I am trying to implement cosine and sine functions in floating point (but I do not have floating point equipment).

Since my processor does not have floating point hardware or instructions, I have already implemented algorithms for floating point multiplication, division, addition, subtraction, and square root. So, those tools that I have are available for implementing cosine and sine.

I was considering using the CORDIC method on this site. However, I implemented split and square root using the newton method, so I was hoping to use the most efficient method.

Please do not tell me that I just looked in the book or that "paper exists", do not joke that they exist. I am looking for the names of well-known algorithms that are known to be fast and efficient.

+6
source share
3 answers

First of all, depending on your accuracy requirements, this can be significantly more complex than your previous questions.

Now that you have been warned: first you want to reduce the modulo pi / 2 argument (or 2pi, or pi or pi / 4) to get input in a controlled range. This is the subtle part. For a pleasant discussion of the issues raised, download a copy of KC NG. REDUCING ARGUMENTS FOR HUGE ARGUMENTS: Good for the last bit. (a simple google search on the title will give you a pdf file). It is very readable and perfectly describes why it is difficult.

After that, you only need to approximate the functions in a small range around zero, which is easy to do using the polynomial approximation. The Taylor series will work, although it is inefficient. The truncated series of Chebyshev is easy to calculate and reasonably effective; calculating the minimax approximation is even better. This is the easy part.

I implemented sine and cosine exactly as described, entirely in the integer, in the past (sorry, not public sources). Using manual assembly, results in the vicinity of 100 cycles are quite reasonable for "typical" processors. I don’t know what equipment you are facing (performance will mainly depend on how quickly your equipment can generate most of the integer multiplication).

+4
source

For various levels of accuracy, you can find good approximations here:

http://www.ganssle.com/approx.htm

With the added advantage that they are determined at run time, as opposed to the different versions of “converging rows”, which can vary greatly depending on the input value. It matters if you do something in real time (games, motion control, etc.).

+1
source

Since you have basic arithmetic operations, you can also implement sine and cosine using their taylor series extensions.

-1
source

Source: https://habr.com/ru/post/908358/


All Articles