01: #define TGEN_FLT_EQ(a, b) ( ((a)==(b)) || ABS(((a) - (b))) / MAX( ABS(a), ABS(b) ) <= __FLT_EPSILON__ ) 02: #define OK_f 1.0 03: #define NO_f 0.0 04: float ftest; 05: 06: int main(void) 07: { 08: float Float; 09: 10: ftest = NO_f; 11: Float = OK_f; 12: ftest = Float * Float + Float / Float - Float; 13: 14: if ( (TGEN_FLT_EQ(ftest, OK_f)) ) 15: printok(); 16: if ( (TGEN_FLT_EQ(ftest, NO_f)) ) 17: printno(); 18: 19: return 0; 20: } |
01: #define TGEN_FLT_EQ(a, b) ( ((a)==(b)) || ABS(((a) - (b))) / MAX( ABS(a), ABS(b) ) <= __FLT_EPSILON__ ) 02: #define OK_f 1.0 03: #define NO_f 0.0 04: #define NOK_f 20.0 05: 06: float ftest; 07: 08: int main(void) 09: { 10: float Float; 11: 12: ftest = NO_f; 13: Float = OK_f; 14: ftest = (Float + Float + Float + Float + Float + Float + Float + Float + Float + Float + Float + Float + Float + Float + Float + Float + Float + Float + Float + Float) / NOK_f; 15: 16: if ( (TGEN_FLT_EQ(ftest, OK_f)) ) 17: printok(); 18: if ( (TGEN_FLT_EQ(ftest, NO_f)) ) 19: printno(); 20: 21: return 0; 22: } |