Skip to content

Numpy float128 overflows on ppc64le but works on x86_64 #10281

@npanpaliya

Description

@npanpaliya

While working on a tensorflow's test case, I came across a problem on ppc64le Linux system that boils down to numpy. I've also written a small test program to show case the behavior on both Power8 and x86_64. This is with numpy version 1.13.3.
Test Program

import numpy
t = numpy.float128(1.7976931e+308)
res = numpy.sqrt(t**2 + 1)
print("Result of sq root of square of 1.7976931e+308:  ", res)

Output on Power with numpy version 1.13.3:

# python test_numpyfloat128.py
test_numpyfloat128.py:3: RuntimeWarning: overflow encountered in longdouble_scalars
  res = numpy.sqrt(t**2 + 1)
('Result of sq root of square of 1.7976931e+308:  ', inf)

Min/max range of float128 on Power:

>>> numpy.finfo(numpy.float128)
finfo(resolution=1e-31, min=-1.79769313486e+308, max=1.79769313486e+308, dtype=float128)

Output on x86 with numpy version 1.13.3:

$ python test_numpyfloat128.py
('Result of sq root of square of 1.7976931e+308:  ', 1.7976931000000000494e+308)

Min/max range of float128 on x86:

>>> numpy.finfo(numpy.float128)
finfo(resolution=1e-18, min=-1.18973149536e+4932, max=1.18973149536e+4932, dtype=float128)

I've read many documents/links about float128 on Power and in general. float128 being platform dependent, is long double on x86 and some other architectures but on Power, it is double double[2]. On Power, I checked long double type is available and it is of 128-bit through a small C/C++ program. Some of the below links say that __float128 type is also available on Power7 and Power8 and we need to have VSX enabled[3], but unfortunately I'm unable to test it in a C/C++ program.

  1. https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/com.ibm.aix.genprogc/128bit_long_double_floating-point_datatype.htm
  2. https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format#Double-double_arithmetic
  3. https://gcc.gnu.org/wiki/Ieee128PowerPC#A1.3_Sizes

I have also come across many issues in numpy on Power around this float128. Also as per npy_common.h, it seems that float128 is not available on systems where size of double is 64bits, instead float64 will be used. But I'm still not sure whether Power has an unsupported feature or it's a bug in numpy on PPC.
Kindly provide me some pointers on this. Or if there is any way, with which above test can give me same results as that of x86_64.

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