From 037c8b63d548500453aeabc8c2416c5770a2e309 Mon Sep 17 00:00:00 2001 From: jhendersonHDF Date: Tue, 12 Mar 2024 07:49:41 -0500 Subject: Handle IBM long double issues in dsets.c test_floattypes test (#4116) * Handle IBM long double issues in dsets.c test_floattypes test --- test/dsets.c | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/test/dsets.c b/test/dsets.c index fe04971..efd95f6 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -5891,41 +5891,34 @@ test_floattypes(hid_t file) (long double)1.0711093225222612990711093225222612, (long double)-9.8971679387636870998971679387636870e-1}}; long double new_data[2][5]; - size_t old_precision; + size_t ld_spos, ld_epos, ld_esize, ld_mpos, ld_msize; + size_t tgt_precision = 128; TESTING(" long double (setup)"); - /* Define user-defined quad-precision floating-point type for dataset */ - datatype = H5Tcopy(H5T_NATIVE_LDOUBLE); - offset = 5; - precision = 123; - if (0 == (old_precision = H5Tget_precision(datatype))) + if ((datatype = H5Tcopy(H5T_NATIVE_LDOUBLE)) < 0) goto error; - if (old_precision < precision) { + + /* Get the layout of the native long double type */ + if (H5Tget_fields(datatype, &ld_spos, &ld_epos, &ld_esize, &ld_mpos, &ld_msize) < 0) + goto error; + + /* Check if all "tgt_precision"+ bits are already used. If not, define + * a custom floating-point type where the mantissa takes up the extra + * bits. Otherwise, just write and read using the native long double type. + */ + if (ld_esize + ld_msize + 1 < tgt_precision) { + size_t extra_bits = tgt_precision - ld_esize - ld_msize - 1; + /* Increasing precision, call H5Tset_precision first */ - if (H5Tset_precision(datatype, precision) < 0) + if (H5Tset_precision(datatype, tgt_precision) < 0) goto error; - /* H5Tset_precision may have changed our offset */ - if (H5Tset_offset(datatype, offset) < 0) + if (H5Tset_fields(datatype, ld_spos + extra_bits, ld_epos + extra_bits, ld_esize, 0, + ld_msize + extra_bits) < 0) goto error; - if (H5Tset_fields(datatype, (size_t)127, (size_t)112, (size_t)15, (size_t)offset, (size_t)107) < - 0) + if (H5Tset_size(datatype, 16) < 0) goto error; } - else { - /* Decreasing precision, call H5Tset_fields first */ - if (H5Tset_offset(datatype, offset) < 0) - goto error; - if (H5Tset_fields(datatype, (size_t)127, (size_t)112, (size_t)15, (size_t)offset, (size_t)107) < - 0) - goto error; - if (H5Tset_precision(datatype, precision) < 0) - goto error; - } - if (H5Tset_size(datatype, (size_t)16) < 0) - goto error; - if (H5Tset_ebias(datatype, (size_t)255) < 0) - goto error; /* Create the data space */ if ((space = H5Screate_simple(2, size, NULL)) < 0) -- cgit v0.12