CxxUtils::sincos Struct Reference

Helper to simultaneously calculate sin and cos of the same angle. More...

#include <sincos.h>

List of all members.

Public Member Functions

 sincos (double x)
 Calculate sine and cosine of x.
double apply (double a, double b) const
 $a\sin(x) + b\cos(x)$
double apply2 (double a, double b, double c) const
 $a\sin^2(x) + b\sin(x)\cos(x) + c\cos^2(x)$

Public Attributes

double sn
 $\sin(x)$
double cs
 $\cos(x)$

Detailed Description

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.


The documentation for this struct was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 15 Apr 2017 for RootCore Packages by  doxygen 1.6.1