From fcad1067ad526de34e4658f6861aaac161c56ffd Mon Sep 17 00:00:00 2001 From: mrdudz Date: Fri, 25 Aug 2023 23:04:13 +0200 Subject: [PATCH] fix some fallout --- src/cc65/typeconv.c | 2 +- test/val/float-const-convert.c | 14 ++++++++++++++ test/val/float-mixed.c | 15 ++++++--------- 3 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 test/val/float-const-convert.c diff --git a/src/cc65/typeconv.c b/src/cc65/typeconv.c index e0f3da10f..17eef13c6 100644 --- a/src/cc65/typeconv.c +++ b/src/cc65/typeconv.c @@ -149,7 +149,6 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType, int Explicit) Expr->V.FVal = FP_D_FromInt(Expr->IVal); LOG(("DoConversion 2 new fval: %f\n", Expr->V.FVal.V)); } - /* FIXME: float --- end of new code */ /* If this is a floating point constant, convert to integer, ** and warn if precision is discarded. @@ -161,6 +160,7 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType, int Explicit) } Expr->IVal = IVal; } + /* FIXME: float --- end of new code */ /* Check if the new datatype will have a smaller range. If it ** has a larger range, things are OK, since the value is diff --git a/test/val/float-const-convert.c b/test/val/float-const-convert.c new file mode 100644 index 000000000..729595e0f --- /dev/null +++ b/test/val/float-const-convert.c @@ -0,0 +1,14 @@ +/* Demonstrates that floating point constants are allowed in a limited way. + Value will be converted to an int, with a warning if precision is lost. */ + +int a = 3.0; +int b = 23.1; +int c = -5.0; + +int main(void) +{ + if (a != 3) return 1; + if (b != 23) return 2; + if (c != -5) return 3; + return 0; +} diff --git a/test/val/float-mixed.c b/test/val/float-mixed.c index 995ebb82f..3c2758d06 100644 --- a/test/val/float-mixed.c +++ b/test/val/float-mixed.c @@ -51,11 +51,11 @@ void test1(float f, char *str) { if (compare(f, str)) { // printf(" (ok)"); - printf("\n"); } else { - printf(" (failed) !!!\n"); + printf(" (failed) !!! "); result++; } + printf("result:%d\n", result); } void SKIPPEDtest1(float f, char *str) @@ -67,15 +67,12 @@ void SKIPPEDtest1(float f, char *str) void test(void) { -#define XMIN 2.0f -#define XSTEP 0.2f - - ch = 3; printf("floatconst + intvar * floatconst\n"); - fp1 = XMIN + ch * XSTEP; - printf("fp1:0x%08lx [0x402663e6] %s (2.5997)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1)); - test1(fp1, "402663e6"); + ch = 3; + fp1 = 2.0f + ch * 0.2f; + printf("fp1:0x%08lx [0x40266666] %s (2.5997)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1)); + test1(fp1, "40266666"); ch = 4; fp1 = ch * 2.0f + 3.0f;