Dana DeLouis said:
Hi. I most likely am wrong, but here's two cents just for discussion.
I think it should be mentioned that I think --True is a unique
"Feature" of Excel, and usually would not work in other languages.
There are few other languages that have a separate binary type. Pascal (and
its derivatives) is the only one I can think of, and it's sooooo 'correct'
that no arithmetic operator of any kind is allowed to work with them.
FWIW, -- works with awk to force numeric strings to be treated as numbers.
That was necessary in an old MKS version of awk I used years ago, but hasn't
been needed in gawk 3.x.
I believe it is correct in that "A single unary minus converts a
number to its additive inverse." However, in this context, I believe
we are not working with numbers per say. . . .
Semantics. Applying any arithmetic operator to a boolean value coerces that
value into either a 1 (for TRUE) or 0 (for FALSE) *first*. Once converted to
a number, the operand is used in conjunction with the operator to give the
arithmetic result. So, once you use a boolean in an arithmetic context, it
ceases to be a boolean and becomes a number by virtue of automatic boolean
to number conversion.
Excel is unique in that a cell formula such as ="123"+4 returns 127.
No, the same thing can be accomplished in any scripting language you could
name, and I believe (but can't find out for sure) that this also works in D
and Icon. You may be right if you just mean that other spreadsheets don't
allow this (other than those designed to work similar to Excel).
. . . So, I think it is unique feature of Excel that
allows -True to return -1. This makes no sense in other languages.
Because many other languages weren't screwed up in the original design by
having a separate boolean type, other than Pascal & offspring. C and its
derivative languages represent TRUE and 1 and FALSE as 0, though any nonzero
numeric value is treated as true when used in a boolean context.
More semantics. In C,
int n;
n = -(1 == 3 - 2);
sets n to -1. So what are you trying to say?
However, this is a useful spreadsheet "Feature." If my memory serves
me correctly, I think this was one of the "nice features" added over
Lotus 123?
....
Correct, in 123 +"123"+4 would return ERR.
You might be interested to know that when the results of an operation
is not a number, a Minus sign is represented in a program like
Mathematica via multiplication.
Both of these operations are represented via multiplication:
- True
- (5 > 4)
Both return
Times[-1,True]
And the relevance of Mathematica to Excel is?
Mathematica is meant to do symbolic math, and there are reasons why it may
be efficient to translate unary minus as multiplication. In languages and
systems that do their arithmetic immediately in binary, unary minus is
represented as flipping the sign bit.
My gut feeling is that Excel is doing the same thing as it brings in
the value of what True. Excel uses basically standard IEEE computer
math, so that is my basis for this gut feeling. . . .
....
You seem to be saying that you believe Excel is using multiplication because
it uses IEEE binary floating point. Why do you believe IEEE binary floating
point has anything to do with how unary minuses are implemented at lower
level?
The Intel i386 Pentium FPUs are all presumably IEEE-754 compliant. Those
FPUs use the machine instruction FCHS to change the sign of values held in
floating point registers. Do you believe Excel uses something else (not that
it'd surprise me given all the oddities in Excel)?
Anyway, very interesting subject. Again, I know you can't compare the
two programs, but it does offer a glimpse into how computer math is
done.
No. It gives a glimpse into how Mathematica performs symbolic math, which
has different requirements than immediate binary numeric calculation. With
regard to Excel, it's likely irrelevant and misleading.