From a85e4a75b27b101b5ad0e5b70bc6fe66c0375727 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Thu, 23 Jan 2020 18:58:08 -0800 Subject: Fix for failing h5diff tests involving floating-point compares. --- tools/lib/h5diff_array.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c index 6cfe3d2..f6dff64 100644 --- a/tools/lib/h5diff_array.c +++ b/tools/lib/h5diff_array.c @@ -4559,11 +4559,15 @@ static hbool_t equal_double(double value, double expected, diff_opt_t *opts) { return FALSE; } - if (H5_DBL_ABS_EQUAL(value, expected)) + /* Are the bits the same? */ + if (!HDmemcmp(&value, &expected, sizeof(double))) return TRUE; + /* Check for equality within appropriate floating-point + * tolerance, if requested. + */ if (opts->use_system_epsilon) - if (ABS((value-expected)) < DBL_EPSILON) + if (H5_DBL_ABS_EQUAL(value, expected)) return TRUE; return FALSE; @@ -4603,11 +4607,15 @@ hbool_t equal_ldouble(long double value, long double expected, diff_opt_t *opts) return FALSE; } - if (H5_LDBL_ABS_EQUAL(value, expected)) + /* Are the bits the same? */ + if (!HDmemcmp(&value, &expected, sizeof(long double))) return TRUE; + /* Check for equality within appropriate floating-point + * tolerance, if requested. + */ if (opts->use_system_epsilon) - if (ABS((value-expected)) < DBL_EPSILON) + if (H5_LDBL_ABS_EQUAL(value, expected)) return TRUE; return FALSE; @@ -4645,11 +4653,15 @@ static hbool_t equal_float(float value, float expected, diff_opt_t *opts) { return FALSE; } - if (H5_FLT_ABS_EQUAL(value, expected)) + /* Are the bits the same? */ + if (!HDmemcmp(&value, &expected, sizeof(float))) return TRUE; + /* Check for equality within appropriate floating-point + * tolerance, if requested. + */ if (opts->use_system_epsilon) - if (ABS( (value-expected) ) < FLT_EPSILON) + if (H5_FLT_ABS_EQUAL(value, expected)) return TRUE; return FALSE; -- cgit v0.12 From 9475ee5d59e9ac916271a64c5372dfc28f709417 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Thu, 23 Jan 2020 19:12:24 -0800 Subject: Optimized the floating point comparisons a little bit. --- tools/lib/h5diff_array.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c index f6dff64..3127870 100644 --- a/tools/lib/h5diff_array.c +++ b/tools/lib/h5diff_array.c @@ -4559,16 +4559,16 @@ static hbool_t equal_double(double value, double expected, diff_opt_t *opts) { return FALSE; } - /* Are the bits the same? */ - if (!HDmemcmp(&value, &expected, sizeof(double))) - return TRUE; - - /* Check for equality within appropriate floating-point - * tolerance, if requested. - */ - if (opts->use_system_epsilon) + if (opts->use_system_epsilon) { + /* Check equality within some epsilon */ if (H5_DBL_ABS_EQUAL(value, expected)) return TRUE; + } + else { + /* Check bits */ + if (!HDmemcmp(&value, &expected, sizeof(double))) + return TRUE; + } return FALSE; } @@ -4607,16 +4607,16 @@ hbool_t equal_ldouble(long double value, long double expected, diff_opt_t *opts) return FALSE; } - /* Are the bits the same? */ - if (!HDmemcmp(&value, &expected, sizeof(long double))) - return TRUE; - - /* Check for equality within appropriate floating-point - * tolerance, if requested. - */ - if (opts->use_system_epsilon) + if (opts->use_system_epsilon) { + /* Check equality within some epsilon */ if (H5_LDBL_ABS_EQUAL(value, expected)) return TRUE; + } + else { + /* Check bits */ + if (!HDmemcmp(&value, &expected, sizeof(long double))) + return TRUE; + } return FALSE; } @@ -4653,16 +4653,16 @@ static hbool_t equal_float(float value, float expected, diff_opt_t *opts) { return FALSE; } - /* Are the bits the same? */ - if (!HDmemcmp(&value, &expected, sizeof(float))) - return TRUE; - - /* Check for equality within appropriate floating-point - * tolerance, if requested. - */ - if (opts->use_system_epsilon) + if (opts->use_system_epsilon) { + /* Check equality within some epsilon */ if (H5_FLT_ABS_EQUAL(value, expected)) return TRUE; + } + else { + /* Check bits */ + if (!HDmemcmp(&value, &expected, sizeof(float))) + return TRUE; + } return FALSE; } -- cgit v0.12