1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-08 15:29:37 +00:00

fix int var - float const, fix float var - int var

This commit is contained in:
mrdudz 2023-09-02 01:56:18 +02:00
parent a8e9783f1c
commit 82346b24db
4 changed files with 29 additions and 25 deletions

View File

@ -14,12 +14,12 @@ build small (and slow...) programs that use floats on any supported target.
- Build the compiler/toolchain/libs from this fptest branch.
- Now you can build the samples and/or tests.
```
samples/floattest.c
samples/mandelfloat.c
samples/mathtest.c (requires full math.h)
samples/tgisincos.c (requires sin/cos from math.h)
```
full math.h is available for C64 when linking agains fp754kernal.o (see below)
### Further info
@ -89,10 +89,10 @@ NOT WORKING YET:
/test/val/float-basic-var-var.c +=, -=
/test/val/float-basic-var-intvar.c -, +=, -=
/test/val/float-basic-var-intvar.c +=, -=
/test/val/float-basic-var-intconst.c -, *, /, +=, -=, *=, /=
/test/val/float-basic-intvar-const.c -, +=, -=, *=, /=
/test/val/float-basic-intvar-const.c +=, -=, *=, /=
/test/val/float-basic-intvar-var.c -, *, /, +=, /=
/test/val/float-basic-intconst-var.c *, /

View File

@ -3942,10 +3942,15 @@ static void parsesub (ExprDesc* Expr)
#if 1
} else if (IsClassFloat (lhst) && IsClassFloat (rhst)) {
/* Float subtraction. We'll adjust the types later */
LOG(("parsesub: float - float\n"));
} else if (IsClassFloat (lhst) && IsClassInt (rhst)) {
/* Float/Int subtraction. We'll adjust the types later */
LOG(("parsesub: float - int\n"));
flags |= CF_FLOAT;
} else if (IsClassInt (lhst) && IsClassFloat (rhst)) {
/* Int/Float subtraction. We'll adjust the types later */
LOG(("parsesub: int - float\n"));
flags |= CF_FLOAT;
#endif
} else {
/* OOPS */
@ -3954,17 +3959,22 @@ static void parsesub (ExprDesc* Expr)
}
if (ED_IsConstAbs (&Expr2)) {
/* rhs is constant */
/* Remove pushed value from stack */
RemoveCode (&Mark2);
if (IsClassInt (lhst)) {
LOG(("const int sub 1\n"));
LOG(("parsesub: lhst int sub 1\n"));
/* Adjust the types */
flags = typeadjust (Expr, &Expr2, 1);
/* Do the subtraction */
g_dec (flags | CF_CONST, Expr2.IVal * rscale);
if (IsClassFloat(rhst)) {
g_dec (flags | CF_CONST, FP_D_As32bitRaw(Expr2.V.FVal));
} else {
g_dec (flags | CF_CONST, Expr2.IVal * rscale);
}
}
else if (IsClassFloat (lhst)) {
LOG(("const float sub 2\n"));
LOG(("parsesub: lhst float sub 2\n"));
/* Adjust the types */
flags = typeadjust (Expr, &Expr2, 1);
if (rscale != 1) {

View File

@ -86,7 +86,6 @@ void intvarconst(void)
printf("fp1:0x%08lx [42687df4] %s (47)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
fp1 = 11.123f;
printf("fp1:0x%08lx [42687df4] %s (11.123)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
#endif
printf("int var + float const\n");
@ -99,14 +98,14 @@ void intvarconst(void)
fp1 = var_int + 11.123f;
printf("fp1:0x%08lx [42687df4] %s (58.123)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "42687df4");
/* subtraction */
#if 0 // gives wrong result
fp1 = var_int - 11.123f;
printf("fp1:0x%08lx [?] %s (35.877)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "42687df4");
#endif
/* subtraction */
#if 1 // gives wrong result
fp1 = var_int - 11.123f;
printf("fp1:0x%08lx [420f820c] %s (35.877)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "420f820c");
#endif
#if 1
/* multiplication */
fp1 = var_int * 11.123f;
printf("fp1:0x%08lx [4402b1fc] %s (522.781)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
@ -116,7 +115,7 @@ void intvarconst(void)
fp1 = var_int / 11.123f;
printf("fp1:0x%08lx [4087371f] %s (4.2254)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "4087371f");
#endif
}
unsigned int i1;

View File

@ -81,23 +81,18 @@ void intvar(void)
fp1 = var_float + var_int;
printf("fp1:0x%08lx [42687df4] %s (58.123)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "42687df4");
#if 0 // Invalid operands for binary operator '-'
fp1 = var_float - var_int;
printf("fp1:0x%08lx [42687df4] %s (-35.877)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "42687df4");
#endif
#if 1
printf("fp1:0x%08lx [c20f820c] %s (-35.877)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "c20f820c");
fp1 = var_float * var_int;
printf("fp1:0x%08lx [4402b1fc] %s (522.781)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "4402b1fc");
#endif
#if 1
fp1 = var_float / var_int;
printf("fp1:0x%08lx [3e7256e3] %s (0.2367)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
test1(fp1, "3e7256e3");
#endif
}
void intvar2(void)