-10^2 (OT)
Raymond E. Griffith
rgriffit at ctc.net
Tue May 27 21:39:00 EDT 2003
on 5/22/03 1:51 PM, Dar Scott at dsc at swcp.com wrote:
>
> On Thursday, May 22, 2003, at 11:32 AM, David Squance wrote:
>
>> -10*-10 is ambiguous, since you have two operations adjacent to each
>> other
>> (ultra picky, I know)
>> Assuming *-10 is meant to be *(-10), -10*-10 = -(-100) = 100
>
> I'm having trouble seeing an alternate meaning.
>
> Dar
>
Here is the issue:
Remember that numbers represented in computers are not represented in
decimal form, but in a binary form. Negative numbers are not represented
with a negative sign, but rather as a binary with a different first digit (1
instead of 0, I think).
The algebraic order of operations is
Parentheses, Exponent, Multiplication and Division (from left to right), and
Addition and Subtraction (from left to right), or PEMDAS
But algebraically, negation is a multiplication process. -5 = -1*5. So
-10^2 means -1*10^2, or -100.
Algebraically, the exponent only affects what it touches. That is why -10^2
means -1*10^2, and not (-10)^2.
But since computers see numerical representation differently, the negation
of a number is not a real "operation" to a computer. -10 is a single unit.
So -10^2 in computer languages will always mean (-10)^2.
Anti-intuitive? Yup. But if the engine were rewritten to check and correct
for this algebraically, it would run a lot slower. Better for us just to
recognize the difficulty and code around it.
Raymond E. Griffith
More information about the use-livecode
mailing list