diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2020-01-24 03:12:24 (GMT) |
---|---|---|
committer | David Young <dyoung@hdfgroup.org> | 2020-05-20 14:31:53 (GMT) |
commit | 6e8ce00c0b2fabbe552b56002f9b21916472b3d4 (patch) | |
tree | 2d9d8aa0ba0640911de385e9cfa003b5e59bb19d | |
parent | 23f103cf6b0e0c13c1ca4f3ff38cc19447ce6891 (diff) | |
download | hdf5-6e8ce00c0b2fabbe552b56002f9b21916472b3d4.zip hdf5-6e8ce00c0b2fabbe552b56002f9b21916472b3d4.tar.gz hdf5-6e8ce00c0b2fabbe552b56002f9b21916472b3d4.tar.bz2 |
Optimized the floating point comparisons a little bit.
-rw-r--r-- | tools/lib/h5diff_array.c | 48 |
1 files 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; } |