Caelum getGregorianDateTimeFromJulianDay BUGFIX

stealth977

27-02-2009 13:25:33

Below is the fix to the getGregorianDateTimeFromJulianDay(....) function not working properly (at least under VS2008 SP1)
the problem was HighPrecision mode not activated in the function so hour/minute/second was not working since they are the parts needing high precision.
Now the set and get functions properly roundtrip :)


void Astronomy::getGregorianDateTimeFromJulianDay(
LongReal julianDay, int &year, int &month, int &day,
int &hour, int &minute, LongReal &second)
{
// Integer julian days are at noon.
// static_cast<int)(floor( is more precise than Ogre::Math::IFloor.
// Yes, it does matter.
int fpmode = enterHighPrecissionFloatingPointMode();
julianDay += (LongReal)0.5;
int ijd = static_cast<int>(floor(julianDay));
getGregorianDateFromJulianDay(ijd, year, month, day);


LongReal s = (julianDay - (LongReal)ijd);
s *= 86400.0;
hour = static_cast<int>(floor(s / 3600));
s -= hour * 3600;
minute = static_cast<int>(floor(s / 60));
s -= minute * 60;
second = s;
restoreFloatingPointMode(fpmode);
}

gerds

04-03-2009 05:39:47

Is this required only when using the DirectX9 plugin and choosing "Floating-point mode=Fastest"?

To get around these kind of issues for my projects I've forced the DirectX9 plugin to always choose "Consistent".

That means you dont need to hunt down and fix problems like this all over the place :-)

cdleonard

06-03-2009 07:49:11

Astronomy functions don't currently switch floating point precision. It would be a bit excessive to switch precision all over the place; I'm afraid it might even affect performance. The current approach is for the user of astronomy functions to switch precision only once before and after all astronomy magic. CaelumSystem and UniversalClock do something like that and they're immune to precission issues.

Since you're writing an editor you ended up dealing with astronomy in interesting ways and hit this issue. You can also fix your code by switching precision before and after calling into Caelum::Astronomy.

I'm not sure adding precission switches in all astronomy methods is justified.

lukeneorm

22-10-2009 18:26:10

Below is the fix to the getGregorianDateTimeFromJulianDay(....) function not working properly (at least under VS2008 SP1)
the problem was HighPrecision mode not activated in the function so hour/minute/second was not working since they are the parts needing high precision.
Now the set and get functions properly roundtrip :)


Thank you stealth977! I was searching for this bugfix! Now everything works fine! ;)

tdev

22-03-2011 08:43:20

merged :)