Why is the implementation of computing both sine and cosine at the same time about the same speed as just computing one of them?

188 viewsMathematicsOther

Was messing around with C and found this quirk. How does this function work so quickly? How is it implemented?

In: Mathematics

3 Answers

Anonymous 0 Comments

Be aware that at least the Intel x86 architecture has an FSINCOS instruction. The ELI5 of that is that the CPU does the hard work in a single operation, meaning the C function isn’t doing anything interesting. FSINCOS is faster than running both FSIN and FCOS.

Of course the CPU isn’t magic and must be doing similar things internally to what a C function would be doing, although more efficiently. There is some commonality in computing the sine and cosine which both CPU instructions of C functions can take advantage of. The details depend on how they’re implemented.

You are viewing 1 out of 3 answers, click here to view all answers.