From c7ec51bf36f986d2ec98e7b2743724821cb3d220 Mon Sep 17 00:00:00 2001
From: Jonathan Helmus <jjhelmus@gmail.com>
Date: Tue, 6 Feb 2018 15:01:45 -0500
Subject: [PATCH 2/2] long double conversion tests on ppc64le

---
 test/dt_arith.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff -urN a/test/dt_arith.c b/test/dt_arith.c
--- a/test/dt_arith.c	2021-07-02 00:26:41.000000000 +0300
+++ b/test/dt_arith.c	2022-06-14 15:12:58.177467545 +0300
@@ -3130,7 +3130,18 @@
 #if H5_SIZEOF_LONG_DOUBLE != H5_SIZEOF_DOUBLE && H5_SIZEOF_LONG_DOUBLE != 0
             }
             else if (src_type == FLT_LDOUBLE) {
-                INIT_FP_SPECIAL(src_size, src_nbits, sendian, LDBL_MANT_DIG, dst_size, buf, saved, nelmts);
+                size_t mant_dig = LDBL_MANT_DIG;
+                if (mant_dig >= src_nbits) {
+                    /* This happens for IBM long double in little endian.
+                       The macro LDBL_MANT_DIG says 106 mantissa bits, but the
+                       HDF5 detection code actually represents it as a normal 64bit
+                       double (52 bit mantissa) with the upper double being
+                       unspec bits (which is sort of okay as the testsuite
+                       wouldn't deal with that format correctly anyway).  So
+                       override the mantissa size.  */
+                    mant_dig = 52;
+                }
+                INIT_FP_SPECIAL(src_size, src_nbits, sendian, mant_dig, dst_size, buf, saved, nelmts);
 #endif
             }
             else
@@ -3840,7 +3851,18 @@
                            nelmts);
         }
         else {
-            INIT_FP_SPECIAL(src_size, src_nbits, sendian, LDBL_MANT_DIG, dst_size, buf, saved, nelmts);
+            size_t mant_dig = LDBL_MANT_DIG;
+            if (mant_dig >= src_nbits) {
+                /* This happens for IBM long double in little endian.
+                   The macro LDBL_MANT_DIG says 106 mantissa bits, but the
+                   HDF5 detection code actually represents it as a normal 64bit
+                   double (52 bit mantissa) with the upper double being
+                   unspec bits (which is sort of okay as the testsuite
+                   wouldn't deal with that format correctly anyway).  So
+                   override the mantissa size.  */
+                mant_dig = 52;
+            }
+            INIT_FP_SPECIAL(src_size, src_nbits, sendian, mant_dig, dst_size, buf, saved, nelmts);
         }
 #endif
     }
