This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Document pure Python version of integer-to-float correctly-rounded conversion
Type: enhancement Stage: resolved
Components: Tests Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: mark.dickinson, python-dev, terry.reedy
Priority: normal Keywords: patch

Created on 2011-01-17 13:00 by mark.dickinson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pure_python_long_to_float.patch mark.dickinson, 2011-01-17 13:00 review
pure_python_long_to_float_v2.patch mark.dickinson, 2011-10-22 18:55 review
Messages (4)
msg126398 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-01-17 13:00
It would be helpful (perhaps to developers of alternative implementations) to give a pure Python version of correctly-rounded long-to-float conversion.  Attached is such a version, as a patch to test_long in the release27-maint branch.
msg126794 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-01-21 23:28
I see there is already something similar for true division.

I find
+    q_max, shift_max = 1 << sig_bits, sys.float_info.max_exp - sig_bits
easier to read as two lines
+    q_max = 1 << sig_bits
+    shift_max = sys.float_info.max_exp - sig_bits

Not having precedence memorized, I prefer added parens here:
+ ...  (n >> shift) | bool(n & (1 << shift) - 1)

I presume that for normal production testing, you would comment out
+       float = long_to_float
msg146177 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-10-22 18:55
Thanks for the comments.  Here's an updated patch, that actually makes use of the pure Python version to test the built-in int-to-float conversion.
msg146247 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-10-23 19:07
New changeset 117d51d3dd7d by Mark Dickinson in branch 'default':
Issue #10925: Add equivalent pure Python code for the builtin int-to-float conversion to test_long.
http://hg.python.org/cpython/rev/117d51d3dd7d
History
Date User Action Args
2022-04-11 14:57:11adminsetgithub: 55134
2011-10-23 19:08:13mark.dickinsonsetstatus: open -> closed
resolution: fixed
stage: resolved
2011-10-23 19:07:54python-devsetnosy: + python-dev
messages: + msg146247
2011-10-22 18:55:07mark.dickinsonsetfiles: + pure_python_long_to_float_v2.patch

messages: + msg146177
versions: - Python 2.7, Python 3.2
2011-01-21 23:28:46terry.reedysetnosy: + terry.reedy
messages: + msg126794
2011-01-17 13:01:07mark.dickinsonsettype: enhancement
components: + Tests
2011-01-17 13:00:41mark.dickinsoncreate