mirror of
https://github.com/cc65/cc65.git
synced 2024-09-27 19:55:09 +00:00
fix ternary operator
This commit is contained in:
parent
5c5653027a
commit
fd070c9b79
@ -1,9 +1,6 @@
|
|||||||
|
|
||||||
## cc65 floating point support
|
## cc65 floating point support
|
||||||
|
|
||||||
WARNING: the following is just a brain dump after a long weekend of hacking. it
|
|
||||||
sure needs cleanup etc :)
|
|
||||||
|
|
||||||
The current goal is to implement ieee754 support in the compiler, using the
|
The current goal is to implement ieee754 support in the compiler, using the
|
||||||
"float" datatype as the common 32bit float. ANYTHING ELSE COMES LATER
|
"float" datatype as the common 32bit float. ANYTHING ELSE COMES LATER
|
||||||
|
|
||||||
@ -28,15 +25,12 @@ feel free to work on "real" ieee754 functions (see below)
|
|||||||
NOT WORKING YET:
|
NOT WORKING YET:
|
||||||
|
|
||||||
- float values as in "12.34f" work, but "12.34" does not - should it?
|
- float values as in "12.34f" work, but "12.34" does not - should it?
|
||||||
- compare, float const vs float const
|
|
||||||
|
- addition, float constant + float variable (compiles but does not work)
|
||||||
- substraction, float variable - float constant (compile error)
|
- substraction, float variable - float constant (compile error)
|
||||||
- multiplication operator, float const * float const (compile error)
|
- multiplication operator, float const * float const (compile error)
|
||||||
- division operator, float const / float const
|
- division operator, float const / float const
|
||||||
|
|
||||||
- ternary operator (compile error)
|
|
||||||
|
|
||||||
- addition, float constant + float variable (compiles but does not work)
|
|
||||||
|
|
||||||
(and probably more :))
|
(and probably more :))
|
||||||
|
|
||||||
TODO (much later):
|
TODO (much later):
|
||||||
@ -182,7 +176,7 @@ ftoseqeax Test for equal * * - -
|
|||||||
|
|
||||||
optional utility functions.
|
optional utility functions.
|
||||||
```
|
```
|
||||||
func description cbmfp cbmfp wozfp 754
|
func description softfloat cbmfp wozfp 754
|
||||||
|
|
||||||
char *_ftostr(char *d, float s) * * ? ? for printf family
|
char *_ftostr(char *d, float s) * * ? ? for printf family
|
||||||
float _strtof(char *d) - * - - for scanf family
|
float _strtof(char *d) - * - - for scanf family
|
||||||
|
@ -4332,6 +4332,9 @@ static void hieQuest (ExprDesc* Expr)
|
|||||||
} else if (IsTypeVoid (Expr2.Type) && IsTypeVoid (Expr3.Type)) {
|
} else if (IsTypeVoid (Expr2.Type) && IsTypeVoid (Expr3.Type)) {
|
||||||
/* Result type is void */
|
/* Result type is void */
|
||||||
ResultType = TypeDup (type_void);
|
ResultType = TypeDup (type_void);
|
||||||
|
} else if (IsTypeFloat (Expr2.Type) && IsTypeFloat (Expr3.Type)) {
|
||||||
|
/* Result type is float */
|
||||||
|
ResultType = TypeDup (type_float);
|
||||||
} else {
|
} else {
|
||||||
if (IsClassStruct (Expr2.Type) && IsClassStruct (Expr3.Type) &&
|
if (IsClassStruct (Expr2.Type) && IsClassStruct (Expr3.Type) &&
|
||||||
TypeCmp (Expr2.Type, Expr3.Type).C == TC_IDENTICAL) {
|
TypeCmp (Expr2.Type, Expr3.Type).C == TC_IDENTICAL) {
|
||||||
|
@ -70,18 +70,10 @@ int main(void)
|
|||||||
{
|
{
|
||||||
float fp2 = 43.21f;
|
float fp2 = 43.21f;
|
||||||
|
|
||||||
printf("float-misc\n");
|
printf("float-binary negate (not)\n");
|
||||||
printf("fp1:0x%08lx [0x414570a4] %s (12.340000)\n", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
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));
|
printf("fp2:0x%08lx [0x422cd70a] %s (43.209999)\n", *((uint32_t*)&fp2), _ftostr(buf, fp2));
|
||||||
|
|
||||||
// FIXME: does not compile
|
|
||||||
#if 0
|
|
||||||
fp1 = (fp2 == 2.5f) ? 1.5f : 0.5f;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// NOT
|
|
||||||
printf("binary negate (not)\n");
|
|
||||||
|
|
||||||
fp1 = 0.0f;
|
fp1 = 0.0f;
|
||||||
fp2 = !fp1;
|
fp2 = !fp1;
|
||||||
var_sint = !fp1;
|
var_sint = !fp1;
|
91
test/val/float-ternary.c
Normal file
91
test/val/float-ternary.c
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
|
||||||
|
// test basic arithmetic operations
|
||||||
|
// WIP WIP WIP
|
||||||
|
|
||||||
|
#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;
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
return (strcmp(temp, str) == 0) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test1(float f, char *str)
|
||||||
|
{
|
||||||
|
if (compare(f, str)) {
|
||||||
|
// printf("(ok)");
|
||||||
|
printf("\n");
|
||||||
|
} else {
|
||||||
|
printf(" (failed)\n");
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void test2(long n, long val)
|
||||||
|
{
|
||||||
|
if (n == val) {
|
||||||
|
// printf("(ok)");
|
||||||
|
printf("\n");
|
||||||
|
} else {
|
||||||
|
printf(" (failed)\n");
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
float fp2 = 43.21f;
|
||||||
|
|
||||||
|
printf("float-ternary\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));
|
||||||
|
|
||||||
|
fp1 = (fp2 == 2.5f) ? 1.5f : 0.5f;
|
||||||
|
|
||||||
|
printf("fp1 0x%08lx [0x3f000000] %s (0.5)", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||||
|
test1(fp1, "3f000000");
|
||||||
|
|
||||||
|
fp2 = 2.5f;
|
||||||
|
|
||||||
|
fp1 = (fp2 == 2.5f) ? 1.5f : 0.5f;
|
||||||
|
|
||||||
|
printf("fp1 0x%08lx [0x3fc00000] %s (1.5)", *((uint32_t*)&fp1), _ftostr(buf, fp1));
|
||||||
|
test1(fp1, "3fc00000");
|
||||||
|
|
||||||
|
printf("float-ternary (res:%d)\n", result);
|
||||||
|
return result;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user