diff options
Diffstat (limited to 'tools/lib/h5diff_array.c')
-rw-r--r-- | tools/lib/h5diff_array.c | 206 |
1 files changed, 111 insertions, 95 deletions
diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c index 2b18acc..13d2353 100644 --- a/tools/lib/h5diff_array.c +++ b/tools/lib/h5diff_array.c @@ -142,10 +142,10 @@ static hbool_t all_zero(const void *_mem, size_t size); static int ull2float(unsigned long_long ull_value, float *f_value); static hsize_t character_compare(unsigned char *mem1,unsigned char *mem2,hsize_t i,unsigned u,int rank,hsize_t *dims,hsize_t *acc,hsize_t *pos,diff_opt_t *options,const char *obj1,const char *obj2,int *ph); static hsize_t character_compare_opt(unsigned char *mem1,unsigned char *mem2,hsize_t i,int rank,hsize_t *dims,hsize_t *acc,hsize_t *pos,diff_opt_t *options,const char *obj1,const char *obj2,int *ph); -static hbool_t equal_float(float value, float expected); -static hbool_t equal_double(double value, double expected); +static hbool_t equal_float(float value, float expected, diff_opt_t *options); +static hbool_t equal_double(double value, double expected, diff_opt_t *options); #if H5_SIZEOF_LONG_DOUBLE !=0 -static hbool_t equal_ldouble(long double value, long double expected); +static hbool_t equal_ldouble(long double value, long double expected, diff_opt_t *options); #endif static int print_data(diff_opt_t *options); static void print_pos(int *ph,int pp,hsize_t curr_pos,hsize_t *acc,hsize_t *pos,int rank,hsize_t *dims,const char *obj1,const char *obj2 ); @@ -1971,7 +1971,7 @@ hsize_t diff_datum(void *_mem1, * no -d and -p *------------------------------------------------------------------------- */ - else if (equal_float(temp1_float,temp2_float)==FALSE) + else if (equal_float(temp1_float,temp2_float,options)==FALSE) { if ( print_data(options) ) @@ -2140,7 +2140,7 @@ hsize_t diff_datum(void *_mem1, * no -d and -p *------------------------------------------------------------------------- */ - else if (equal_double(temp1_double,temp2_double)==FALSE) + else if (equal_double(temp1_double,temp2_double,options)==FALSE) { if ( print_data(options) ) { @@ -2311,7 +2311,7 @@ hsize_t diff_datum(void *_mem1, * no -d and -p *------------------------------------------------------------------------- */ - else if (equal_ldouble(temp1_double,temp2_double)==FALSE) + else if (equal_ldouble(temp1_double,temp2_double,options)==FALSE) { if ( print_data(options) ) { @@ -2932,7 +2932,7 @@ hsize_t diff_float(unsigned char *mem1, memcpy(&temp2_float, mem2, sizeof(float)); - if (equal_float(temp1_float,temp2_float)==FALSE) + if (equal_float(temp1_float,temp2_float,options)==FALSE) { if ( print_data(options) ) { @@ -3115,7 +3115,7 @@ hsize_t diff_double(unsigned char *mem1, memcpy(&temp1_double, mem1, sizeof(double)); memcpy(&temp2_double, mem2, sizeof(double)); - if (equal_double(temp1_double,temp2_double)==FALSE) + if (equal_double(temp1_double,temp2_double,options)==FALSE) { if ( print_data(options) ) { @@ -3294,7 +3294,7 @@ hsize_t diff_ldouble(unsigned char *mem1, memcpy(&temp1_double, mem1, sizeof(long double)); memcpy(&temp2_double, mem2, sizeof(long double)); - if (equal_ldouble(temp1_double,temp2_double)==FALSE) + if (equal_ldouble(temp1_double,temp2_double,options)==FALSE) { if ( print_data(options) ) { @@ -5184,48 +5184,53 @@ error: *------------------------------------------------------------------------- */ static -hbool_t equal_double(double value, double expected) +hbool_t equal_double(double value, double expected, diff_opt_t *options) { int both_zero; int is_zero; -/*------------------------------------------------------------------------- - * detect NaNs - *------------------------------------------------------------------------- - */ - int isnan1 = my_isnan(FLT_DOUBLE,&value); - int isnan2 = my_isnan(FLT_DOUBLE,&expected); - - /*------------------------------------------------------------------------- - * we consider NaN == NaN to be true - *------------------------------------------------------------------------- - */ - if ( isnan1 && isnan2 ) - { - return TRUE; - } - /*------------------------------------------------------------------------- - * one is a NaN, do not compare but assume difference - *------------------------------------------------------------------------- - */ - if ( (isnan1 && !isnan2) || ( !isnan1 && isnan2 ) ) + if ( options->do_nans ) { - return FALSE; + + /*------------------------------------------------------------------------- + * detect NaNs + *------------------------------------------------------------------------- + */ + int isnan1 = my_isnan(FLT_DOUBLE,&value); + int isnan2 = my_isnan(FLT_DOUBLE,&expected); + + /*------------------------------------------------------------------------- + * we consider NaN == NaN to be true + *------------------------------------------------------------------------- + */ + if ( isnan1 && isnan2 ) + { + return TRUE; + } + + /*------------------------------------------------------------------------- + * one is a NaN, do not compare but assume difference + *------------------------------------------------------------------------- + */ + if ( (isnan1 && !isnan2) || ( !isnan1 && isnan2 ) ) + { + return FALSE; + } + + /*------------------------------------------------------------------------- + * both are not NaNs, compare + *------------------------------------------------------------------------- + */ } - /*------------------------------------------------------------------------- - * both are not NaNs, compare - *------------------------------------------------------------------------- - */ - BOTH_ZERO(value,expected) if (both_zero) return TRUE; IS_ZERO(expected) if (is_zero) - return(equal_double(expected,value)); + return(equal_double(expected,value,options)); if ( ABS( (value-expected) / expected) < H5DIFF_DBL_EPSILON) return TRUE; @@ -5245,48 +5250,54 @@ hbool_t equal_double(double value, double expected) #if H5_SIZEOF_LONG_DOUBLE !=0 static -hbool_t equal_ldouble(long double value, long double expected) +hbool_t equal_ldouble(long double value, long double expected, diff_opt_t *options) { int both_zero; int is_zero; -/*------------------------------------------------------------------------- - * detect NaNs - *------------------------------------------------------------------------- - */ - int isnan1 = my_isnan(FLT_LDOUBLE,&value); - int isnan2 = my_isnan(FLT_LDOUBLE,&expected); - - /*------------------------------------------------------------------------- - * we consider NaN == NaN to be true - *------------------------------------------------------------------------- - */ - if ( isnan1 && isnan2 ) - { - return TRUE; - } - - /*------------------------------------------------------------------------- - * one is a NaN, do not compare but assume difference - *------------------------------------------------------------------------- - */ - if ( (isnan1 && !isnan2) || ( !isnan1 && isnan2 ) ) + + if ( options->do_nans ) { - return FALSE; + + /*------------------------------------------------------------------------- + * detect NaNs + *------------------------------------------------------------------------- + */ + int isnan1 = my_isnan(FLT_LDOUBLE,&value); + int isnan2 = my_isnan(FLT_LDOUBLE,&expected); + + /*------------------------------------------------------------------------- + * we consider NaN == NaN to be true + *------------------------------------------------------------------------- + */ + if ( isnan1 && isnan2 ) + { + return TRUE; + } + + /*------------------------------------------------------------------------- + * one is a NaN, do not compare but assume difference + *------------------------------------------------------------------------- + */ + if ( (isnan1 && !isnan2) || ( !isnan1 && isnan2 ) ) + { + return FALSE; + } + + /*------------------------------------------------------------------------- + * both are not NaNs, compare + *------------------------------------------------------------------------- + */ + } - /*------------------------------------------------------------------------- - * both are not NaNs, compare - *------------------------------------------------------------------------- - */ - BOTH_ZERO(value,expected) if (both_zero) return TRUE; IS_ZERO(expected) if (is_zero) - return(equal_ldouble(expected,value)); + return(equal_ldouble(expected,value,options)); if ( ABS( (value-expected) / expected) < H5DIFF_DBL_EPSILON) return TRUE; @@ -5310,48 +5321,53 @@ hbool_t equal_ldouble(long double value, long double expected) *------------------------------------------------------------------------- */ static -hbool_t equal_float(float value, float expected) +hbool_t equal_float(float value, float expected, diff_opt_t *options) { int both_zero; int is_zero; -/*------------------------------------------------------------------------- - * detect NaNs - *------------------------------------------------------------------------- - */ - int isnan1 = my_isnan(FLT_FLOAT,&value); - int isnan2 = my_isnan(FLT_FLOAT,&expected); - - /*------------------------------------------------------------------------- - * we consider NaN == NaN to be true - *------------------------------------------------------------------------- - */ - if ( isnan1 && isnan2 ) + if ( options->do_nans ) { - return TRUE; - } - - /*------------------------------------------------------------------------- - * one is a NaN, do not compare but assume difference - *------------------------------------------------------------------------- - */ - if ( (isnan1 && !isnan2) || ( !isnan1 && isnan2 ) ) - { - return FALSE; + + /*------------------------------------------------------------------------- + * detect NaNs + *------------------------------------------------------------------------- + */ + int isnan1 = my_isnan(FLT_FLOAT,&value); + int isnan2 = my_isnan(FLT_FLOAT,&expected); + + /*------------------------------------------------------------------------- + * we consider NaN == NaN to be true + *------------------------------------------------------------------------- + */ + if ( isnan1 && isnan2 ) + { + return TRUE; + } + + /*------------------------------------------------------------------------- + * one is a NaN, do not compare but assume difference + *------------------------------------------------------------------------- + */ + if ( (isnan1 && !isnan2) || ( !isnan1 && isnan2 ) ) + { + return FALSE; + } + + /*------------------------------------------------------------------------- + * both are not NaNs, compare + *------------------------------------------------------------------------- + */ + } - /*------------------------------------------------------------------------- - * both are not NaNs, compare - *------------------------------------------------------------------------- - */ - BOTH_ZERO(value,expected) if (both_zero) return TRUE; IS_ZERO(expected) if (is_zero) - return(equal_float(expected,value)); + return(equal_float(expected,value,options)); if ( ABS( (value-expected) / expected) < H5DIFF_FLT_EPSILON) return TRUE; |