Description
Consider this:
import numpy as np
import fpread
print("before:", hex(fpread._control87() & fpread._MCW_PC))
np.absolute(complex(np.inf, 0))
print("after:", hex(fpread._control87() & fpread._MCW_PC))
where _control87 returns the floating point control word. Full code in https://github.com/pv/fpread
On win32, using the current numpy 1.13.1 Python 3.6 wheels from Pypi, this prints
before: 0x10000
after: 0x0
I.e., the precision mode changes from 53-bit to 64-bit. On win64 it's 0x0 before and after.
The mode is apparently not changed unless the value passed in to np.absolute is both complex-valued and contains nan or inf.
In addition to np.absolute
, also np.hypot(np.inf, 0)
appears to have the same issue.
I'm not sure if this is actually a bug, but it seems strange that np.absolute
changes the precision mode. This however appears to be a source for some fun as it seems as if this can break gfortran optimizations and make heisenbugs appear.