From 1f260277f7feb5b5aca365bd9a9275a8384ab574 Mon Sep 17 00:00:00 2001 From: Jordan Henderson Date: Mon, 11 Mar 2024 18:23:45 -0500 Subject: [PATCH 1/2] Handle IBM long double issues in dsets.c test_floattypes test --- test/dsets.c | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/test/dsets.c b/test/dsets.c index fe04971847c..41e06c219c6 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -5891,41 +5891,35 @@ 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 + * 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) From 55924ba22f7bb3e1df5f4b6b601663bfc446b675 Mon Sep 17 00:00:00 2001 From: Jordan Henderson Date: Mon, 11 Mar 2024 19:56:19 -0500 Subject: [PATCH 2/2] Fix comment --- test/dsets.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/dsets.c b/test/dsets.c index 41e06c219c6..efd95f60366 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -5905,8 +5905,7 @@ test_floattypes(hid_t file) /* Check if all "tgt_precision"+ bits are already used. If not, define * a custom floating-point type where the mantissa takes up the extra - * extra bits. Otherwise, just write and read using the native long - * double type. + * 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;