-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport py3k float repr to trunk #51366
Comments
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 (1) Check in David Gay's code plus necessary build changes, (2) Switch to using the new code for float -> string (str, repr, float (3) Fix up builtin round function to use the new code. (4) Make any necessary fixes to the documentation. (Raymond, I assume (1), (3) and (4) should be straightforward. (2) is where most of the |
Some key revision numbers from the py3k short float repr, for reference: r71663: include Gay's code, build and configure fixes Backported most of r71663 and r71723 to trunk in: r75651: Add dtoa.c, dtoa.h, update license. Significant changes from r71663 not yet included:
|
r75666: Add sys.float_repr_style attribute. |
r75672: temporarily disable the short float repr while we're putting When testing, the disablement can be disabled (hah) by defining the CC='gcc -DPY_SHORT_FLOAT_REPR' ./configure && make |
I think the next step on my side is to remove _PyOS_double_to_string, That's the approach we used in the py3k branch. I'll start work on it. The existing _PyOS_double_to_string will become the basis for the |
One issue occurs to me: should the backport change the behaviour of the In py3k, round consistently uses round-half-to-even for halfway cases. I definitely want to use Gay's code for round in 2.7, since having round Options: (1) change round in 2.7 to do round-half-to-even. This is easy,
(2) have round stick with round-half-away-from-zero. This may be >>> '{0:.1f}'.format(1.25)
'1.2'
>>> round(1.25, 1)
1.3 |
Adding tim_one as nosy. He'll no doubt have an opinion on rounding. And |
Another thing to consider is that in py3k we removed all conversions of
Should we also do that as part of this exercise? Or should it be another |
+1 on backporting the 'f' and 'g' work also. Eliminating obscure differences makes it easier |
r75720: Backport py3k version of pystrtod.c to trunk. There are still |
[Eric, on removing f to g conversions]
I'd definitely like to remove the f to g conversion in trunk. I don't |
Found it: issue bpo-5859 was opened for the removal of the f -> g conversion |
r75730: backport pystrtod.h |
r75739: Fix complexobject.c to use PyOS_string_to_double. |
r75743: Fix cPickle.c to use PyOS_string_to_double. |
r75745: Fix stropmodule.c to use PyOS_string_to_double. |
r75824: Fix ast.c to use PyOS_string_to_double. |
r75846: Fix marshal.c to use PyOS_string_to_double. |
r75913: Fix _json.c to use PyOS_string_to_double. Change made after This completes the removal of calls to PyOS_ascii_strtod. |
The next job is to deprecate PyOS_ascii_atof and PyOS_ascii_strtod, I |
r75979: Deprecate PyOS_ascii_atof and PyOS_ascii_strtod; document |
Here's a patch for correctly-rounded round in trunk. This patch doesn't I want to let this sit for a couple of days before I apply it. |
r76373: Backport round. |
Short float repr is now enabled in r76379. Misc/NEWS entries added/updated in r76411. |
r76465 removes the fixed-length buffer for formatting floats, hence |
r76474: Remove %f -> %g switch. |
I think we're pretty much done here. I'd still like to produce a more complete set of float formatting test Eric, Raymond: can you spot anything we've missed? |
Thanks for tackling the last few bits, Mark. I think we're done, I suggest we close this issue and if any problems occur open them as new |
Thanks, Eric. The only remaining documentation issues I'm aware of are in I'll call this done, then! Thanks for all your help. |
Wondered if you guys had heard of some recent advances in the state of the art in this field. I'm sure you have, but thought I'd link it here anywhere. Quote taken from this article (which links to relevant papers): In 2010, Florian Loitsch published a wonderful paper in PLDI, "Printing floating-point numbers quickly and accurately with integers", which represents the biggest step in this field in 20 years: he mostly figured out how to use machine integers to perform accurate rendering! Why do I say "mostly"? Because although Loitsch's "Grisu3" algorithm is very fast, it gives up on about 0.5% of numbers, in which case you have to fall back to Dragon4 or a derivative. If you're a language runtime author, the Grisu algorithms are a big deal: Grisu3 is about 5 times faster than the algorithm used by printf in GNU libc, for instance. A few language implementors have already taken note: Google hired Loitsch, and the Grisu family acts as the default rendering algorithms in both the V8 and Mozilla Javascript engines (replacing David Gay's 17-year-old dtoa code). Loitsch has kindly released implementations of his Grisu algorithms as a library named double-conversion. |
Hadn't seen that. Interesting! |
Thanks for the link :-) |
I've filed bpo-12450 to track this last idea. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: