Why do sin(45) and cos(45) give different results? [duplicate]

I know I will never get a 100% precise value of these numbers, but AT LEAST I was expecting to get the same “unprecise” value of sin and cos of complementary angles.

Why? The are calculated differently, so different floating point errors will occur (and accumulate). What you see is not an error; FP arithmetic isn’t predictable by math laws.

Btw., providing eg. 30 or 100 digits of PI won’t be anything different
if your type can’t hold 30 digits in the first place.

Leave a Comment