8000 On win32, np.absolute changes floating point control word · Issue #9567 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
On win32, np.absolute changes floating point control word #9567
Closed
@pv

Description

@pv

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0