[Python-ideas] Yet another sum function (fractions.sum)
Chris Angelico
rosuav at gmail.com
Thu Aug 22 09:11:52 CEST 2013
On Thu, Aug 22, 2013 at 1:02 PM, Mark Dickinson <dickinsm at gmail.com> wrote:
> In that sense, I'd say that it's rather the ** operation that's the odd man
> out, in that there are very few other ways to get complex numbers with no
> obvious explicit request for complex numbers
1/2 == 0.5 # int/int --> float
(-4.0)**0.5 == (-4.0)**0.5 == 1.2246467991473532e-16+2j #
float**float --> complex
(though why it doesn't equal 2j exactly, I don't know - surely there's
enough precision in these floats to calculate that?)
Personally, I don't like the automated casting of int to float, since
int covers arbitrary range and float will quietly lose precision; if
you flick to float early in a calculation, you may be suddenly
surprised by the inaccuracy at the end. But that's the decision
Python's made, so it makes good sense for the upcasting of float to
complex to work the same way - especially since you can't lose
precision by going from float to complex (AFAIK).
ChrisA
More information about the Python-ideas
mailing list