mirror of
https://github.com/cc65/cc65.git
synced 2024-06-18 07:29:36 +00:00
add some tests on comparing floats vs ints. not all cases working
This commit is contained in:
parent
f7f5d39f20
commit
cfdf6aef9d
|
@ -39,27 +39,94 @@ int result = 0;
|
|||
result++; \
|
||||
}
|
||||
|
||||
// when making individual sub tests work, remove them here and uncomment them
|
||||
// in val/float-cmp.c
|
||||
void constconst(void)
|
||||
{
|
||||
//-------------------------------------------------------------------------
|
||||
// float constant vs float const
|
||||
printf("const vs const\n");
|
||||
|
||||
expect("1.5f == 1.6f is", 0, (1.5f == 1.6f));
|
||||
expect("1.6f == 1.5f is", 0, (1.6f == 1.5f));
|
||||
expect("1.6f == 1.6f is", 1, (1.6f == 1.6f));
|
||||
|
||||
expect("1.5f != 1.6f is", 1, (1.5f != 1.6f));
|
||||
expect("1.6f != 1.5f is", 1, (1.6f != 1.5f));
|
||||
expect("1.6f != 1.6f is", 0, (1.6f != 1.6f));
|
||||
|
||||
expect("1.5f < 1.6f is", 1, (1.5f < 1.6f));
|
||||
expect("1.6f < 1.5f is", 0, (1.6f < 1.5f));
|
||||
expect("1.6f < 1.6f is", 0, (1.6f < 1.6f));
|
||||
|
||||
expect("1.5f > 1.6f is", 0, (1.5f > 1.6f));
|
||||
expect("1.6f > 1.5f is", 1, (1.6f > 1.5f));
|
||||
expect("1.6f > 1.6f is", 0, (1.6f > 1.6f));
|
||||
|
||||
expect("1.5f <= 1.6f is", 1, (1.5f <= 1.6f));
|
||||
expect("1.6f <= 1.5f is", 0, (1.6f <= 1.5f));
|
||||
expect("1.6f <= 1.6f is", 1, (1.6f <= 1.6f));
|
||||
|
||||
expect("1.5f >= 1.6f is", 0, (1.5f >= 1.6f));
|
||||
expect("1.6f >= 1.5f is", 1, (1.6f >= 1.5f));
|
||||
expect("1.6f >= 1.6f is", 1, (1.6f >= 1.6f));
|
||||
}
|
||||
|
||||
void intconstconst(void)
|
||||
{
|
||||
printf("int const vs const\n");
|
||||
|
||||
// FIXME: Comparing types 'int' with 'float' is invalid
|
||||
#if 0
|
||||
expect("10 == 1.6f is", 0, (10 == 1.6f));
|
||||
expect("20 == 1.5f is", 0, (20 == 1.5f));
|
||||
expect("20 == 1.6f is", 1, (20 == 1.6f));
|
||||
|
||||
expect("10 != 1.6f is", 1, (10 != 1.6f));
|
||||
expect("20 != 1.5f is", 1, (20 != 1.5f));
|
||||
expect("20 != 1.6f is", 0, (20 != 1.6f));
|
||||
|
||||
expect("10 < 1.6f is", 1, (10 < 1.6f));
|
||||
expect("20 < 1.5f is", 0, (20 < 1.5f));
|
||||
expect("20 < 1.6f is", 0, (20 < 1.6f));
|
||||
|
||||
expect("10 > 1.6f is", 0, (10 > 1.6f));
|
||||
expect("20 > 1.5f is", 1, (20 > 1.5f));
|
||||
expect("20 > 1.6f is", 0, (20 > 1.6f));
|
||||
|
||||
expect("10 <= 1.6f is", 1, (10 <= 1.6f));
|
||||
expect("20 <= 1.5f is", 0, (20 <= 1.5f));
|
||||
expect("20 <= 1.6f is", 1, (20 <= 1.6f));
|
||||
|
||||
expect("10 >= 1.6f is", 0, (10 >= 1.6f));
|
||||
expect("20 >= 1.5f is", 1, (20 >= 1.5f));
|
||||
expect("20 >= 1.6f is", 1, (20 >= 1.6f));
|
||||
#endif
|
||||
}
|
||||
|
||||
void constintconst(void)
|
||||
{
|
||||
printf("const vs int const\n");
|
||||
|
||||
expect("10.0f == 20 is", 0, (10.0f == 20));
|
||||
expect("20.0f == 10 is", 0, (20.0f == 10));
|
||||
expect("20.0f == 20 is", 1, (20.0f == 20));
|
||||
|
||||
expect("10.0f != 20 is", 1, (10.0f != 20));
|
||||
expect("20.0f != 10 is", 1, (20.0f != 10));
|
||||
expect("20.0f != 20 is", 0, (20.0f != 20));
|
||||
|
||||
expect("10.0f < 20 is", 1, (10.0f < 20));
|
||||
expect("20.0f < 10 is", 0, (20.0f < 10));
|
||||
expect("20.0f < 20 is", 0, (20.0f < 20));
|
||||
|
||||
expect("10.0f > 20 is", 0, (10.0f > 20));
|
||||
expect("20.0f > 10 is", 1, (20.0f > 10));
|
||||
expect("20.0f > 20 is", 0, (20.0f > 20));
|
||||
|
||||
expect("10.0f <= 20 is", 1, (10.0f <= 20));
|
||||
expect("20.0f <= 10 is", 0, (20.0f <= 10));
|
||||
expect("20.0f <= 20 is", 1, (20.0f <= 20));
|
||||
|
||||
expect("10.0f >= 20 is", 0, (10.0f >= 20));
|
||||
expect("20.0f >= 10 is", 1, (20.0f >= 10));
|
||||
expect("20.0f >= 20 is", 1, (20.0f >= 20));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -69,6 +136,8 @@ int main(void)
|
|||
printf("float-cmp-const-const\n");
|
||||
|
||||
constconst();
|
||||
intconstconst();
|
||||
constintconst();
|
||||
|
||||
printf("float-cmp-const-const (res: %d)\n", result);
|
||||
return result;
|
||||
|
|
|
@ -39,9 +39,6 @@ int result = 0;
|
|||
result++; \
|
||||
}
|
||||
|
||||
// float constant vs float variable
|
||||
// when making individual sub tests work, remove them here and uncomment them
|
||||
// in val/float-cmp.c
|
||||
void constvar(void)
|
||||
{
|
||||
printf("const vs var\n");
|
||||
|
@ -69,8 +66,44 @@ void constvar(void)
|
|||
expect("1.5f >= 1.6f is", 0, (1.5f >= fp1));
|
||||
expect("1.6f >= 1.5f is", 1, (1.6f >= fp2));
|
||||
expect("1.6f >= 1.6f is", 1, (1.6f >= fp1));
|
||||
|
||||
}
|
||||
|
||||
void intconstvar(void)
|
||||
{
|
||||
printf("int const vs var\n");
|
||||
|
||||
fp1 = 20.0f;
|
||||
fp2 = 10.0f;
|
||||
|
||||
// Comparing types 'int' with 'float' is invalid
|
||||
#if 0
|
||||
expect("10 == 20 is", 0, (10 == fp1));
|
||||
expect("20 == 10 is", 0, (20 == fp2));
|
||||
expect("20 == 20 is", 1, (20 == fp1));
|
||||
|
||||
expect("10 != 20 is", 1, (10 != fp1));
|
||||
expect("20 != 10 is", 1, (20 != fp2));
|
||||
expect("20 != 20 is", 0, (20 != fp1));
|
||||
|
||||
expect("10 < 20 is", 1, (10 < fp1));
|
||||
expect("20 < 10 is", 0, (20 < fp2));
|
||||
expect("20 < 20 is", 0, (20 < fp1));
|
||||
|
||||
expect("10 > 20 is", 0, (10 > fp1));
|
||||
expect("20 > 10 is", 1, (20 > fp2));
|
||||
expect("20 > 20 is", 0, (20 > fp1));
|
||||
|
||||
expect("10 <= 20 is", 1, (10 <= fp1));
|
||||
expect("20 <= 10 is", 0, (20 <= fp2));
|
||||
expect("20 <= 20 is", 1, (20 <= fp1));
|
||||
|
||||
expect("10 >= 20 is", 0, (10 >= fp1));
|
||||
expect("20 >= 10 is", 1, (20 >= fp2));
|
||||
expect("20 >= 20 is", 1, (20 >= fp1));
|
||||
#endif
|
||||
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
int main(void)
|
||||
|
@ -80,6 +113,7 @@ int main(void)
|
|||
fp1 = 1.6f;
|
||||
fp2 = 1.5f;
|
||||
constvar();
|
||||
intconstvar();
|
||||
|
||||
printf("float-cmp-const-var (res: %d)\n", result);
|
||||
return result;
|
||||
|
|
|
@ -31,10 +31,12 @@ unsigned long var_ulong;
|
|||
int result = 0;
|
||||
|
||||
#define expect(msg, exp, val) \
|
||||
printf("%s %s%s\n", \
|
||||
printf("%s %s%s (is:%d want:%d)\n", \
|
||||
msg, \
|
||||
val ? "true" : "false", \
|
||||
(exp != val) ? " (failed)" : ""); \
|
||||
(exp != val) ? " (failed)" : "", \
|
||||
exp, val \
|
||||
); \
|
||||
if (exp != val) { \
|
||||
result++; \
|
||||
}
|
||||
|
@ -42,8 +44,6 @@ int result = 0;
|
|||
//-------------------------------------------------------------------------
|
||||
// float variable vs float constant
|
||||
|
||||
// when making individual sub tests work, remove them here and uncomment them
|
||||
// in val/float-cmp.c
|
||||
void varconst(void)
|
||||
{
|
||||
printf("var vs const\n");
|
||||
|
@ -51,19 +51,62 @@ void varconst(void)
|
|||
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));
|
||||
|
||||
}
|
||||
|
||||
void varintconst(void)
|
||||
{
|
||||
printf("var vs int const\n");
|
||||
|
||||
fp1 = 10.0f;
|
||||
fp2 = 20.0f;
|
||||
|
||||
expect("20 == 10 is", 0, (fp2 == 10));
|
||||
expect("10 == 20 is", 0, (fp1 == 20));
|
||||
expect("10 == 10 is", 1, (fp1 == 10));
|
||||
|
||||
expect("20 != 10 is", 1, (fp2 != 10));
|
||||
expect("10 != 20 is", 1, (fp1 != 20));
|
||||
expect("10 != 10 is", 0, (fp1 != 10));
|
||||
|
||||
// expect("20 < 10 is", 1, (fp2 < 10));
|
||||
// expect("10 < 20 is", 0, (fp1 < 20));
|
||||
expect("10 < 10 is", 0, (fp1 < 10));
|
||||
|
||||
// expect("20 > 10 is", 0, (fp2 > 10));
|
||||
// expect("10 > 20 is", 1, (fp1 > 20));
|
||||
expect("10 > 10 is", 0, (fp1 > 10));
|
||||
|
||||
// expect("20 <= 10 is", 1, (fp2 <= 10));
|
||||
// expect("10 <= 20 is", 0, (fp1 <= 20));
|
||||
expect("10 <= 10 is", 1, (fp1 <= 10));
|
||||
|
||||
// expect("20 >= 10 is", 0, (fp2 >= 10));
|
||||
// expect("10 >= 20 is", 1, (fp1 >= 20));
|
||||
expect("10 >= 10 is", 1, (fp1 >= 10));
|
||||
|
||||
}
|
||||
|
||||
|
@ -72,6 +115,7 @@ int main(void)
|
|||
printf("float-cmp-var-const\n");
|
||||
|
||||
varconst();
|
||||
varintconst();
|
||||
|
||||
printf("float-cmp-var-const (res: %d)\n", result);
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue
Block a user