In C library math.h
, there was a sincos
function which was pretty efficient, because it computed both sine and cosine in a time closer to a single call to sin()
or cos()
than to the total time of calling both.
Is there such function in C++ standard library?
Just use sin and cos separately and turn on optimizations. C compilers are pretty good at optimizing, and they will probably realize that you are computing both the sine and cosine of the same variable. If you want to make sure, you can allways inspect the resulting assembly (for gcc use the -S option) and see what did it generate.
The compiler will probably optimize away any calls to
sin
orcos
in favour of simply using SSE intructions to calculate it. I'm not sure SSE has asincos
opcode but even calculating them separatly is faster than calling anysincos
function that the compiler won't optimize out.No, unfortunately there isn't.
On Linux, it is available as GNU Extension. It's not standard in C either.