Overview
Features
Download
Documentation
Community
Add-Ons & Services

concerns about using double for Julian day number in DateTime

General discussion regarding the development of POCO for contributors.

concerns about using double for Julian day number in DateTime

Postby marlowa » 25 Jul 2006, 00:35

I am concerned about the use of a double to store a Julian day number, given that the number is stored in binary floating point, not decimal.

The number of significant figures for a double in most systens today, assuming 8 byte doubles with IEEE encoding, is 15 significant figures. The Julian day number for today is 2453941, which takes 6 significant figures, leaving only 11 for the time of day down to microsecond granularity. The number of microseconds in one day is 86400,000,000 which is JUST enough (when I first noticed a double being used I was not if there would be enough). But there are some decimal numbers that do not have exact representations in binary (just like the number one third cannot be represented precisely as a decimal number even though it can be represented precisely in base 3).

I am still working on adding tests to the DateTime test harness. I cannot help wondering if I will be able to come up with some DateTimes that cannot be stored accurately.

I cannot help thinking that it would be better to store the integer part of the Julian day number in an integer and store the number of microseconds offset as a 64 bit integer.

-Andrew Marlow

marlowa
 
Posts: 36
Joined: 19 Jul 2006, 09:02
Location: United_Kingdom

Re: concerns about using double for Julian day number in DateTime

Postby guenter » 26 Jul 2006, 08:46

DateTime has never been meant to be a class for sophisticated date and time storage and manipulation. The original intent was to provide a facility for some simple conversions between the usual date/time representations, for current dates.

Regarding the usage of double for Gregorian dates: many other implementations (by Microsoft, Apple, ...) also do this, so, at least for the intended purposes of DateTime it seems to be a valid choice.

Personally, I don't really want to make DateTime any more sophisticated than it currently is. Handling dates and times can become quite complex, especially when it comes to supporting different calendars. IMO this is an issue best left to specialized libraries, like ICU (http://www-306.ibm.com/software/globalization/icu/index.jsp).
guenter
 
Posts: 1112
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: concerns about using double for Julian day number in DateTime

Postby marlowa » 08 Aug 2006, 13:35

> I am concerned about the use of a double to store a Julian day number, given that the number is stored in binary floating point, not decimal.

> I cannot help thinking that it would be better to store the integer part of the Julian day number in an integer and store the number of microseconds offset as a 64 bit integer.

I have a hacked version of the DateTime class in which I pick a date and try every possible value of time down to the mircrosecond. I construct the time and check that the hour, minute, second, millisecond and microsecond once extracted are equal to the loop counters. As you can imagine it took some time for this program to run. But the good news is that it worked ok. So despite my misgivings I have enough evidence to say that it is ok to use a double. False alarm. Well you live and learn :-)
marlowa
 
Posts: 36
Joined: 19 Jul 2006, 09:02
Location: United_Kingdom


Return to Contributors

Who is online

Users browsing this forum: No registered users and 2 guests

cron