summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-09-25 01:50:09 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-09-28 22:16:21 (GMT)
commit33b036190697d614c9f822f700350022461bd089 (patch)
treeb688380cbf699fe1fa1d5f8c674a1b3cc2aa51e6
parent2d4f65a20b3da0bc7c8123a11da316c07d8b4b5c (diff)
Revert "Experiment 1: Can we cache trig values during first computation?"
This reverts commit 11bb5cf4f213277437d7a9b503b49627fe6a0d19.
-rw-r--r--kstars/auxiliary/dms.cpp2
-rw-r--r--kstars/auxiliary/dms.h60
2 files changed, 21 insertions, 41 deletions
diff --git a/kstars/auxiliary/dms.cpp b/kstars/auxiliary/dms.cpp
index 33a1f70..b457be1 100644
--- a/kstars/auxiliary/dms.cpp
+++ b/kstars/auxiliary/dms.cpp
@@ -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
diff --git a/kstars/auxiliary/dms.h b/kstars/auxiliary/dms.h
index 2945f3d..b07fbab 100644
--- a/kstars/auxiliary/dms.h
+++ b/kstars/auxiliary/dms.h
@@ -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();