mirror of
https://github.com/cc65/cc65.git
synced 2024-06-17 16:29:32 +00:00
fix int variable + float constant, fix float variable + int constant, add tests
This commit is contained in:
parent
3164917f46
commit
dd5f12b352
|
@ -3420,15 +3420,42 @@ static void parseadd (ExprDesc* Expr, int DoArrayRef)
|
|||
/*flags = typeadjust (Expr, &Expr2, 1);*/
|
||||
flags |= CF_FLOAT;
|
||||
Expr->Type = Expr2.Type;
|
||||
#if 1
|
||||
} else if (!DoArrayRef && IsClassInt (lhst) && IsClassFloat (rhst)) {
|
||||
/* FIXME: float - what to do here exactly? */
|
||||
LOG(("%s:%d float addition (Expr2.V.FVal.V:%f)\n", __FILE__, __LINE__, Expr2.V.FVal.V));
|
||||
/* Float addition (int variable + float constant) */
|
||||
/* adjust lhs */
|
||||
flags = typeadjust (Expr, &Expr2, 1);
|
||||
// flags |= CF_FLOAT;
|
||||
// Expr->Type = Expr2.Type;
|
||||
#endif
|
||||
#if 1
|
||||
} else if (!DoArrayRef && IsClassFloat (lhst) && IsClassInt (rhst)) {
|
||||
/* FIXME: float - what to do here exactly? */
|
||||
LOG(("%s:%d float addition (Expr2.V.FVal.V:%f)\n", __FILE__, __LINE__, Expr2.V.FVal.V));
|
||||
/* Float addition (float variable + int constant) */
|
||||
/*flags = typeadjust (Expr, &Expr2, 1);*/
|
||||
flags |= CF_FLOAT;
|
||||
// Expr->Type = Expr2.Type;
|
||||
// g_push(CF_FLOAT, 0);
|
||||
/* Load lhs */
|
||||
// flags = typeadjust (Expr, &Expr2, 0);
|
||||
#endif
|
||||
} else {
|
||||
/* OOPS */
|
||||
LOG(("%s:%d OOPS\n", __FILE__, __LINE__));
|
||||
AddDone = -1;
|
||||
}
|
||||
|
||||
/* add rhs constant value */
|
||||
if (flags & CF_FLOAT) {
|
||||
/* FIXME: float - what to do here exactly? */
|
||||
g_inc (flags | CF_CONST, FP_D_As32bitRaw(Expr2.V.FVal));
|
||||
if (IsClassInt (rhst)) {
|
||||
g_inc (flags | CF_CONST, FP_D_As32bitRaw(FP_D_FromInt(Expr2.IVal)));
|
||||
} else {
|
||||
g_inc (flags | CF_CONST, FP_D_As32bitRaw(Expr2.V.FVal));
|
||||
}
|
||||
} else {
|
||||
/* Generate code for the add */
|
||||
g_inc (flags | CF_CONST, Expr2.IVal);
|
||||
|
|
99
test/val/float-basic-intvar-const.c
Normal file
99
test/val/float-basic-intvar-const.c
Normal file
|
@ -0,0 +1,99 @@
|
|||
|
||||
// test basic arithmetic operations
|
||||
|
||||
#ifdef CONIO
|
||||
#include <conio.h>
|
||||
#define WAIT() cgetc()
|
||||
#else
|
||||
#define WAIT()
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <_float.h>
|
||||
|
||||
float fp1 = 12.34f;
|
||||
float fp2; // non initialized
|
||||
float fp3, fp4 = 55.55f;
|
||||
|
||||
char buf[0x20];
|
||||
char buf2[0x20];
|
||||
char buf3[0x20];
|
||||
|
||||
unsigned long l1,l2;
|
||||
|
||||
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;
|
||||
int i;
|
||||
|
||||
unsigned char var_char;
|
||||
unsigned int var_int;
|
||||
float var_float;
|
||||
|
||||
// returns 1 if value in f matches the string
|
||||
// the string is a hex value without leading "0x"
|
||||
int compare(float f, char *str)
|
||||
{
|
||||
char temp[12];
|
||||
sprintf(temp, "%08lx", *((uint32_t*)&f));
|
||||
printf("[%s:%s]", temp, str);
|
||||
return (strcmp(temp, str) == 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
void test1(float f, char *str)
|
||||
{
|
||||
if (compare(f, str)) {
|
||||
// printf(" (ok)");
|
||||
} else {
|
||||
printf(" (failed) !!! ");
|
||||
result++;
|
||||
}
|
||||
printf("result:%d\n", result);
|
||||
}
|
||||
|
||||
void SKIPPEDtest1(float f, char *str)
|
||||
{
|
||||
char temp[12];
|
||||
sprintf(temp, "%08lx", *((uint32_t*)&f));
|
||||
printf(" (SKIPPED:%s:%s)\n", temp, str);
|
||||
}
|
||||
|
||||
void test(void)
|
||||
{
|
||||
var_int = 47;
|
||||
#if 1
|
||||
fp1 = var_int;
|
||||
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
|
||||
/* addition */
|
||||
fp1 = var_int + 11.123f;
|
||||
printf("fp1:0x%08lx [42687df4] %s (58.123)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
test1(fp1, "42687df4");
|
||||
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float fp2 = 43.21f;
|
||||
|
||||
printf("*** float-basic-intvar-const ***\n");
|
||||
printf("fp1:0x%08lx [0x414570a4] %s (12.340000)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
printf("fp2:0x%08lx [0x422cd70a] %s (43.209999)\n", *((uint32_t*)&fp2), _ftostr(buf, fp2));
|
||||
|
||||
test();
|
||||
WAIT();
|
||||
|
||||
printf("\nfloat-basic-intvar-const (res:%d)\n", result);
|
||||
return result;
|
||||
}
|
101
test/val/float-basic-var-intconst.c
Normal file
101
test/val/float-basic-var-intconst.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
|
||||
// test basic arithmetic operations
|
||||
|
||||
#ifdef CONIO
|
||||
#include <conio.h>
|
||||
#define WAIT() cgetc()
|
||||
#else
|
||||
#define WAIT()
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <_float.h>
|
||||
|
||||
float fp1 = 12.34f;
|
||||
float fp2; // non initialized
|
||||
float fp3, fp4 = 55.55f;
|
||||
|
||||
char buf[0x20];
|
||||
char buf2[0x20];
|
||||
char buf3[0x20];
|
||||
|
||||
unsigned long l1,l2;
|
||||
|
||||
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;
|
||||
int i;
|
||||
|
||||
unsigned char var_char;
|
||||
unsigned int var_int;
|
||||
float var_float;
|
||||
|
||||
// returns 1 if value in f matches the string
|
||||
// the string is a hex value without leading "0x"
|
||||
int compare(float f, char *str)
|
||||
{
|
||||
char temp[12];
|
||||
sprintf(temp, "%08lx", *((uint32_t*)&f));
|
||||
printf("[%s:%s]", temp, str);
|
||||
return (strcmp(temp, str) == 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
void test1(float f, char *str)
|
||||
{
|
||||
if (compare(f, str)) {
|
||||
// printf(" (ok)");
|
||||
} else {
|
||||
printf(" (failed) !!! ");
|
||||
result++;
|
||||
}
|
||||
printf("result:%d\n", result);
|
||||
}
|
||||
|
||||
void SKIPPEDtest1(float f, char *str)
|
||||
{
|
||||
char temp[12];
|
||||
sprintf(temp, "%08lx", *((uint32_t*)&f));
|
||||
printf(" (SKIPPED:%s:%s)\n", temp, str);
|
||||
}
|
||||
|
||||
void test(void)
|
||||
{
|
||||
|
||||
var_float = 11.123f;
|
||||
#if 1
|
||||
fp1 = 47;
|
||||
printf("fp1:0x%08lx [42687df4] %s (47)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
fp1 = var_float;
|
||||
printf("fp1:0x%08lx [42687df4] %s (11.123)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
#endif
|
||||
#if 1 // Invalid operands for binary operator '+'
|
||||
/* addition */
|
||||
fp1 = var_float + 47;
|
||||
printf("fp1:0x%08lx [42687df4] %s (58.123)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
test1(fp1, "42687df4");
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
float fp2 = 43.21f;
|
||||
|
||||
printf("*** float-basic-var-intconst ***\n");
|
||||
printf("fp1:0x%08lx [0x414570a4] %s (12.340000)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||
printf("fp2:0x%08lx [0x422cd70a] %s (43.209999)\n", *((uint32_t*)&fp2), _ftostr(buf, fp2));
|
||||
|
||||
test();
|
||||
WAIT();
|
||||
|
||||
printf("\nfloat-basic-var-intconst (res:%d)\n", result);
|
||||
return result;
|
||||
}
|
Loading…
Reference in New Issue
Block a user