Live data from Hacker News

How do computers calculate sine?

androidcalculator.com

1–10 of 167 posts

Re: How do computers calculate sine?

#6
I've seen the third order Taylor series used, but with the coefficients calculated at various offsets for a quarter wave. So you lookuo where you are in the quarter wave, then look up the 3 or 4 cofficients. This keeps the error somewhat bounded as the size of X is a small so the series does not diverge too much.

Re: How do computers calculate sine?

#9
post #4

sine is easy because the series is globally convergent and fast converging

Did you read the article? It is specifically about how the series looks simple, but the error is actually very bad if you do things naively.

That still makes it easier compared to computing constants in which the series are not globally convergent, like inverse trig functions. Obviously, you would have to break it apart to speed convergence.

Re: How do computers calculate sine?

#10
This made me realize that trigonometric functions are not deterministic across different CPU architectures, OS, and programming languages (floating point precision aside).

E.g. I would assume that Math.sin(x) returns the same thing in NodeJS on Windows and Mac/M1, but it turns out it is necessarily so. https://stackoverflow.com/questions/74074312/standard-math-f...

Post reply on HN