[Kstars-devel] branches/KDE/3.5/kdeedu/kstars/kstars
Jason Harris
kstars at 30doradus.org
Thu Aug 4 16:48:12 CEST 2005
SVN commit 442973 by harris:
Fixing Bug #109788 (Rounding error when computing arcmin/arcsec for a
dms angle)
The issue manifests itself when converting a double value with all
zeroes after the decimal point, to an int. e.g.:
double d = 10.000000000;
int i = int(d); // i == 9 !! >:(
I tried several ways of massaging the code, but in the end, this is
the only thing I could get to work:
double d = 10.000000000;
int i = int( float(d) ); // i == 10 !! :D
So, it works, but maybe it's a kludge and maybe someone knows a better
way.
Will port to trunk.
CCMAIL: kstars-devel at kde.org
BUG: 109788
M +6 -6 dms.cpp
--- branches/KDE/3.5/kdeedu/kstars/kstars/dms.cpp #442972:442973
@@ -166,7 +166,7 @@
}
const int dms::arcmin( void ) const {
- int am = int( 60.0*( fabs(D) - abs( degree() ) ) );
+ int am = int( float( 60.0*( fabs(D) - abs( degree() ) ) ) );
if ( D<0.0 && D>-1.0 ) { //angle less than zero, but greater than -1.0
am = -1*am; //make minute negative
}
@@ -174,7 +174,7 @@
}
const int dms::arcsec( void ) const {
- int as = int( 60.0*( 60.0*( fabs(D) - abs( degree() ) ) - abs( arcmin() ) ) );
+ int as = int( float( 60.0*( 60.0*( fabs(D) - abs( degree() ) ) - abs( arcmin() ) ) ) );
//If the angle is slightly less than 0.0, give ArcSec a neg. sgn.
if ( degree()==0 && arcmin()==0 && D<0.0 ) {
as = -1*as;
@@ -183,7 +183,7 @@
}
const int dms::marcsec( void ) const {
- int as = int( 1000.0*(60.0*( 60.0*( fabs(D) - abs( degree() ) ) - abs( arcmin() ) ) - abs( arcsec() ) ) );
+ int as = int( float( 1000.0*(60.0*( 60.0*( fabs(D) - abs( degree() ) ) - abs( arcmin() ) ) - abs( arcsec() ) ) ) );
//If the angle is slightly less than 0.0, give ArcSec a neg. sgn.
if ( degree()==0 && arcmin()==0 && arcsec()== 0 && D<0.0 ) {
as = -1*as;
@@ -192,7 +192,7 @@
}
const int dms::minute( void ) const {
- int hm = int( 60.0*( fabs( Hours() ) - abs( hour() ) ) );
+ int hm = int( float( 60.0*( fabs( Hours() ) - abs( hour() ) ) ) );
if ( Hours()<0.0 && Hours()>-1.0 ) { //angle less than zero, but greater than -1.0
hm = -1*hm; //make minute negative
}
@@ -200,7 +200,7 @@
}
const int dms::second( void ) const {
- int hs = int( 60.0*( 60.0*( fabs( Hours() ) - abs( hour() ) ) - abs( minute() ) ) );
+ int hs = int( float( 60.0*( 60.0*( fabs( Hours() ) - abs( hour() ) ) - abs( minute() ) ) ) );
if ( hour()==0 && minute()==0 && Hours()<0.0 ) {
hs = -1*hs;
}
@@ -208,7 +208,7 @@
}
const int dms::msecond( void ) const {
- int hs = int( 1000.0*(60.0*( 60.0*( fabs( Hours() ) - abs( hour() ) ) - abs( minute() ) ) - abs( second() ) ) );
+ int hs = int( float( 1000.0*(60.0*( 60.0*( fabs( Hours() ) - abs( hour() ) ) - abs( minute() ) ) - abs( second() ) ) ) );
if ( hour()==0 && minute()==0 && second()==0 && Hours()<0.0 ) {
hs = -1*hs;
}
More information about the Kstars-devel
mailing list