Mark Dickinson <[email protected]> added the comment:
Updated patch:
4. also simplify complex printing: no special handling for nans or
infinities. This means that e.g. complex(1, inf) prints as
"1 + infj" instead of "1+inf*j".
This might look ugly, but I think it's better than what was there
before. Complex reprs are now more uniform and easier to parse
by external code. And the expression "1 + inf*j" doesn't give
the right thing anyway, even if you replace j by 1j and inf by
float(inf):
>>> inf = float('inf')
>>> 1 + inf*j
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'j' is not defined
>>> 1 + inf*1j # expect (1+infj), but get nan in real part:
(nan+infj)
Furthermore, with these simplifications to printing and
parsing, roundtripping now works: the output of repr(z)
is valid input to
5. Print real part if it's negative zero: z =complex(-0.0, 0.0)
now prints as -0 + 0j instead of just 0j, so again roundtripping
works: complex(repr(z)) recovers z exactly.
6. Change PyOS_ascii_strtod to always output a sign when requested,
even for nans. As far as I can tell, the complex formatting is
the only place that's affected by this. Eric?
----------
nosy: +eric.smith
Added file: http://bugs.python.org/file13746/simplify_complex_parsing_v2.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue5816>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com