summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2007-02-05 19:22:26 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2007-02-05 19:22:26 (GMT)
commita82e85c2d408386b14859f40c572a3911aaaa682 (patch)
tree3d41a800b047a185814eed5dde195bffdd15b947
parent08ea58bac21f32f091045b28bccee27d95d0effe (diff)
downloadhdf5-a82e85c2d408386b14859f40c572a3911aaaa682.zip
hdf5-a82e85c2d408386b14859f40c572a3911aaaa682.tar.gz
hdf5-a82e85c2d408386b14859f40c572a3911aaaa682.tar.bz2
[svn-r13238] A trial fix for the comparison of equality between floating-point values in hyperslab.c. A few
macros are defined in h5test.h to check if the difference between two values is smaller than Epsilon.
-rw-r--r--test/h5test.h15
-rw-r--r--test/hyperslab.c6
2 files changed, 20 insertions, 1 deletions
diff --git a/test/h5test.h b/test/h5test.h
index 640a882..8187bcf 100644
--- a/test/h5test.h
+++ b/test/h5test.h
@@ -117,6 +117,21 @@ extern MPI_Info h5_io_info_g; /* MPI INFO object for IO */
/* set alarms to N seconds if N > 0, else use default alarm_seconds. */
#define ALARM_SET(N) HDalarm((N)>0 ? N : alarm_seconds)
+/*
+ * The methods to compare the equality of floating-point values:
+ * 1. XXX_ABS_EQUAL - check if the difference is smaller than the
+ * Epsilon value. The Epsilon values, FLT_EPSILON, DBL_EPSILON,
+ * and LDBL_EPSILON, are defined by compiler in float.h.
+ * 2. To be defined later.
+ */
+#define FLT_ABS_EQUAL(X,Y) (fabsf(X-Y)<FLT_EPSILON)
+#define DBL_ABS_EQUAL(X,Y) (fabs(X-Y)<DBL_EPSILON)
+#define LDBL_ABS_EQUAL(X,Y) (fabsl(X-Y)<LDBL_EPSILON)
+
+/*#define FP_ABS_UNEQUAL(X,Y,T) ((T==1 && fabsf(X-Y)>FLT_EPSILON) || \
+ (T==2 && fabs(X-Y)>DBL_EPSILON) || \
+ (T==3 && fabsl(X-Y)>LDBL_EPSILON))*/
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/test/hyperslab.c b/test/hyperslab.c
index 0a46faf..16bd1bb 100644
--- a/test/hyperslab.c
+++ b/test/hyperslab.c
@@ -663,7 +663,11 @@ test_multifill(size_t nx)
for (i = 0; i < nx; i++) {
if (dst[i].left != 3333333) {
sprintf(s, "bad dst[%lu].left", (unsigned long)i);
- } else if (dst[i].mid != fill.mid) {
+ } else if (!DBL_ABS_EQUAL(dst[i].mid, fill.mid)) {
+ /* Check if two DOUBLE values are equal. If their difference
+ * is smaller than the EPSILON value for double, they are
+ * considered equal. See the definition in h5test.h.
+ */
sprintf(s, "bad dst[%lu].mid", (unsigned long)i);
} else if (dst[i].right != 4444444) {
sprintf(s, "bad dst[%lu].right", (unsigned long)i);