[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

date representations and real number precision



PureBytes Links

Trading Reference Links

We've been through the details of single and double precision
representations of numbers/dates in the Wintel architecture before
on this list.  The storage of dates has nothing to do with whether
or not a TSxx application or an MSxx operating system is a "32-bit"
program or not.  It has nothing to do with the compiler used.

The problem boils down to the fact that some time in the distant
past some programmer of some trading application was not thinking
clearly, and for an unknown reason decided to store dates as
single precision floating point numbers, when that same programmer
had many reasons to instead choose an unsigned long integer (also
32 bits in length) for the purpose.  For some equally unknown 
reason, that programmer's choice was adopted by many trading
applications, including those from OR.

An unsigned long integer can store the decimal number 4,294,967,295
in its 32 bits.  This makes the number 2000 12 31 (when run together)
look small in comparison.  No problems would have been encountered
for centuries.  Not only would we not have any problems in 2000,
20,000 would also still function correctly.

Instead, we must investigate how 32 bit floats are stored.  23 bits
are dedicated to the mantissa, 1 to the sign, and 8 to the exponent.
In addition in the IEEE representation used by Wintel, there is an
implicit assumption that the exponent is adjusted so that the left
most binary digit is always a 1 and thus need not be stored.  Hence
we have 24 bits to represent the mantissa.  With all 24 bits "on",
then we can store the decimal number 16,777,215.  Thus the frequently
quoted story that a float can represent exactly "7 and a fraction
decimal digits."  Given that the computer industry has chosen to
store dates in the order year/month/day for ease of sorting, etc. we 
cannot exactly represent 2000 12 31 in a single precision float.
Two digit year representations worked fine.  Four digits fail 
anytime after 1677.  So now we are seemingly stuck with representing
years as an offset from 1900 while 9 bits go unused (really wasted,
but used).

End of story,

Rod
-- 
_______________________________________________________________________

J. Rodney Grisham, Ph.D.                   Technix Systems, Inc.
mailto:grisham@xxxxxxxxxxx                 P. O. Box 940129
Phone: 281-493-9221                        Houston, Texas 77094-7129
_______________________________________________________________________