mirror of
https://github.com/cc65/cc65.git
synced 2024-06-08 15:29:37 +00:00
in an expression when both sides are constant, and one side is float, convert the other side to float and make the result float
This commit is contained in:
parent
34420ac153
commit
7467503f6e
|
@ -730,12 +730,16 @@ void _g_getimmed(unsigned Flags, uintptr_t Val, long Offs)
|
|||
switch (Flags & CF_TYPEMASK) {
|
||||
|
||||
case CF_CHAR:
|
||||
LOG(("g_getimmed CF_CHAR Val: %08lx\n", Val));
|
||||
ASMLOG(("nop\t; g_getimmed CF_CHAR %08lx\n", Val)); // FIXME: remove
|
||||
if ((Flags & CF_FORCECHAR) != 0) {
|
||||
AddCodeLine ("lda #$%02X", (unsigned char) Val);
|
||||
break;
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
case CF_INT:
|
||||
LOG(("g_getimmed CF_INT Val: %08lx\n", Val));
|
||||
ASMLOG(("nop\t; g_getimmed CF_INT %08lx\n", Val)); // FIXME: remove
|
||||
AddCodeLine ("ldx #$%02X", (unsigned char) (Val >> 8));
|
||||
AddCodeLine ("lda #$%02X", (unsigned char) Val);
|
||||
break;
|
||||
|
|
|
@ -2259,12 +2259,24 @@ LOG(("hie_internal Expr->Type:%s Expr2->Type:%s\n",
|
|||
this must be extended to handle mixed operations */
|
||||
// if ((IsClassFloat (Expr->Type) == CF_FLOAT) &&
|
||||
// (IsClassFloat (Expr2.Type) == CF_FLOAT)) {
|
||||
if ((Expr->Type == type_float) &&
|
||||
if ((ltype == CF_FLOAT) ||
|
||||
(Expr2.Type == type_float)) {
|
||||
/* Evaluate the result for float operands */
|
||||
Double Val1 = Expr->V.FVal;
|
||||
Double Val2 = Expr2.V.FVal;
|
||||
LOG(("hie_internal float X float\n"));
|
||||
Double Val1;
|
||||
Double Val2;
|
||||
LOG(("hie_internal float X float %d %d\n", Expr->IVal, Expr2.IVal));
|
||||
if (ltype == CF_FLOAT) {
|
||||
Val1 = Expr->V.FVal;
|
||||
} else {
|
||||
Val1 = FP_D_FromInt(Expr->IVal);
|
||||
}
|
||||
if (TypeOf (Expr2.Type) == CF_FLOAT) {
|
||||
Val2 = Expr2.V.FVal;
|
||||
} else {
|
||||
Val2 = FP_D_FromInt(Expr2.IVal);
|
||||
}
|
||||
LOG(("hie_internal float X float %f %f\n", Expr->V.FVal.V, Expr2.V.FVal.V));
|
||||
|
||||
switch (Tok) {
|
||||
case TOK_DIV:
|
||||
#if 0 // TODO
|
||||
|
@ -2973,7 +2985,7 @@ static void hie9 (ExprDesc *Expr)
|
|||
{ TOK_INVALID, 0, 0 }
|
||||
};
|
||||
int UsedGen;
|
||||
|
||||
LOG(("hie9\n"));
|
||||
hie_internal (hie9_ops, Expr, hie10, &UsedGen);
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,21 @@ void test(void)
|
|||
fp1 = XMIN + ch * XSTEP;
|
||||
printf("fp1:0x%08lx [0x3f19979a] %s (0.5999)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
test1(fp1, "3f19979a");
|
||||
|
||||
printf("floatconst / intconst, intconst / floatconst\n");
|
||||
fp1 = ( (20.0f / 4.5f));
|
||||
fp2 = ( (4.5f / 20.0f));
|
||||
printf(" fp1:0x%08lx [0x408e38e4] %s (exp:4.444445)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
test1(fp1, "408e38e4");
|
||||
printf(" fp2:0x%08lx [0x3e666666] %s (exp:0.225000)\n", *((uint32_t*)&fp2), _ftostr(buf, fp2));
|
||||
test1(fp2, "3e666666");
|
||||
|
||||
fp1 = ((20 / 4.5f)); // 4.44
|
||||
fp2 = ((4.5f / 20)); // 0.225
|
||||
printf(" fp1:0x%08lx [0x408e38e4] %s (exp:4.444445)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
test1(fp1, "408e38e4");
|
||||
printf(" fp2:0x%08lx [0x3e666666] %s (exp:0.225000)\n", *((uint32_t*)&fp2), _ftostr(buf, fp2));
|
||||
test1(fp2, "3e666666");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
|
Loading…
Reference in New Issue
Block a user