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
2049 case '*': f1 *= f2; break;2049 case '*': f1 *= f2; break;
2050 case '/': 2050 case '/':
2051 if (f2 == 0.0) {2051 if (f2 == 0.0) {
2052 if (const_wanted)2052 /* If not in initializer we need to potentially generate
2053 tcc_error("division by zero in constant");2053 FP exceptions at runtime, otherwise we want to fold. */
2054 goto general_case;2054 if (!const_wanted)
2055 goto general_case;
2055 }2056 }
2056 f1 /= f2; 2057 f1 /= f2;
2057 break;2058 break;
tests/tcctest.c+4−0
@@ -2234,6 +2234,9 @@ void float_test(void) · 2233 unmodified lines
2234 double da, db;2234 double da, db;
2235 int a;2235 int a;
2236 unsigned int b;2236 unsigned int b;
2237 static double nan2 = 0.0/0.0;
2238 static double inf1 = 1.0/0.0;
2239 static double inf2 = 1e5000;
2237 2240
2238 printf("float_test:\n");2241 printf("float_test:\n");
2239 printf("sizeof(float) = %d\n", sizeof(float));2242 printf("sizeof(float) = %d\n", sizeof(float));
@@ -2255,6 +2258,7 @@ void float_test(void) · 15 unmodified lines
2255 b = 4000000000;2258 b = 4000000000;
2256 db = b;2259 db = b;
2257 printf("db = %f\n", db);2260 printf("db = %f\n", db);
2261 printf("nan != nan = %d, inf1 = %f, inf2 = %f\n", nan2 != nan2, inf1, inf2);
2258#endif2262#endif
2259}2263}
2260 2264

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