[Kstars-devel] [kstars/bleeding-edge] kstars: Initialize dms to NaN, and not zero. This unearthed the last two bugs
Akarsh Simha
akarsh.simha at kdemail.net
Sun Mar 17 03:15:38 UTC 2013
Git commit 89ac1b8731fad0c43b84e63e3ace8045b3fa0517 by Akarsh Simha.
Committed on 17/03/2013 at 04:14.
Pushed by asimha into branch 'bleeding-edge'.
Initialize dms to NaN, and not zero. This unearthed the last two bugs
that were fixed, but there could be many more yet undiscovered bugs,
and bugs introduced by this change as well.
So watch out for NaNsense in the results of a computation!
CCMAIL: kstars-devel at kde.org
M +10 -10 kstars/dms.cpp
M +7 -3 kstars/dms.h
M +1 -1 kstars/skyobjects/skypoint.cpp
M +7 -2 kstars/skyobjects/starobject.cpp
http://commits.kde.org/kstars/89ac1b8731fad0c43b84e63e3ace8045b3fa0517
diff --git a/kstars/dms.cpp b/kstars/dms.cpp
index f1ca8e1..f49e10d 100644
--- a/kstars/dms.cpp
+++ b/kstars/dms.cpp
@@ -55,7 +55,7 @@ bool dms::setFromString( const QString &str, bool isDeg ) {
//empty entry returns false
if ( entry.isEmpty() ) {
- setD( 0.0 );
+ setD( NaN::d );
return false;
}
@@ -85,7 +85,7 @@ bool dms::setFromString( const QString &str, bool isDeg ) {
//anything with one field is invalid!
if ( fields.count() == 1 ) {
- setD(0.0);
+ setD( NaN::d );
return false;
}
@@ -103,7 +103,7 @@ bool dms::setFromString( const QString &str, bool isDeg ) {
fields[1] = QString::number( int(mx) );
fields.append( QString::number( int( 60.0*(mx - int(mx)) ) ) );
} else {
- setD( 0.0 );
+ setD( NaN::d );
return false;
}
}
@@ -138,7 +138,7 @@ bool dms::setFromString( const QString &str, bool isDeg ) {
setH( D );
}
} else {
- setD( 0.0 );
+ setD( NaN::d );
return false;
}
@@ -150,7 +150,7 @@ int dms::arcmin( void ) const {
if ( D<0.0 && D>-1.0 ) { //angle less than zero, but greater than -1.0
am = -1*am; //make minute negative
}
- return am;
+ return am; // Warning: Will return 0 if the value is NaN
}
int dms::arcsec( void ) const {
@@ -159,7 +159,7 @@ int dms::arcsec( void ) const {
if ( degree()==0 && arcmin()==0 && D<0.0 ) {
as = -1*as;
}
- return as;
+ return as; // Warning: Will return 0 if the value is NaN
}
int dms::marcsec( void ) const {
@@ -168,7 +168,7 @@ int dms::marcsec( void ) const {
if ( degree()==0 && arcmin()==0 && arcsec()== 0 && D<0.0 ) {
as = -1*as;
}
- return as;
+ return as; // Warning: Will return 0 if the value is NaN
}
int dms::minute( void ) const {
@@ -176,7 +176,7 @@ int dms::minute( void ) const {
if ( Hours()<0.0 && Hours()>-1.0 ) { //angle less than zero, but greater than -1.0
hm = -1*hm; //make minute negative
}
- return hm;
+ return hm; // Warning: Will return 0 if the value is NaN
}
int dms::second( void ) const {
@@ -184,7 +184,7 @@ int dms::second( void ) const {
if ( hour()==0 && minute()==0 && Hours()<0.0 ) {
hs = -1*hs;
}
- return hs;
+ return hs; // Warning: Will return 0 if the value is NaN
}
int dms::msecond( void ) const {
@@ -192,7 +192,7 @@ int dms::msecond( void ) const {
if ( hour()==0 && minute()==0 && second()==0 && Hours()<0.0 ) {
hs = -1*hs;
}
- return hs;
+ return hs; // Warning: Will return 0 if the value is NaN
}
diff --git a/kstars/dms.h b/kstars/dms.h
index 22ffdee..b6423ae 100644
--- a/kstars/dms.h
+++ b/kstars/dms.h
@@ -18,10 +18,14 @@
#ifndef DMS_H_
#define DMS_H_
-#include <math.h>
-#include <qstring.h>
+#include "nan.h"
+
#include <kdebug.h>
+#include <QString>
+
+#include <cmath>
+
/**@class dms
* @short An angle, stored as degrees, but expressible in many ways.
* @author Jason Harris
@@ -39,7 +43,7 @@
class dms {
public:
/** Default constructor. */
- dms() : D(0) {}
+ dms() : D( NaN::d ) {}
/**@short Set the floating-point value of the angle according to the four integer arguments.
* @param d degree portion of angle (int). Defaults to zero.
diff --git a/kstars/skyobjects/skypoint.cpp b/kstars/skyobjects/skypoint.cpp
index 3bc5b83..09b2c41 100644
--- a/kstars/skyobjects/skypoint.cpp
+++ b/kstars/skyobjects/skypoint.cpp
@@ -326,7 +326,7 @@ void SkyPoint::updateCoords( KSNumbers *num, bool /*includePlanets*/, const dms
// places. Please be wary of changing one without changing the
// other.
- Q_ASSERT( isfinite( lastPrecessJD ) );
+ Q_ASSERT( std::isfinite( lastPrecessJD ) );
if( Options::useRelativistic() && checkBendLight() ) {
recompute = true;
diff --git a/kstars/skyobjects/starobject.cpp b/kstars/skyobjects/starobject.cpp
index fc5806a..1ae38f5 100644
--- a/kstars/skyobjects/starobject.cpp
+++ b/kstars/skyobjects/starobject.cpp
@@ -42,6 +42,8 @@
//QVector<SkyPoint *> StarObject::Trail;
// END DEBUG
+#include <cmath>
+
//----- Static Methods -----
//
double StarObject::reindexInterval( double pm )
@@ -265,6 +267,7 @@ void StarObject::updateCoords( KSNumbers *num, bool , const dms*, const dms*, bo
void StarObject::getIndexCoords( KSNumbers *num, double *ra, double *dec )
{
+ static double pmms;
// Old, Incorrect Proper motion Computation. We retain this in a
// comment because we might want to use it to come up with a
@@ -277,7 +280,9 @@ void StarObject::getIndexCoords( KSNumbers *num, double *ra, double *dec )
// atan2( pmRA(), pmDec() ) to an angular distance given by the Magnitude of
// PM times the number of Julian millenia since J2000.0
- if( pmMagnitudeSquared() * num->julianMillenia() * num->julianMillenia() < 1. ) {
+ pmms = pmMagnitudeSquared();
+
+ if( isnan( pmms ) || pmms * num->julianMillenia() * num->julianMillenia() < 1. ) {
// Ignore corrections
*ra = ra0().Degrees();
*dec = dec0().Degrees();
@@ -316,7 +321,7 @@ void StarObject::JITupdate()
if ( updateNumID != data->updateNumID() ) {
// TODO: This can be optimized and reorganized further in a better manner.
// Maybe we should do this only for stars, since this is really a slow step only for stars
- Q_ASSERT( isfinite( lastPrecessJD ) );
+ Q_ASSERT( std::isfinite( lastPrecessJD ) );
if( ( lastPrecessJD - data->updateNum()->getJD() ) >= 0.0005 // TODO: Make this 0.0005 a constant / define it
|| ( lastPrecessJD - data->updateNum()->getJD() ) <= -0.0005
|| Options::alwaysRecomputeCoordinates()
More information about the Kstars-devel
mailing list