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 78 of file sincos.h.

81  { __asm __volatile__ ("fsincos\n\t" : "=t" (cs), "=u" (sn) : "0" (x)); }
82 #elif defined(__USE_GNU)
83  // Version using the GNU sincos() function.
84  { ::sincos(x, &sn, &cs); }
85 #else
86  // Generic version.
87  : 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 97 of file sincos.h.

97 { 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 100 of file sincos.h.

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

Member Data Documentation

◆ cs

double CxxUtils::sincos::cs

\(\cos(x)\)

Definition at line 94 of file sincos.h.

◆ sn

double CxxUtils::sincos::sn

\(\sin(x)\)

Definition at line 91 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:78
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
x
#define x
CxxUtils::sincos::cs
double cs
Definition: sincos.h:94
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CxxUtils::sincos::sn
double sn
Definition: sincos.h:91
a
TList * a
Definition: liststreamerinfos.cxx:10
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
python.compressB64.c
def c
Definition: compressB64.py:93