Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

kkwli
Copy link
Contributor

@kkwli kkwli commented Sep 11, 2025

numpy.power() does not raise the overflow exception with numpy.float64 type.
It can be illustrated in the following code.

import numpy as np
#fi = np.finfo(np.float64)
dtyp = np.dtype(np.float64).type
with np.errstate(all='raise'):
  try:
    x = np.power(dtyp(2), dtyp(2048))   # 2**fi.nexp == 2048
    print(f'No fpe error ({x})')
  except FloatingPointError as exc:
    print(f'FloatingPointError')

Output on AIX:

No fpe error (inf)

Output on Linux/PowerPC and Linux/x86:

FloatingPointError

This patch is to guard the self.assert_raises_fpe(overflow, np.power, ftype(2), ftype(2**fi.nexp)) test to skip it on AIX.

# it returns inf. Long double is the same as double.
if sys.platform != 'aix' or typecode not in 'dDgG':
self.assert_raises_fpe(overflow,
np.power, ftype(2), ftype(2**fi.nexp))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this papering over a bug in our floating point exception detection or is this just a fundamental limitation of the AIX math library?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants