[Python-ideas] Fix some special cases in Fractions?

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Aug 30 03:07:51 EDT 2018


Jonathan Goble wrote:
> How? Raising something to the 2/3 power means squaring it and then 
> taking the cube root of it.

On reflection, "wrong" is not quite accurate. A better
word might be "surprising".

(-1) ** (2/3) == 1 would imply that 1 ** (3/2) == -1.
I suppose that could be considered true if you take the
negative solution of the square root, but it seems a
bit strange, and it's not what Python gives you for
the result of 1 ** (3/2).

If you want a solution that round-trips, you need
complex numbers. That's what Python does when you use
floats. Making Fractions do something different would
make it inconsistent with floats.

My calculator (which only does real floats) reports an
error when trying to evaluate (-1) ** (2/3).

-- 
Greg



More information about the Python-ideas mailing list