diff options
author | jhendersonHDF <jhenderson@hdfgroup.org> | 2024-03-12 12:49:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-12 12:49:41 (GMT) |
commit | 037c8b63d548500453aeabc8c2416c5770a2e309 (patch) | |
tree | 72a71659ab560d5ac193781ddc7ec29338978109 | |
parent | 4b297e986c6d53224c305b42acbbebcff4eade63 (diff) | |
download | hdf5-037c8b63d548500453aeabc8c2416c5770a2e309.zip hdf5-037c8b63d548500453aeabc8c2416c5770a2e309.tar.gz hdf5-037c8b63d548500453aeabc8c2416c5770a2e309.tar.bz2 |
Handle IBM long double issues in dsets.c test_floattypes test (#4116)
* Handle IBM long double issues in dsets.c test_floattypes test
-rw-r--r-- | test/dsets.c | 45 |
1 files 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) |