llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Gross error in floating-point calculation

Open tydeman opened this issue 9 years ago • 4 comments

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.

tydeman avatar Oct 05 '17 19:10 tydeman

Fix available in review https://reviews.llvm.org/D69771

ekatz avatar Nov 06 '19 09:11 ekatz

Indeed, this overflow occurs at compilation time, so even with -O0 the constants are incorrectly calculated...

DimitryAndric avatar Oct 07 '17 11:10 DimitryAndric

Wow, that's kind of scary. IEEEFloat::multiplySignificand is overflowing the "exponent" field of APFloat, so a very small number turns into infinity.

efriedma-quic avatar Oct 06 '17 02:10 efriedma-quic

assigned to @ekatz

tydeman avatar Oct 05 '17 19:10 tydeman