Mark Dickinson <dicki...@gmail.com> added the comment:

[Tim]
> a couple lines of inline assembler could be added at Python startup to
> set the Pentium's FPU "precision control" bits to "round to 53 bits" mode

On second thoughts, I don't think this will work; or at least, not easily. The 
libm on such a platform may expect the FPU to be in 64-bit precision mode. So 
we'd potentially need to switch the precision before calling any math library 
function and then switch it back again afterwards. And then there may be 3rd 
party libraries that need the same treatment.

On the existence of platforms with double rounding, last time I checked, 32-bit 
Linux was the most obvious offender on Intel hardware. Windows used to use the 
x87 but set the precision to 53 bits, and I think newer versions may well use 
SSE2 in preference to x87. macOS has used SSE2 for a good number of releases 
now.

And indeed, I just tested Python 3.5.2 on Ubuntu 16.04.4 LTS 32-bit (running in 
a VM on a not-too-ancient MacBook Pro), and it exhibits double rounding:

>>> (1e16 + 2.9999).hex()
'0x1.1c37937e08002p+53'
>>> (1/2731).hex()
'0x1.7ff4005ffd002p-12'
>>> 1/(1 - 2**-53)
1.0

Expected results without double rounding:

>>> (1e16 + 2.9999).hex()
'0x1.1c37937e08001p+53'
>>> (1/2731).hex()
'0x1.7ff4005ffd001p-12'
>>> 1/(1 - 2**-53)
1.0000000000000002

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue24567>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to