[issue1600] str.format() produces different output on different platforms (Py30a2)

Mark Summerfield report at bugs.python.org
Sun Dec 16 20:10:58 CET 2007


Mark Summerfield added the comment:

On 2007-12-15, Christian Heimes wrote:
> Christian Heimes added the comment:
>
> Mark Summerfield wrote:
> > It seems to me that Python should provide consistent results across
> > platforms wherever possible and that this is a gratuitous inconsistency
> > that makes cross-platform testing less convenient than it need be.
> >
> > I'll take a look at those functions next week.
>
> It should be fixed in the trunk and merged into py3k. 2.6 suffers from
> the same problem.
>
> By the way I have another pending patch which adds consistent handling
> of "nan" and "inf" on all platforms to float.

Hi Christian,

I've added some code to pystrtod.c's PyOS_ascii_formatd() function that
ensures that the exponent is always at least 3 digits, so long as the
buffer passed in has room.

Although I have svn access, this was granted to me by Georg Brandl only
for doing documentation edits, so I don't feel that I can submit code
patches myself---and in any case my C is rusty, so I would prefer my
code was peer reviewed anyway. Would you be willing to add the patch for
me, assuming you are happy with it?

I've attached my modified pystrtod.c and also pystrtod.diff which shows
the diff against Python 30a2. My code is at the end of the function all
in one lump so it is easy to see what I've done. (I've assumed ANSI C,
so have declared some local variables in my code block rather than at
the top of the function: start, exponent_digit_count, and zeros; they
could all be moved if necessary.)

I hope this helps:-)

Added file: http://bugs.python.org/file8964/pystrtod.diff
Added file: http://bugs.python.org/file8965/pystrtod.c

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1600>
__________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pystrtod.diff
Type: text/x-diff
Size: 1270 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-bugs-list/attachments/20071216/d3f6c6dd/attachment.diff 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pystrtod.c
Type: text/x-csrc
Size: 7108 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-bugs-list/attachments/20071216/d3f6c6dd/attachment.c 


More information about the Python-bugs-list mailing list