History

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).

Michael Matz committed 8 years ago

Commit 414b2241 parent 9e47b182 files · +8 −3Browse files

Unified · Split

2 files
  1. tccgen.c +4 −3
  2. tests/tcctest.c +4 −0
tccgen.c+4−3
@@ -2049,9 +2049,10 @@ static void gen_opif(int op) · 2048 unmodified lines
20492049 case '*': f1 *= f2; break;
20502050 case '/':
20512051 if (f2 == 0.0) {
2052− if (const_wanted)
2053− tcc_error("division by zero in constant");
2054− goto general_case;
2052+ /* If not in initializer we need to potentially generate
2053+ FP exceptions at runtime, otherwise we want to fold. */
2054+ if (!const_wanted)
2055+ goto general_case;
20552056 }
20562057 f1 /= f2;
20572058 break;
tests/tcctest.c+4−0
@@ -2234,6 +2234,9 @@ void float_test(void) · 2233 unmodified lines
22342234 double da, db;
22352235 int a;
22362236 unsigned int b;
2237+ static double nan2 = 0.0/0.0;
2238+ static double inf1 = 1.0/0.0;
2239+ static double inf2 = 1e5000;
22372240
22382241 printf("float_test:\n");
22392242 printf("sizeof(float) = %d\n", sizeof(float));
@@ -2255,6 +2258,7 @@ void float_test(void) · 15 unmodified lines
22552258 b = 4000000000;
22562259 db = b;
22572260 printf("db = %f\n", db);
2261+ printf("nan != nan = %d, inf1 = %f, inf2 = %f\n", nan2 != nan2, inf1, inf2);
22582262 #endif
22592263 }
22602264

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t