[svn-r13388] Added a relative comparison between floating-point values to avoid compiler's

warning of comparing values with "==" or "!=".
This commit is contained in:
Raymond Lu 2007-02-26 11:55:45 -05:00
parent cd8dfb4650
commit 3ea2c632d5
3 changed files with 12 additions and 7 deletions

View File

@ -5160,7 +5160,7 @@ test_set_local(hid_t fapl)
h5_fixname(FILENAME[5], fapl, filename, sizeof filename);
/* Initialize the integer & floating-point dataset */
n=0.0;
n=1.0;
for (i = 0; i < DSET_DIM1; i++)
for (j = 0; j < DSET_DIM2; j++) {
points[i][j] = (int)n++;
@ -5356,7 +5356,9 @@ test_set_local(hid_t fapl)
/* Check that the values read are the modified version of what was written */
for (i=0; i<dims[0]; i++) {
for (j=0; j<dims[1]; j++) {
if (points_dbl[i][j] != check_dbl[i][j]) {
/* If the difference between two values is greater than 0.001%, they're
* considered not equal. */
if(!DBL_REL_EQUAL(points_dbl[i][j],check_dbl[i][j],0.00001)) {
H5_FAILED();
printf(" Line %d: Read different values than written.\n",__LINE__);
printf(" At index %lu,%lu\n", (unsigned long)(i), (unsigned long)(j));

View File

@ -693,6 +693,7 @@ h5_show_hostname(void)
WSACleanup();
#endif
}
#ifdef H5_HAVE_PARALLEL
/*

View File

@ -123,15 +123,18 @@ extern MPI_Info h5_io_info_g; /* MPI INFO object for IO */
* 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.
* 2. XXX_REL_EQUAL - check if the relative difference is smaller than a
* predefined value M. See if two values are relatively equal.
* It's the test's responsibility not to pass in the value 0, which
* may cause the equation to fail.
*/
#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))*/
#define FLT_REL_EQUAL(X,Y,M) (fabsf((Y-X)/X<M)
#define DBL_REL_EQUAL(X,Y,M) (fabs((Y-X)/X)<M)
#define LDBL_REL_EQUAL(X,Y,M) (fabsl((Y-X)/X)<M)
#ifdef __cplusplus
extern "C" {
@ -174,7 +177,6 @@ H5TEST_DLL const void *GetTestParameters(void);
H5TEST_DLL int TestErrPrintf(const char *format, ...);
H5TEST_DLL void SetTest(const char *testname, int action);
#ifdef H5_HAVE_FILTER_SZIP
H5TEST_DLL int h5_szip_can_encode(void);
#endif /* H5_HAVE_FILTER_SZIP */