Commit 33b03619 authored by Akarsh Simha's avatar Akarsh Simha
Browse files

Revert "Experiment 1: Can we cache trig values during first computation?"

This reverts commit 11bb5cf4f213277437d7a9b503b49627fe6a0d19.
parent 2d4f65a2
......@@ -34,7 +34,6 @@ double dms::seconds_in_trig = 0;
void dms::setD(const int &d, const int &m, const int &s, const int &ms) {
D = (double)abs(d) + ((double)m + ((double)s + (double)ms/1000.)/60.)/60.;
if (d<0) {D = -1.0*D;}
m_s = m_c = NaN::d;
#ifdef COUNT_DMS_SINCOS_CALLS
m_cosDirty = m_sinDirty = true;
#endif
......@@ -50,7 +49,6 @@ void dms::setH( const double &x ) {
void dms::setH(const int &h, const int &m, const int &s, const int &ms) {
D = 15.0*((double)abs(h) + ((double)m + ((double)s + (double)ms/1000.)/60.)/60.);
if (h<0) {D = -1.0*D;}
m_s = m_c = NaN::d;
#ifdef COUNT_DMS_SINCOS_CALLS
m_cosDirty = m_sinDirty = true;
#endif
......
......@@ -53,7 +53,6 @@ public:
#ifdef COUNT_DMS_SINCOS_CALLS
, m_sinCosCalled(false), m_sinDirty( true ), m_cosDirty( true )
#endif
, m_s( NaN::d ), m_c( NaN::d )
{
#ifdef COUNT_DMS_SINCOS_CALLS
++dms_constructor_calls;
......@@ -66,16 +65,15 @@ public:
* @param s arcsecond portion of angle (int). Defaults to zero.
* @param ms arcsecond portion of angle (int). Defaults to zero.
*/
explicit dms( const int &d, const int &m=0, const int &s=0, const int &ms=0 ) :
explicit dms( const int &d, const int &m=0, const int &s=0, const int &ms=0 )
#ifdef COUNT_DMS_SINCOS_CALLS
m_sinCosCalled(false), m_sinDirty( true ), m_cosDirty( true ),
: m_sinCosCalled(false), m_sinDirty( true ), m_cosDirty( true )
#endif
m_s( NaN::d ), m_c( NaN::d )
{ setD( d, m, s, ms );
#ifdef COUNT_DMS_SINCOS_CALLS
++dms_constructor_calls;
#endif
}
}
/** @short Construct an angle from a double value.
*
......@@ -86,7 +84,6 @@ public:
#ifdef COUNT_DMS_SINCOS_CALLS
, m_sinCosCalled(false), m_sinDirty( true ), m_cosDirty( true )
#endif
, m_s( NaN::d ), m_c( NaN::d )
{
#ifdef COUNT_DMS_SINCOS_CALLS
++dms_constructor_calls;
......@@ -106,11 +103,10 @@ public:
* @param isDeg if true, value is in degrees; if false, value is in hours.
* @sa setFromString()
*/
explicit dms( const QString &s, bool isDeg=true ) :
explicit dms( const QString &s, bool isDeg=true )
#ifdef COUNT_DMS_SINCOS_CALLS
m_sinCosCalled(false), m_sinDirty( true ), m_cosDirty( true ),
: m_sinCosCalled(false), m_sinDirty( true ), m_cosDirty( true )
#endif
m_s( NaN::d ), m_c( NaN::d )
{ setFromString( s, isDeg );
#ifdef COUNT_DMS_SINCOS_CALLS
++dms_constructor_calls;
......@@ -174,9 +170,7 @@ public:
#ifdef COUNT_DMS_SINCOS_CALLS
m_sinDirty = m_cosDirty = true;
#endif
m_s = m_c = NaN::d;
D = x;
}
D = x; }
/** @short Sets floating-point value of angle, in degrees.
*
......@@ -254,17 +248,15 @@ public:
#endif
#ifdef PROFILE_SINCOS
std::clock_t start, stop;
double s;
start = std::clock();
#endif
if( std::isnan( m_s ) )
m_s = ::sin(D*DegToRad);
#ifdef PROFILE_SINCOS
s = ::sin(D*DegToRad);
stop = std::clock();
seconds_in_trig += double(stop - start)/double(CLOCKS_PER_SEC);
return s;
#else
return ::sin(D*DegToRad);
#endif
Q_ASSERT( !std::isnan( m_s ) );
return m_s;
}
/** @short Compute the Angle's Cosine.
......@@ -283,17 +275,15 @@ public:
#endif
#ifdef PROFILE_SINCOS
std::clock_t start, stop;
double c;
start = std::clock();
#endif
if( std::isnan( m_c ) )
m_c = ::cos(D*DegToRad);
#ifdef PROFILE_SINCOS
c = ::cos(D*DegToRad);
stop = std::clock();
seconds_in_trig += double(stop - start)/double(CLOCKS_PER_SEC);
return c;
#else
return ::cos(D*DegToRad);
#endif
Q_ASSERT( !std::isnan( m_c ) );
return m_c;
}
/** @short Express the angle in radians.
......@@ -362,7 +352,6 @@ public:
#endif
private:
double D;
mutable double m_s, m_c; // Trigonometric functions
#ifdef COUNT_DMS_SINCOS_CALLS
mutable bool m_sinDirty, m_cosDirty, m_sinCosCalled;
#endif
......@@ -391,24 +380,17 @@ inline void dms::SinCos(double& s, double& c) const {
#ifdef __GLIBC__
#if ( __GLIBC__ >= 2 && __GLIBC_MINOR__ >=1 && !defined(__UCLIBC__))
//GNU version
if( std::isnan( m_s ) || std::isnan( m_c ) )
sincos( radians(), &m_s, &m_c );
sincos( radians(), &s, &c );
#else
//For older GLIBC versions
if( std::isnan( m_s ) )
m_s = ::sin( radians() );
if( std::isnan( m_c ) )
m_c = ::cos( radians() );
s = ::sin( radians() );
c = ::cos( radians() );
#endif
#else
//ANSI-compliant version
if( std::isnan( m_s ) )
m_s = ::sin( radians() );
if( std::isnan( m_c ) )
m_c = ::cos( radians() );
s = ::sin( radians() );
c = ::cos( radians() );
#endif
s = m_s; c = m_c;
Q_ASSERT( !std::isnan( m_s ) && !std::isnan( m_c ) );
#ifdef PROFILE_SINCOS
stop = std::clock();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment