Bizarre arithmetic results

Jussi Piitulainen jpiitula at ling.helsinki.fi
Fri Feb 12 04:40:20 EST 2010


Terry Reedy writes:
> On 2/11/2010 11:23 AM, Jussi Piitulainen wrote:
> > Robert Kern writes:
> >> On 2010-02-11 06:31 AM, Shashwat Anand wrote:
> >>> There is a little issue here that '>>>  -.1 ** .1' should give you
> >>> error message. That is it.
> >>
> >> No, fractional powers of negative numbers are perfectly valid
> >> mathematically. The result is a complex number. In Python 3 (what
> >> the OP is using), this has been implemented, but not in Python 2.6.
> >
> > Perhaps it should raise a MisleadingSpacingError at compile time.
> 
> You forgot the smiley ;-).
> 
>  > The error message could recommend - .1**.1, or better -(.1 ** .1).
> 
> The compiler would never see the difference between -.1 ** .1 and the
> first and probably no difference with the second either.

It could be done the same way that the compiler keeps track of the
source line numbers now: early phases annotate their output with any
information that later phases may need. This error would be detected
during syntactic analysis.

:)



More information about the Python-list mailing list