Mathematics in Python are not correct

castironpi at gmail.com castironpi at gmail.com
Thu May 8 19:49:25 EDT 2008


On May 8, 6:10 pm, Nicolas Dandrimont <nicolas.dandrim... at gmail.com>
wrote:
> * wxPytho... at gmail.com <wxPytho... at gmail.com> [2008-05-08 15:54:42 -0700]:
>
> > Have a look at this:
>
> > >>> -123**0
> > -1
>
> > The result is not correct, because every number (positive or negative)
> > raised to the power of 0 is ALWAYS 1 (a positive number 1 that is).
>
> > The problem is that Python parses -123**0 as -(123**0), not as
> > (-123)**0.
>
> And why is this a problem ? It is the "standard" operator precedence
> that -123^0 is -(123^0), isn't it ?
>
> > I suggest making the Python parser omit the negative sign if a
> > negative number is raised to the power of 0. That way the result will
> > always be a positive 1, which is the mathematically correct result.
>
> That's what it does :
>
> >>> -123**0
> -1
> >>> (-123)**0
>
> 1
>
> > This is a rare case when the parser is fooled, but it must be fixed in
> > order to produce the correct mathematical result.
>
> Again, the mathematical result is correct. -123^0 is -(123^0), not
> (-123)^0.
>
> Regards,
> --
> Nicolas Dandrimont
>
>  signature.asc
> 1KDownload

Signs include power.

>>> -2**0
-1
>>> (-2)**0
1
>>> -(2**0)
-1

+x, -x Positive, negative
~x Bitwise not
** Exponentiation

from Help;

However:

>>> 2+3**1
5
>>> 2+3**2
11

So, the order of precedence table has not listed the identical order
of operations with the implementation.

I have hit parentheses in rolling too.

In terms of money, processor-based operations may not be equals.
Clock cycles cost fractions of time.  But, I don't see x= -x in realty.



More information about the Python-list mailing list