This commit is contained in:
Miloslav Ciz 2025-02-15 17:03:53 +01:00
parent 8ffe198bf4
commit 580a061146
11 changed files with 1902 additions and 1899 deletions

21
sin.md
View file

@ -183,23 +183,28 @@ Mainstream way of implementing [floating point](float.md) sine (but potentially
*sin(x) = x/1! - x^(3)/3! + x^(5)/5! - x^(7)/7! + ...*
Here is a simple implementation using fixed number of terms, which nonetheless gives quite precise results:
Here is a simple implementation using fixed number of terms, which gives quite precise results:
```
double sinF(double x)
{
#define _PI 3.141593
if (x < 0)
// adjust argument:
if (x < -1 * _PI / 2)
x = -1 * x + _PI;
int part = (2 * x) / _PI;
x -= part * _PI / 2;
if (part % 2)
x = _PI / 2 - x;
if (x > _PI / 2)
{
x -= _PI / 2;
int part = x / _PI;
x -= part * _PI;
x = (part % 2) ? (-1 * _PI / 2 + x) : (_PI / 2 - x);
}
#undef _PI
// Taylor series:
double x2 = x * x, r = x;
x *= x2;