And the reason KB214094 uses a five-digit representation for an
elapsed time of 12 hours 45 minutes is because 0.53125 is the
exact decimal value for that time period. 12.75/24 = 0.53125.
I was referring to the general statement at the beginning of the KB
article, to wit: "Times are stored as decimal numbers between .0 and .
99999, where .0 is 00:00:00 and .99999 is 23:59:59".
I was trying to contrast that with statements on Chip's web page,
namely: "Excel stores dates and times as a number representing the
number of days since 1900-Jan-0, plus a fractional portion of a 24
hour day: ddddd.tttttt. [....] The integer portion of the number,
tttttt, represents the fractional portion of a 24 hour day".
(I presume Chip meant to say the __fractional__ portion, tttttt.)
Your conclusion that time is accurate to 0.1 seconds was based on the
fact that Chip showed only 6 decimal places for time. But if Chip
were wrong and MS were right (an interesting proposition ;->), you
would have to conclude that time is accurate to only 1 second because
the MS KB shows only 5 decimal places for time.
That "proof by contradition" was intended to be an eye-opener for
you. Obviously, the strategy failed.
No matter, because ....
I just had an "aha" moment. If I store just the time in a cell,
e.g. 12:01:01 PM, Excel displays the time but stores the
information as 0.500011574074074 -- fifteen digits [...].
Apparently Excel does keep track of time to more than six decimal
digits.
Ding! And with that, the student becomes the master ;-). I'm sorry
that my explanations did not help you. But there is nothing like self-
discovery to advance your own education. I was hoping that you would
try to fill in the blanks with your own experiments anyway. (BTW,
apparently you entered 12:00:01, not 12:01:01.)
I'm not getting into the decimal system vs. the binary
system and the loss of accuracy that entails at some
point in working with very small numbers.
Small numbers per se are not the problem. For example, 2^-1022 is a
__very__ small number, yet it can be represented with no loss of
accuracy. The issue is whether or not a decimal value can be
represented exactly as a sum of a finite number (53) of consecutive
powers of 2. That is as much a problem with 12345678901234.1 as it is
with 0.0000000000123456789012341.
It's a little more involved than that. For example, small changes to
large numbers can sometimes be problematic. (Not in this case,
though.) But I'm not getting into the whole decimal v. binary system
thing ;-).
Perhaps I should have said unreliable digits rather than
unreliable numbers.
[....]
Some fractions are exactly equal in decimal and binary.
1.1 binary exactly equals 1.5 decimal. 1.11 exactly equals
1.75 decimal. Most such conversions are approximate,
although close enough for most practical purposes.
And my point was.... The approximation of 0.01 seconds is just as
"close enough for most practical purposes" as is the approximation for
0.1 seconds in Excel's time format. The representation of 0.01
seconds is no less "reliable" than the representation of 0.1 seconds,
by your definition. They are both accurate to +/- 8.64 microseconds,
less than 1/1000 of 0.01 seconds. (See below.)
(Here, I am referring to the "reliability" of the representation and
presentation of the time format, not the reliability of the Excel NOW
() function per se.)
Ten milliseconds is 0.01 seconds. And I noted above
that the numbers beyond the tenths column are
unreliable. That could explain the occasional 20
millisecond difference.
No, it is not due to the potential "loss of accuracy", which you
explained is what you mean by "unreliable". Today's date/time in
numeric format to 15 significant digits is 39890.5031526620. The
potential "error" (numerical abberation) in the last digit represents
+/- 8.64 microseconds (10^-10 * 86400 seconds).
The variability in the minimum non-zero difference between calls to
the Excel NOW() function (10 and 20 msec) is because: (a) the Excel
NOW() function truncates time to the lowest multiple of 10
milliseconds (hundredths of a second); and (b) system time is
incremented every 15.625 milliseconds, not a multiple of 10
milliseconds. Consider these two examples, recorded by a VB macro.
(1) Actual time: start= 0:12:21.062 end= 0:12:21.078 diff= 0.016 sec
NOW: start= 0:12:21.060 end= 0:12:21.070 diff= 0.010
sec
(2) Actual time: start= 0:12:31.484 end= 0:12:31.500 diff= 0.016 sec
NOW: start= 0:12:31.480 end= 0:12:31.500 diff= 0.020 sec
("Actual time" is returned by a kernel function.)
The repetition of the digits "740" four times before
the comma in the examples above [....] is suspect,
although I guess no more so than the endless threes
in the decimal representation of 1/3.
Exactly right!
I'd be less suspicious if the 740's kept on repeating.
But they do, at least in decimal. As you say, "do the math". Compute
1/86400 on paper. You should get 0.0000115(740)..., which is my
notation for the infinitely repeating pattern 740.
The only reason that the pattern stops repeating in the binary
representation is because of the finite number of bits in the binary
representation. 1/86400 is represented internally exactly by
0.0000115740740740740,73499346533566711769935864140279591083526611328125.
If we add 2^-69, the smallest possible one-bit increment [1], the
internal representation is exactly
0.0000115740740740740,7519341242807531244807250914163887500762939453125.
As you might note, the first is below ",740", and the second is above
",740" [2]. In other words, for this value, ",740" cannot be
represented within the limits of the IEEE 64-bit floating point
format.
HTH.
Thanks. I'm having a lot of fun with this
.
Endnotes:
[1] Actually 2^-70 is the smallest possible one-bit increment. But
adding either 2^-69 or 2^-70 has the same effect. This is because
binary floating-point arithmetic is actually performed in 80-bit FP
registers, then stored into a 64-bit result. The conversion might
result in rounding of the least-significant bit, which is represented
by 2^-69 in this case.
[2] You cannot see the difference using Excel formatting because Excel
formats only the first 15 significant digits.
----- original posting -----
My math was based on Chip's information that date/time information is
stored as an integer and decimal combination with six digits set aside
for the time component. That means you can slice 24 hours into 1,000,000
equal pieces. There are 24x60x60x10 = 860,000 tenths of a second in a
day. Therefore Excel can potentially track only to the tenths of a
second. The hundredths of a second and beyond will result in unreliable
numbers.
Your reasoning would be sound, if the information were correct. But
Chip's information is incorrect, at least in a literal sense.
First, I hasten to note that according tohttp://support.microsoft.com/kb/214094,
the format of the time component is just 5 decimal fractions.