T
T
TreShk02018-08-01 11:07:51
Mathematics
TreShk0, 2018-08-01 11:07:51

Algorithm for finding the sine of any angle?

Is there any algorithm for finding the sine, cosine, tangent of any angle. The same one used by calculators

Answer the question

In order to leave comments, you need to log in

6 answer(s)
R
Rsa97, 2018-08-01
@Rsa97

What kind of accuracy is needed. There is a Bhaskar formula that works on the range from 0° to 180° (0-π):
sin(x°) = 4 x (180−x)/(40500−x (180−x))
sin(x) = 16 x (π−x)/(5 π 2 −4 x (π−x))
Over most of the range, it gives an accuracy within 0.2%, at the edges the accuracy drops to 2%.
Values ​​for angles outside this range can be obtained from the identity:
sin(2 π+x) = sin(x)
sin(π+x) = -sin(x)

R
res2001, 2018-08-01
@res2001

Taylor series
And not only for sine.

R
Ruslan., 2018-08-01
@LaRN

Sometimes a tabular method is used for speed.
Those. create a table in memory with calculated function values ​​(with the required accuracy)
for some fixed angle step.
If we get between the grid nodes of the angle table, then we use interpolation.

A
Alexander Skusnov, 2018-08-01
@AlexSku

1) in the arithmetic coprocessor, the length of fractional numbers is 10 bytes, not 8 (double), so the accuracy is higher.
2) Fourier series are difficult to apply, because the factorial (in the denominator of each fraction) grows rapidly.
3) there is a CORDIC method, which can calculate any accuracy from a small table.
4) I heard at the video seminar that Chebyshev polynomials are most likely used (know ours!)

V
Vladimir Proskurin, 2018-08-01
@Vlad_IT

Google - an approximate calculation of the sine (substitute the one you need).
The fact is that there is no clear formula for finding the values ​​of these functions, there are only approximate ones that can be calculated with a given accuracy, the higher the accuracy, the longer it will take to calculate.

A
Aenigma, 2021-09-24
@Aenigma

The fastest and most accurate, but not economical, is the interpolation method in the table. However, there are more economical and almost equally fast (and, possibly, faster) methods for calculating transcendental functions - these are approximations by the Chebyshev and Padé-Chebyshev method. The performance of the respective algorithms will depend on the required accuracy. For example, to approximate trigonometric functions with single precision (7-8 significant decimal digits) using the Chebyshev method, as a rule, it is sufficient to use a polynomial with 5 terms. Its calculation is so fast that it can outperform the table method. To calculate functions with double and higher precision, the best results are achieved by the Padé-Chebyshev method (approximation by a fractional rational function).
An additional advantage of these methods is that with the help of vector commands it is easy to do, for example, parallel calculation of the sine and cosine of one argument. In the Pade-Chebyshev method, using vector instructions, it is possible to calculate the numerator and denominator of a function in parallel, which almost doubles the performance. I tested the performance of a Padé-Chebyshev double-precision natural logarithm function, it outperformed a standard library function. Single precision is even faster.
As an example, here is a link to a quick function for calculating the tangent in degrees with single precision using the Chebyshev method (post dated 2021-09-20 13:12:22):
https://codengineering.ru/q/bystraya-realizaciya-t.. .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question