Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7117] Backport py3k float repr to trunk

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Oct 13, 2009, 1:30 AM

Post #1 of 22 (598 views)
Permalink
[issue7117] Backport py3k float repr to trunk

New submission from Mark Dickinson <dickinsm [at] gmail>:

See the thread starting at:

http://mail.python.org/pipermail/python-dev/2009-October/092958.html

Eric suggested that we don't need a separate branch for this; sounds
fine to me. It should still be possible to do the backport in stages,
though. Something like the following?

(1) Check in David Gay's code plus necessary build changes,
configuration steps, etc; conversions still use the old code.

(2) Switch to using the new code for float -> string (str, repr, float
formatting) and string -> float conversions (float, complex
constructors, numeric literals in Python code). [Substeps?]

(3) Fix up builtin round function to use the new code.

(4) Make any necessary fixes to the documentation. (Raymond, I assume
you'll take care of the whatsnew changes when the time comes?)

(1), (3) and (4) should be straightforward. (2) is where most of the
work is, I think. I think it should be possible to do the stage (2)
work in pieces without breaking too much.

----------
assignee: mark.dickinson
components: Interpreter Core
messages: 93918
nosy: eric.smith, mark.dickinson, rhettinger
priority: normal
severity: normal
status: open
title: Backport py3k float repr to trunk
type: feature request
versions: Python 2.7

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 24, 2009, 6:41 AM

Post #2 of 22 (555 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

Some key revision numbers from the py3k short float repr, for reference:

r71663: include Gay's code, build and configure fixes
r71723: backout SSE2 detection code added in r71663
r71665: rewrite of float formatting code to use Gay's code

Backported most of r71663 and r71723 to trunk in:

r75651: Add dtoa.c, dtoa.h, update license.
r75658: configuration changes - detect float endianness,
add functions to get and set x87 control word, and
determine when short float repr can be used.

Significant changes from r71663 not yet included:

* Misc/NEWS update
* Lib/test/formatfloat_testcases.txt needs updating to match py3k.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 24, 2009, 7:06 AM

Post #3 of 22 (555 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

r75666: Add sys.float_repr_style attribute.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 24, 2009, 9:02 AM

Post #4 of 22 (549 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

r75672: temporarily disable the short float repr while we're putting
the pieces in place.

When testing, the disablement can be disabled (hah) by defining the
PY_SHORT_FLOAT_REPR preprocessor symbol, e.g. (on Unix) with

CC='gcc -DPY_SHORT_FLOAT_REPR' ./configure && make

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 24, 2009, 10:04 AM

Post #5 of 22 (554 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Eric Smith <eric [at] trueblade> added the comment:

I think the next step on my side is to remove _PyOS_double_to_string,
and make all of the internal code call PyOS_double_to_string. The
distinction is that _PyOS_double_to_string gets passed a buffer and
length, but PyOS_double_to_string returns allocated memory that must be
freed. David Gay's code (_Py_dg_dtoa) returns allocated memory, so
that's the easiest interface to propagate internally.

That's the approach we used in the py3k branch. I'll start work on it.
So Mark's work should be mostly config stuff and hooking up Gay's code
to PyOS_double_to_string. I think it will basically match the py3k version.

The existing _PyOS_double_to_string will become the basis for the
fallback code for use when PY_NO_SHORT_FLOAT_REPR is defined (and it
will then be renamed PyOS_double_to_string and have its signature
changed to match).

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 24, 2009, 11:15 AM

Post #6 of 22 (559 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

One issue occurs to me: should the backport change the behaviour of the
round function?

In py3k, round consistently uses round-half-to-even for halfway cases.
In trunk, round semi-consistently uses round-half-away-from-zero (and
this is documented). E.g., round(1.25, 1) will give 1.2 in py3k and
(usually) 1.3 in trunk.

I definitely want to use Gay's code for round in 2.7, since having round
work sensibly is part of the motivation for the backport in the first
place. But this naturally leads to a round-half-to-even version of
round, since the Python-adapted version of Gay's code isn't capable of
doing anything other than round-half-to-even at the moment.

Options:

(1) change round in 2.7 to do round-half-to-even. This is easy,
natural, and means that round will agree with float formatting
(which does round-half-to-even in both py3k and trunk). But it
may break existing applications. However: (a) those applications
would need fixing anyway to work with py3k, and (b) I have little
sympathy for people depending on behaviour of rounding of
*binary* floats for halfway *decimal* cases. (Decimal is another
matter, of course: there it's perfectly reasonable to expect
guaranteed rounding behaviour.)

It's more complicated than that, though, since if rounding
becomes round-half-to-even for floats, it should also change
for integers, Fractions, etc.

(2) have round stick with round-half-away-from-zero. This may be
awkward to implement (though I have some half-formed ideas about
how to make it work), and would lead to round occasionally not
agreeing with float formatting. For example:

>>> '{0:.1f}'.format(1.25)
'1.2'
>>> round(1.25, 1)
1.3

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 24, 2009, 11:29 AM

Post #7 of 22 (551 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Eric Smith <eric [at] trueblade> added the comment:

Adding tim_one as nosy. He'll no doubt have an opinion on rounding. And
hopefully he'll share it!

----------
nosy: +tim_one

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 24, 2009, 2:17 PM

Post #8 of 22 (547 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Eric Smith <eric [at] trueblade> added the comment:

Another thing to consider is that in py3k we removed all conversions of
converting 'f' to 'g', such as this, from Objects/unicodeobject.c:

if (type == 'f' && fabs(x) >= 1e50)
type = 'g';

Should we also do that as part of this exercise? Or should it be another
issue, or not done at all?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 24, 2009, 10:56 PM

Post #9 of 22 (537 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Raymond Hettinger <rhettinger [at] users> added the comment:

+1 on backporting the 'f' and 'g' work also.
We will be well served by getting the two
code bases ins-sync with one another.

Eliminating obscure differences makes it easier
to port code from 2.x to 3.x

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 26, 2009, 9:03 AM

Post #10 of 22 (534 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

r75720: Backport py3k version of pystrtod.c to trunk. There are still
some (necessary) differences between the two versions, which
should become unnecessary once everything else is hooked up.
The differences should be re-examined later.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 26, 2009, 10:01 AM

Post #11 of 22 (522 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

[Eric, on removing f to g conversions]
> Should we also do that as part of this exercise? Or should it be another
> issue, or not done at all?

I'd definitely like to remove the f to g conversion in trunk. I don't
see any great need to open a separate issue for that. (Was there one
already for the py3k removal?)

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 26, 2009, 10:03 AM

Post #12 of 22 (527 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

Found it: issue #5859 was opened for the removal of the f -> g conversion
in py3k. We could just add a note to that issue.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 26, 2009, 2:19 PM

Post #13 of 22 (523 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

r75730: backport pystrtod.h
r75731: Fix floatobject.c to use PyOS_string_to_double.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 26, 2009, 3:30 PM

Post #14 of 22 (524 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

r75739: Fix complexobject.c to use PyOS_string_to_double.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 27, 2009, 4:37 AM

Post #15 of 22 (521 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Eric Smith <eric [at] trueblade> added the comment:

r75743: Fix cPickle.c to use PyOS_string_to_double.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 27, 2009, 5:13 AM

Post #16 of 22 (524 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Eric Smith <eric [at] trueblade> added the comment:

r75745: Fix stropmodule.c to use PyOS_string_to_double.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 27, 2009, 11:37 AM

Post #17 of 22 (518 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Eric Smith <eric [at] trueblade> added the comment:

r75824: Fix ast.c to use PyOS_string_to_double.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 27, 2009, 12:43 PM

Post #18 of 22 (510 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Eric Smith <eric [at] trueblade> added the comment:

r75846: Fix marshal.c to use PyOS_string_to_double.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 28, 2009, 1:46 AM

Post #19 of 22 (507 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Eric Smith <eric [at] trueblade> added the comment:

r75913: Fix _json.c to use PyOS_string_to_double. Change made after
consulting with Bob Ippolito.

This completes the removal of calls to PyOS_ascii_strtod.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 29, 2009, 3:17 AM

Post #20 of 22 (505 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

The next job is to deprecate PyOS_ascii_atof and PyOS_ascii_strtod, I
think. I'll get to work on that.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Oct 31, 2009, 2:44 AM

Post #21 of 22 (493 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

r75979: Deprecate PyOS_ascii_atof and PyOS_ascii_strtod; document
PyOS_double_to_string.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 3, 2009, 8:15 AM

Post #22 of 22 (473 views)
Permalink
[issue7117] Backport py3k float repr to trunk [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

Here's a patch for correctly-rounded round in trunk. This patch doesn't
change the rounding behaviour between 2.6 and 2.7: it's still doing
round-half-away-from-zero instead of round-half-even. It was necessary to
detect and treat halfway cases specially to make this work. Removing this
special case code would be easy, so we can decide later whether it's worth
changing round to do round-half-to-even for 2.7.

I want to let this sit for a couple of days before I apply it.

----------
keywords: +patch
Added file: http://bugs.python.org/file15254/round_fixup.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.