This commit is contained in:
Miloslav Ciz 2025-08-16 19:22:10 +02:00
parent a64b3eb7a9
commit e2ad87ccf9
10 changed files with 1967 additions and 1955 deletions

2
sin.md
View file

@ -78,7 +78,7 @@ In [programming languages](programming_language.md) the sine function is general
**Want to make your own sine function for whatever reason (performance, curiosity, ...)?** Then firstly consider what you expect from it. If you want a small, fast and perhaps integer only `sin` function (the one we'd prefer in [LRS](lrs.md)) that doesn't need extreme accuracy, consider using a **[look up table](lut.md)**. You simply precompute the values of the sine function into a static table in memory and the function just retrieves them when called -- this is super fast. Note that you can save a lot of space by **only storing sine values between 0 and 1/2 pi**, the remaining parts of the function are just different transformations of this part. You can further save space and/or make the function work with [floats](float.md) by further [interpolating](interpolation.md) (even just linearly) between the stored values, for example if `sin(3.45)` is called and you only have values stored for `sin(3.4)` and `sin(3.5)`, you simply average them.
Lot of times, e.g. in many calculators where speed isn't really critical, sine is computed using [Taylor series](taylor_series.md) -- a sum of infinitely many terms of which if we take the first *N*, we get an [approximation](approximation.md) of the function (the more terms we add, the more precise we get). For sine the series is
Lot of times, e.g. in many calculators where speed isn't really critical, sine is computed using [Taylor series](taylor_series.md) (no, it's not named after Taylor Swift) -- a sum of infinitely many terms of which if we take the first *N*, we get an [approximation](approximation.md) of the function (the more terms we add, the more precise we get). For sine the series is
*sin(x) = x - x^3 / 3! + x^5 / 5! - x^7 / 7! + ...*