Gross error in floating-point calculation
| Bugzilla Link | 34851 |
| Resolution | FIXED |
| Resolved on | Nov 22, 2019 11:31 |
| Version | 4.0 |
| OS | Linux |
| CC | @DimitryAndric,@efriedma-quic,@ekatz,@RKSimon,@rotateright |
| Fixed by commit(s) | 8606d013983d2098ba0d9ea9c2129a0b32a93e33 |
Extended Description
This code
#include <stdio.h> #define DEN 3.645199531882474602528e-4951L int main(void){ static float f = DENDEN; static double d = DENDEN; static long double ld = DEN*DEN; printf("DEN=%Lg, f=%g, d=%g, ld=%Lg\n", DEN, f, d, ld); return 0; }
prints 'inf' instead of the expected '0.0' for f, d, and ld.
Fix available in review https://reviews.llvm.org/D69771
Indeed, this overflow occurs at compilation time, so even with -O0 the constants are incorrectly calculated...
Wow, that's kind of scary. IEEEFloat::multiplySignificand is overflowing the "exponent" field of APFloat, so a very small number turns into infinity.
assigned to @ekatz