[issue3166] Make conversions from long to float correctly rounded.

Mark Dickinson report at bugs.python.org
Tue Dec 9 22:02:37 CET 2008


Mark Dickinson <dickinsm at gmail.com> added the comment:

> floating-point variable "x" has an exact nonnegative integer value 
> between 0 and 2**DBL_MANT_DIG. 

Hmm.  On closer inspection that's not quite true.  After the line

x = x * PyLong_BASE + (dig & (PyLong_BASE - pmask));

x has a value of the form n * pmask, where pmask is a power of 2 and
n is in the range [0, 2**DBL_MANT_DIG).  It's still exactly represented, 
provided that FLT_RADIX is 2.  (It's the multiplications by powers of 2 
that get hairy when FLT_RADIX is 16, since they *can* lose information.)

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3166>
_______________________________________


More information about the Python-bugs-list mailing list