// test comparison operations #include #include #include #include <_float.h> #ifdef CONIO #include #define WAIT() cgetc() #else #define WAIT() #endif float fp1, fp2, fp3, fp4; char buf[0x30]; char buf2[0x30]; char buf3[0x30]; signed char var_schar; unsigned char var_uchar; signed int var_sint; unsigned int var_uint; signed long var_slong; unsigned long var_ulong; int result = 0; #define expect(msg, exp, val) \ printf("%s %s%s (is:%d want:%d)\n", \ msg, \ val ? "true" : "false", \ (exp != val) ? " (failed)" : "", \ exp, val \ ); \ if (exp != val) { \ result++; \ } //------------------------------------------------------------------------- // float variable vs float constant void varconst(void) { printf("var vs const\n"); fp1 = 1.6f; fp2 = 1.5f; expect("1.5f == 1.6f is", 0, (fp2 == 1.6f)); expect("1.6f == 1.5f is", 0, (fp1 == 1.5f)); expect("1.6f == 1.6f is", 1, (fp1 == 1.6f)); expect("1.5f != 1.6f is", 1, (fp2 != 1.6f)); expect("1.6f != 1.5f is", 1, (fp1 != 1.5f)); expect("1.6f != 1.6f is", 0, (fp1 != 1.6f)); expect("1.5f < 1.6f is", 1, (fp2 < 1.6f)); expect("1.6f < 1.5f is", 0, (fp1 < 1.5f)); expect("1.6f < 1.6f is", 0, (fp1 < 1.6f)); expect("1.5f > 1.6f is", 0, (fp2 > 1.6f)); expect("1.6f > 1.5f is", 1, (fp1 > 1.5f)); expect("1.6f > 1.6f is", 0, (fp1 > 1.6f)); expect("1.5f <= 1.6f is", 1, (fp2 <= 1.6f)); expect("1.6f <= 1.5f is", 0, (fp1 <= 1.5f)); expect("1.6f <= 1.6f is", 1, (fp1 <= 1.6f)); expect("1.5f >= 1.6f is", 0, (fp2 >= 1.6f)); expect("1.6f >= 1.5f is", 1, (fp1 >= 1.5f)); expect("1.6f >= 1.6f is", 1, (fp1 >= 1.6f)); } int main(void) { printf("float-cmp-var-const\n"); varconst(); printf("float-cmp-var-const (res: %d)\n", result); return result; }