mirror of
https://github.com/frida/tinycc
synced 2024-11-28 02:29:38 +03:00
Accept more floating point constant expressions
the rules for constant expressions in static initializers are more relaxed than for integer constant expressions. We need to accept 0.0/0.0 in static initializers (in non-static initializers the potential exceptions need to be raised though, so no translation-time calculation then).
This commit is contained in:
parent
9e47b18229
commit
414b224efa
7
tccgen.c
7
tccgen.c
@ -2049,9 +2049,10 @@ static void gen_opif(int op)
|
||||
case '*': f1 *= f2; break;
|
||||
case '/':
|
||||
if (f2 == 0.0) {
|
||||
if (const_wanted)
|
||||
tcc_error("division by zero in constant");
|
||||
goto general_case;
|
||||
/* If not in initializer we need to potentially generate
|
||||
FP exceptions at runtime, otherwise we want to fold. */
|
||||
if (!const_wanted)
|
||||
goto general_case;
|
||||
}
|
||||
f1 /= f2;
|
||||
break;
|
||||
|
@ -2234,6 +2234,9 @@ void float_test(void)
|
||||
double da, db;
|
||||
int a;
|
||||
unsigned int b;
|
||||
static double nan2 = 0.0/0.0;
|
||||
static double inf1 = 1.0/0.0;
|
||||
static double inf2 = 1e5000;
|
||||
|
||||
printf("float_test:\n");
|
||||
printf("sizeof(float) = %d\n", sizeof(float));
|
||||
@ -2255,6 +2258,7 @@ void float_test(void)
|
||||
b = 4000000000;
|
||||
db = b;
|
||||
printf("db = %f\n", db);
|
||||
printf("nan != nan = %d, inf1 = %f, inf2 = %f\n", nan2 != nan2, inf1, inf2);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user