Helper to simultaneously calculate sin and cos of the same angle. More...
#include <sincos.h>
Public Member Functions | |
sincos (double x) | |
Calculate sine and cosine of x. | |
double | apply (double a, double b) const |
| |
double | apply2 (double a, double b, double c) const |
| |
Public Attributes | |
double | sn |
| |
double | cs |
|
Helper to simultaneously calculate sin and cos of the same angle.
Instantiate an instance of this object, passing the angle to the constructor. The sin and cos are then available as the sn and cs members. In addition, the apply() method may be used to calculate a*sin(x) + b*cos(x).
Implementation notes:
The i386/x87 architecture has an instruction to do this. So, on that platform, we use that instruction directly. It seems to be a win to use it even if we're using SSE math, so we'll use it for x86_64 too. Otherwise, we'll use sincos() if it's available (it's a GNU extension). Otherwise, just call sin() and cos() separately.
Note that the fsincos instruction only works correctly if the input angle is in the range -2^63 ... 2^63. This is not likely to be an issue for us.
Why prefer using the fsincos instruction directly to calling the sincos() library function?
sincos sc (ang); double a = sc.apply (x, y)
can be calculated entirely in the FPU register file, with no spills.