diff --git a/src/H5Tconv_complex.c b/src/H5Tconv_complex.c index 7a4c553b7f2..965eb37d89f 100644 --- a/src/H5Tconv_complex.c +++ b/src/H5Tconv_complex.c @@ -66,7 +66,8 @@ /* TODO: may need to edit NOTE comment above depending on approach */ herr_t H5T__conv_complex(const H5T_t *src_p, const H5T_t *dst_p, H5T_cdata_t *cdata, const H5T_conv_ctx_t *conv_ctx, - size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg) + size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride, void *buf, + void H5_ATTR_UNUSED *bkg) { H5T_atomic_t src_atomic; /* source datatype atomic info */ H5T_atomic_t dst_atomic; /* destination datatype atomic info */ @@ -84,14 +85,16 @@ H5T__conv_complex(const H5T_t *src_p, const H5T_t *dst_p, H5T_cdata_t *cdata, co if (!H5T_IS_ATOMIC(dst_p->shared->parent->shared)) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid destination complex number datatype"); if (!src_p->shared->u.cplx.homogeneous || !dst_p->shared->u.cplx.homogeneous) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "source and destination complex number datatypes must be homogeneous"); + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, + "source and destination complex number datatypes must be homogeneous"); src_atomic = src_p->shared->parent->shared->u.atomic; dst_atomic = dst_p->shared->parent->shared->u.atomic; if (H5T_ORDER_LE != src_atomic.order && H5T_ORDER_BE != src_atomic.order && H5T_ORDER_VAX != src_atomic.order) HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order for source datatype"); - if (H5T_ORDER_LE != dst_atomic.order && H5T_ORDER_BE != dst_atomic.order && H5T_ORDER_VAX != src_atomic.order) + if (H5T_ORDER_LE != dst_atomic.order && H5T_ORDER_BE != dst_atomic.order && + H5T_ORDER_VAX != src_atomic.order) HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order for destination datatype"); if (dst_p->shared->size > TEMP_FLOAT_CONV_BUFFER_SIZE) diff --git a/test/dt_arith.c b/test/dt_arith.c index e5f7547bac1..712b2b359fc 100644 --- a/test/dt_arith.c +++ b/test/dt_arith.c @@ -77,10 +77,10 @@ typedef enum dtype_t { } dtype_t; typedef enum conv_func_ret_t { - CONV_ERROR = -1, /* Failure during conversion */ - CONV_SUCCESS, /* Converted without overflow or underflow */ - CONV_OVERFLOW, /* Converted with overflow */ - CONV_UNDERFLOW, /* Converted with underflow */ + CONV_ERROR = -1, /* Failure during conversion */ + CONV_SUCCESS, /* Converted without overflow or underflow */ + CONV_OVERFLOW, /* Converted with overflow */ + CONV_UNDERFLOW, /* Converted with underflow */ /* Complex number overflow/underflow values */ CONV_OVERFLOW_REAL, /* Converted with overflow on real part */ @@ -3729,7 +3729,7 @@ test_conv_flt_1_hw_conv_from_ldouble(void *hw_dst, unsigned char *src_buf, size_ static conv_func_ret_t test_conv_flt_1_hw_conv_from_fcomplex(void *hw_dst, unsigned char *src_buf, size_t idx, dtype_t dst_type) { - float _Complex aligned; + float _Complex aligned; conv_func_ret_t ret = CONV_SUCCESS; memcpy(&aligned, src_buf + idx * sizeof(float _Complex), sizeof(float _Complex)); @@ -3967,8 +3967,8 @@ static conv_func_ret_t test_conv_flt_1_hw_conv_from_lcomplex(void *hw_dst, unsigned char *src_buf, size_t idx, dtype_t dst_type) { long double _Complex aligned; - long double real_val, imag_val; - conv_func_ret_t ret = CONV_SUCCESS; + long double real_val, imag_val; + conv_func_ret_t ret = CONV_SUCCESS; memcpy(&aligned, src_buf + idx * sizeof(long double _Complex), sizeof(long double _Complex)); @@ -4631,10 +4631,12 @@ test_conv_flt_1(const char *name, int run_test, hid_t src, hid_t dst) if (conv_ret == CONV_ERROR) goto error; - overflow = (conv_ret == CONV_OVERFLOW || conv_ret == CONV_OVERFLOW_REAL || conv_ret == CONV_OVERFLOW_IMAG || - conv_ret == CONV_OVERFLOW_BOTH || conv_ret == CONV_OVERUNDER || conv_ret == CONV_UNDEROVER); - underflow = (conv_ret == CONV_UNDERFLOW || conv_ret == CONV_UNDERFLOW_REAL || conv_ret == CONV_UNDERFLOW_IMAG || - conv_ret == CONV_UNDERFLOW_BOTH || conv_ret == CONV_OVERUNDER || conv_ret == CONV_UNDEROVER); + overflow = + (conv_ret == CONV_OVERFLOW || conv_ret == CONV_OVERFLOW_REAL || conv_ret == CONV_OVERFLOW_IMAG || + conv_ret == CONV_OVERFLOW_BOTH || conv_ret == CONV_OVERUNDER || conv_ret == CONV_UNDEROVER); + underflow = (conv_ret == CONV_UNDERFLOW || conv_ret == CONV_UNDERFLOW_REAL || + conv_ret == CONV_UNDERFLOW_IMAG || conv_ret == CONV_UNDERFLOW_BOTH || + conv_ret == CONV_OVERUNDER || conv_ret == CONV_UNDEROVER); /* For Intel machines, the size of "long double" is 12 bytes, precision * is 80 bits; for Intel IA64 and AMD processors, the size of "long double" @@ -4826,9 +4828,9 @@ test_conv_flt_1(const char *name, int run_test, hid_t src, hid_t dst) #ifdef H5_HAVE_COMPLEX_NUMBERS else if (FLT_COMPLEX == dst_type) { float _Complex fc; - float real_val, hw_real_val; - float imag_val, hw_imag_val; - bool val_passes = true; + float real_val, hw_real_val; + float imag_val, hw_imag_val; + bool val_passes = true; memcpy(&fc, &buf[j * dst_size], sizeof(float _Complex)); real_val = crealf(fc); @@ -4838,27 +4840,31 @@ test_conv_flt_1(const char *name, int run_test, hid_t src, hid_t dst) if (underflow) { /* Check real part against hardware */ - if (conv_ret == CONV_UNDERFLOW_REAL || conv_ret == CONV_UNDERFLOW_BOTH || conv_ret == CONV_UNDEROVER) + if (conv_ret == CONV_UNDERFLOW_REAL || conv_ret == CONV_UNDERFLOW_BOTH || + conv_ret == CONV_UNDEROVER) if (fabsf(real_val) > FLT_MIN || fabsf(hw_real_val) > FLT_MIN) val_passes = false; /* Check imaginary part against hardware */ - if (conv_ret == CONV_UNDERFLOW_IMAG || conv_ret == CONV_UNDERFLOW_BOTH || conv_ret == CONV_OVERUNDER) + if (conv_ret == CONV_UNDERFLOW_IMAG || conv_ret == CONV_UNDERFLOW_BOTH || + conv_ret == CONV_OVERUNDER) if (fabsf(imag_val) > FLT_MIN || fabsf(hw_imag_val) > FLT_MIN) val_passes = false; } if (overflow) { /* Check real part against hardware */ - if (conv_ret == CONV_OVERFLOW_REAL || conv_ret == CONV_OVERFLOW_BOTH || conv_ret == CONV_OVERUNDER) + if (conv_ret == CONV_OVERFLOW_REAL || conv_ret == CONV_OVERFLOW_BOTH || + conv_ret == CONV_OVERUNDER) if (!my_isinf(dendian, buf + j * sizeof(float _Complex), dst_size / 2, dst_mpos, dst_msize, dst_epos, dst_esize)) val_passes = false; /* Check imaginary part against hardware */ - if (conv_ret == CONV_OVERFLOW_IMAG || conv_ret == CONV_OVERFLOW_BOTH || conv_ret == CONV_UNDEROVER) - if (!my_isinf(dendian, buf + (j * sizeof(float _Complex)) + (dst_size / 2), dst_size / 2, - dst_mpos, dst_msize, dst_epos, dst_esize)) + if (conv_ret == CONV_OVERFLOW_IMAG || conv_ret == CONV_OVERFLOW_BOTH || + conv_ret == CONV_UNDEROVER) + if (!my_isinf(dendian, buf + (j * sizeof(float _Complex)) + (dst_size / 2), + dst_size / 2, dst_mpos, dst_msize, dst_epos, dst_esize)) val_passes = false; } @@ -4872,9 +4878,9 @@ test_conv_flt_1(const char *name, int run_test, hid_t src, hid_t dst) } else if (DBL_COMPLEX == dst_type) { double _Complex dc; - double real_val, hw_real_val; - double imag_val, hw_imag_val; - bool val_passes = true; + double real_val, hw_real_val; + double imag_val, hw_imag_val; + bool val_passes = true; memcpy(&dc, &buf[j * dst_size], sizeof(double _Complex)); real_val = creal(dc); @@ -4884,27 +4890,31 @@ test_conv_flt_1(const char *name, int run_test, hid_t src, hid_t dst) if (underflow) { /* Check real part against hardware */ - if (conv_ret == CONV_UNDERFLOW_REAL || conv_ret == CONV_UNDERFLOW_BOTH || conv_ret == CONV_UNDEROVER) + if (conv_ret == CONV_UNDERFLOW_REAL || conv_ret == CONV_UNDERFLOW_BOTH || + conv_ret == CONV_UNDEROVER) if (fabs(real_val) > DBL_MIN || fabs(hw_real_val) > DBL_MIN) val_passes = false; /* Check imaginary part against hardware */ - if (conv_ret == CONV_UNDERFLOW_IMAG || conv_ret == CONV_UNDERFLOW_BOTH || conv_ret == CONV_OVERUNDER) + if (conv_ret == CONV_UNDERFLOW_IMAG || conv_ret == CONV_UNDERFLOW_BOTH || + conv_ret == CONV_OVERUNDER) if (fabs(imag_val) > DBL_MIN || fabs(hw_imag_val) > DBL_MIN) val_passes = false; } if (overflow) { /* Check real part against hardware */ - if (conv_ret == CONV_OVERFLOW_REAL || conv_ret == CONV_OVERFLOW_BOTH || conv_ret == CONV_OVERUNDER) + if (conv_ret == CONV_OVERFLOW_REAL || conv_ret == CONV_OVERFLOW_BOTH || + conv_ret == CONV_OVERUNDER) if (!my_isinf(dendian, buf + j * sizeof(double _Complex), dst_size / 2, dst_mpos, dst_msize, dst_epos, dst_esize)) val_passes = false; /* Check imaginary part against hardware */ - if (conv_ret == CONV_OVERFLOW_IMAG || conv_ret == CONV_OVERFLOW_BOTH || conv_ret == CONV_UNDEROVER) - if (!my_isinf(dendian, buf + (j * sizeof(double _Complex)) + (dst_size / 2), dst_size / 2, - dst_mpos, dst_msize, dst_epos, dst_esize)) + if (conv_ret == CONV_OVERFLOW_IMAG || conv_ret == CONV_OVERFLOW_BOTH || + conv_ret == CONV_UNDEROVER) + if (!my_isinf(dendian, buf + (j * sizeof(double _Complex)) + (dst_size / 2), + dst_size / 2, dst_mpos, dst_msize, dst_epos, dst_esize)) val_passes = false; } @@ -4918,8 +4928,8 @@ test_conv_flt_1(const char *name, int run_test, hid_t src, hid_t dst) } else if (LDBL_COMPLEX == dst_type) { long double _Complex ldc; - long double real_val, hw_real_val; - long double imag_val, hw_imag_val; + long double real_val, hw_real_val; + long double imag_val, hw_imag_val; memcpy(&ldc, &buf[j * dst_size], sizeof(long double _Complex)); real_val = creall(ldc); @@ -4941,12 +4951,14 @@ test_conv_flt_1(const char *name, int run_test, hid_t src, hid_t dst) if (FLT_COMPLEX == dst_type || DBL_COMPLEX == dst_type || LDBL_COMPLEX == dst_type) { if (check_expo[0] < (-(int)dst_ebias) || check_expo[1] < (-(int)dst_ebias) || check_expo[2] < (-(int)dst_ebias) || check_expo[3] < (-(int)dst_ebias)) { - double epsilon_real = 1.0; - double epsilon_imag = 1.0; - int expo_diff_real = check_expo[0] - check_expo[1]; - int expo_diff_imag = check_expo[2] - check_expo[3]; - int valid_bits_real = (int)((dst_ebias + dst_msize) + (size_t)MIN(check_expo[0], check_expo[1])) - 1; - int valid_bits_imag = (int)((dst_ebias + dst_msize) + (size_t)MIN(check_expo[2], check_expo[3])) - 1; + double epsilon_real = 1.0; + double epsilon_imag = 1.0; + int expo_diff_real = check_expo[0] - check_expo[1]; + int expo_diff_imag = check_expo[2] - check_expo[3]; + int valid_bits_real = + (int)((dst_ebias + dst_msize) + (size_t)MIN(check_expo[0], check_expo[1])) - 1; + int valid_bits_imag = + (int)((dst_ebias + dst_msize) + (size_t)MIN(check_expo[2], check_expo[3])) - 1; /* Re-scale the mantissas based on any exponent difference */ if (expo_diff_real != 0) @@ -4964,8 +4976,10 @@ test_conv_flt_1(const char *name, int run_test, hid_t src, hid_t dst) continue; } else { - if ((check_expo[0] == check_expo[1] && fabs(check_mant[0] - check_mant[1]) < (double)FP_EPSILON) && - (check_expo[2] == check_expo[3] && fabs(check_mant[2] - check_mant[3]) < (double)FP_EPSILON)) + if ((check_expo[0] == check_expo[1] && + fabs(check_mant[0] - check_mant[1]) < (double)FP_EPSILON) && + (check_expo[2] == check_expo[3] && + fabs(check_mant[2] - check_mant[3]) < (double)FP_EPSILON)) continue; } } diff --git a/test/dtypes.c b/test/dtypes.c index 2f28307f1d6..351b22c6d30 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -7221,7 +7221,7 @@ test_complex_type_conv(void) H5T_t *native_double_complex = NULL; H5T_t *native_ldouble_complex = NULL; #endif - hid_t complex_tid = H5I_INVALID_HID; + hid_t complex_tid = H5I_INVALID_HID; TESTING("complex number datatype conversions");