https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120937
Bug ID: 120937 Summary: floating-point arithmetic can result zero with incorrect sign Product: gcc Version: 13.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: madams846 at hotmail dot com Target Milestone: --- The result of a*b+c can be zero with incorrect negative sign for some values of a, b, c. The program #include <stdio.h> int main() { double a= 5.174463056948843312e-23; double b= 7.778216080286462531e-19; double c= -4.024809449233739591e-41; printf(" a*b+c %f \n", a*b+c ); return 0 ; } compiled with “gcc program.c” prints out “a*b+c -0.000000”. Another set of values that returns negative zero is a= -2.542400512695312500e+02, b= -8.732892029672259986e-42, c= -2.220250918039383963e-39. The result is negative zero also for these values as types long double and __float128 BUT not for type float. The same program with a= 2.0 b=2.0 c= -4.0 prints out “a*b+c 0.000000”. According to the Wikipedia page on signed zero the IEEE 754 – 2008 rules have x – x = x + (-x) = +0 for any finite x except when rounding toward negative. This bug seems to be new. It arose when testing a larger program with random values. This bug did not appear on my system last week but now appears consistently in testing. I run sudo apt update and upgrade on Linux about once a week. My system: Ubuntu 24.04.2 LTS (GNU/Linux 6.6.87.1-microsoft-standard-WSL2 x86_64) WSL 5.10.102.1 Dell PC 64-bit 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz Windows 11 Home 24H2 OS build 26100.4351 gcc version 13.3.0-6ubuntu2~24.04