diff --git a/tccgen.c b/tccgen.c index c88c537..2c365be 100644 --- a/tccgen.c +++ b/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; diff --git a/tests/tcctest.c b/tests/tcctest.c index 57670be..f807966 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -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 }