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.

Author mark.dickinson
Recipients mark.dickinson
Date 2008-06-21.21:11:57
SpamBayes Score 0.0503535
Marked as misclassified No
Message-id <>
If n is a Python long, then one might expect float(n) to return the 
closest float to n.  Currently it doesn't do this.  For example (with 
Python 2.6, on OS X 10.5.2/Intel):

>>> n = 295147905179352891391L

The closest float to n is equal to n+1.  But float(n) returns the 
further of the two floats bracketing n, equal to n-65535:

>>> float(n)
>>> long(float(n))
>>> n - long(float(n))

It's fairly straightforward to fix PyLong_AsDouble to return the closest 
double to a given long integer n (using the round-half-to-even rule in 
the case of a tie).  The attached patch does this.

Having a correctly rounded float(n) can be useful for testing other 
floating-point routines that are supposed to be correctly rounded.
Date User Action Args
2008-06-21 21:12:00mark.dickinsonsetspambayes_score: 0.0503535 -> 0.0503535
recipients: + mark.dickinson
2008-06-21 21:12:00mark.dickinsonsetspambayes_score: 0.0503535 -> 0.0503535
messageid: <>
2008-06-21 21:11:59mark.dickinsonlinkissue3166 messages
2008-06-21 21:11:59mark.dickinsoncreate