J
JoeU2004
PS....
Previously, I wrote: "okay, I can see your point: it is a constant, not a
value returned by a formula. So arguably, it should be limited by the rules
for constants", referring to the contraints on entering constants into an
Excel cell manually.
I intended to paraphrase what I thought you were saying.
But now that I understand what you mean by "permitted as Excel constants" in
this context, perhaps you were never suggesting that "point" in the first
place.
Too bad. I thought it was an excellent theory, even though I demonstrated
that it is wrong.
If I were implementing some constraint on VBA binary representations
assigned to cells as constants (but I wouldn't), that is the rule I would
specify. It is simple to implement; and it makes good sense. Two dead
give-aways that should tell us MS would never have implemented it ;-).
Anyway, sorry if I misunderstood your original point. I did not mean to be
nitpicky about your terminology. It's just that I realized that it was the
crux of my original misunderstanding.
Other than that, I think we are on the same page.
----- original message -----
[....]Jerry W. Lewis said:all the binary variants of 0.283 are permitted as Excel constants.
I believe you are trying to say that the following preserves the VBA
binary representation
Previously, I wrote: "okay, I can see your point: it is a constant, not a
value returned by a formula. So arguably, it should be limited by the rules
for constants", referring to the contraints on entering constants into an
Excel cell manually.
I intended to paraphrase what I thought you were saying.
But now that I understand what you mean by "permitted as Excel constants" in
this context, perhaps you were never suggesting that "point" in the first
place.
Too bad. I thought it was an excellent theory, even though I demonstrated
that it is wrong.
If I were implementing some constraint on VBA binary representations
assigned to cells as constants (but I wouldn't), that is the rule I would
specify. It is simple to implement; and it makes good sense. Two dead
give-aways that should tell us MS would never have implemented it ;-).
Anyway, sorry if I misunderstood your original point. I did not mean to be
nitpicky about your terminology. It's just that I realized that it was the
crux of my original misunderstanding.
Other than that, I think we are on the same page.
----- original message -----
JoeU2004 said:Jerry W. Lewis said:A follow-up to be sure that we have communicated:
I agree that this is a good summary of the points that I tried to make.
This phenomenon is different than truncation on input.
Right.
Initially, you had written: "all the binary variants for the 15 digit
display collapse into a single binary value for each of the 'unpermitted'
constants", and "the issue is not with your VBA code, but is due to the
fact that Excel simply does not permit these binary values as constants in
cells".
I understood you to be asserting that the problem relates to how Excel
handles entering constants into cells manually; that the "unpermitted
constants" are constants with digits beyond the first 15 significant
digits.
I refuted that assertion with examples "where the cell value assignment in
a Sub does indeed preserve the internal binary representation, even though
it can __not__ be entered manually as a constant in Excel".
If, instead, your term "unpermitted constants" is meant to refer to some
list or category of constants, I would be very surprised if that is the
case. It is more likely explained by an algorithm (or heuristic or rule).
If you have a theory about the algorithm, I'd be interested in hearing it.
all the binary variants of 0.283 are permitted as Excel constants.
Fascinating example.
I believe you are trying to say that the following preserves the VBA
binary representation for all constants that are displayed as
0.283000000000000 when formatted to 15 significant digits, namely for all
"i" equal to -8 to 9:
Range("A1") = 0.283 + i*2^-54
I agree. And I believe the examples for "i" equal to 1 to 9 contradict
even the contorted rule that I had devised to explain all this. Back to
the drawing boards!
(Counter-example: CDbl("'0.28000000000000047"), 17 sig digits, whose
binary representation is not preserved when assigned to a cell in VBA.)
Nitpick: I would not say that these "variants" are "permitted as Excel
constants" per se. To me, that means we can enter them into a cell as a
constant. I know that is not what you mean, because I know you understand
that for manual data entry, Excel "truncates input to 15 [significant]
digits before converting the input to binary". (You said that so much
better than I did.)
I would say, as I presume you mean, that the assignment of these values to
a cell in a macro preserves the VBA binary representation.
----- original message -----
Jerry W. Lewis said:A follow-up to be sure that we have communicated:
This phenomenon is different than truncation on input. For example, all
the
binary variants
of 0.283 are permitted as Excel constants. My vague recollection is that
this phenomenon
is more complex than simply replacing x with VALUE(x&"") when x&"" has no
more than
2 decimal places, but that was so many years ago that I cannot be
certain.
Also, even though VBA and Excel both only display 15 digits, they are
different in the way
that they handle input with more than 15 digits:
- Excel always truncates input to 15 decimal digits before converting the
input to binary,
thus input of
0.12399999999999961 will be stored as the binary representation of
0.123999999999999, and then correctly displayed to 15 decimal digits as
0.123999999999999
- VBA converts the full input to binary, thus input of
0.12399999999999961 will be stored as the binary representation of
0.12399999999999961, and then correctly displayed to 15 decimal digits as
0.124. If you subsequently edit that line of code, then the underlying
value will actually
change to the binary representation of 0.124
As a result, if I am doing accuracy checks in a worksheet, then my
reference
values would
be given to full precision by =D2F("0.12399999999999961")
If I am doing numerical work in VBA that involves floating point
constants,
then I either use
CDbl("0.12399999999999961") or maintain the code in a text editor to be
insure that the
full precision of the numeric constants is not lost.
Jerry