ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
CxxUtils::sincos Struct Reference

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

#include <sincos.h>

Collaboration diagram for CxxUtils::sincos:

Public Member Functions

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

Public Attributes

double sn
 \(\sin(x)\) More...
 
double cs
 \(\cos(x)\) More...
 

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?

Definition at line 75 of file sincos.h.

Constructor & Destructor Documentation

◆ sincos()

CxxUtils::sincos::sincos ( double  x)
inline

Calculate sine and cosine of x.

Definition at line 79 of file sincos.h.

82  { __asm __volatile__ ("fsincos\n\t" : "=t" (cs), "=u" (sn) : "0" (x)); }
83 #elif defined(__USE_GNU)
84  // Version using the GNU sincos() function.
85  { ::sincos(x, &sn, &cs); }
86 #else
87  // Generic version.
88  : sn (std::sin (x)), cs (std::cos (x)) {}

Member Function Documentation

◆ apply()

double CxxUtils::sincos::apply ( double  a,
double  b 
) const
inline

\(a\sin(x) + b\cos(x)\)

Definition at line 98 of file sincos.h.

98 { return a*sn + b*cs; }

◆ apply2()

double CxxUtils::sincos::apply2 ( double  a,
double  b,
double  c 
) const
inline

\(a\sin^2(x) + b\sin(x)\cos(x) + c\cos^2(x)\)

Definition at line 101 of file sincos.h.

102  { return a*sn*sn + b*sn*cs + c*cs*cs; }

Member Data Documentation

◆ cs

double CxxUtils::sincos::cs

\(\cos(x)\)

Definition at line 95 of file sincos.h.

◆ sn

double CxxUtils::sincos::sn

\(\sin(x)\)

Definition at line 92 of file sincos.h.


The documentation for this struct was generated from the following file:
CxxUtils::sincos::sincos
sincos(double x)
Calculate sine and cosine of x.
Definition: sincos.h:79
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
x
#define x
CxxUtils::sincos::cs
double cs
Definition: sincos.h:95
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CxxUtils::sincos::sn
double sn
Definition: sincos.h:92
a
TList * a
Definition: liststreamerinfos.cxx:10
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
python.compressB64.c
def c
Definition: compressB64.py:93