Skip to content

Commit

Permalink
Handle IBM long double issues in dsets.c test_floattypes test (HDFGro…
Browse files Browse the repository at this point in the history
…up#4116)

* Handle IBM long double issues in dsets.c test_floattypes test
  • Loading branch information
jhendersonHDF authored and lrknox committed Mar 21, 2024
1 parent a7fe8e8 commit 770f91f
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions test/dsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 770f91f

Please sign in to comment.