[Tutor] a puzzle about -3**2 vs (-3)**2
Steven D'Aprano
steve at pearwood.info
Fri Jul 31 20:54:52 CEST 2015
Hi Deb,
On Fri, Jul 31, 2015 at 10:48:57AM -0700, D Wyatt wrote:
> I have never really thought about any of this before, but many of you
> have responded like this is so obvious. That is not helpful. I'm
> looking at a negative number as being an object that is one less than
> zero, and the unary sign being a part of that object, glued to it.
> Why is that so hard to understand?
Like many things, the behaviour here is obvious in hindsight. And you
are right, sometimes people forget that hindsight is 20:20 but foresight
is not. If I said anything that gave you the impression that your
question was a dumb question, sorry, that wasn't my intention.
In this case, your expectation that -3**2 should be treated as -3 as a
single value, raised to the power of 2, is a perfectly reasonable
expectation. I daresay that there are programming languages where that
actually is the case, and if you search the Internet, you'll find lots
of people making the same assumption as you.
Regards,
Steve
More information about the Tutor
mailing list