Bug 39034 - Decimal floating-point math done wrong
Summary: Decimal floating-point math done wrong
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.3.2
: P3 normal
Target Milestone: 4.3.3
Assignee: Janis Johnson
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2009-01-30 01:22 UTC by Fred J. Tydeman
Modified: 2010-04-07 09:32 UTC (History)
6 users (show)

See Also:
Host: 4.3.2
Target: 4.3.2
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-01-30 20:46:02


Attachments
expanded testcase (688 bytes, text/plain)
2009-01-30 20:44 UTC, Janis Johnson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Fred J. Tydeman 2009-01-30 01:22:41 UTC
Using gcc 4.3.2-7 on Intel Pentium 4 running Fedora Core 10 with -std=gnu99 of

/* DFP TR 24732 == WG14 / N1176, N1312 */
#define __STDC_WANT_DEC_FP__ /* Tell implementation that we want Decimal FP */
#include <stdio.h>	/* printf() */

int main(void){
  double     d2  = (double)((28./3.-9.) - (31./3.-10.));
  _Decimal64 d10 = (double)((28./3.-9.) - (31./3.-10.));
  if( d2 ){
    printf("d2 should be zero\n");
  }
  if( d10 ){
    printf("d10 should be zero\n");
  }
  return 0;
}

gets:

d10 should be zero

This should be independent of Translation Time Data Type (TTDT)
which has been dropped from the DFP TR as of WG14 N1312.
Comment 1 Fred J. Tydeman 2009-01-30 17:31:31 UTC
My analysis shows that
  d10=0x2fe0000000000003=+3.e-15
So, d10 is not zero, while d2 is zero.
Comment 2 Janis Johnson 2009-01-30 20:44:55 UTC
Created attachment 17214 [details]
expanded testcase

I expanded the testcase to test both constant folding and runtime calculations for all three decimal float types.

The problem occurs with 4.3.3 but not with mainline.  I can track down the patch that fixed it if anyone is interested.

Test results for trunk and 4.3 for powerpc64-linux and x86-linux (bid and dpd):

elm3b187% uname -m
ppc64
elm3b187% /opt/gcc-nightly/trunk/bin/gcc -DDBG -O2 -std=gnu99 39034.c && ./a.out 
elm3b187% /opt/gcc-nightly/4.3/bin/gcc -DDBG -O2 -std=gnu99 39034.c && ./a.out
line 29: runtime: d32 should be zero
line 42: runtime: d64 should be zero
line 56: runtime: d128 should be zero
Aborted


laptop% uname -m
i686
laptop% /home/janis/tools/gcc-trunk-bid/bin/gcc -DDBG -O2 -std=gnu99 39034.c && ./a.out
laptop% /home/janis/tools/gcc-trunk-dpd/bin/gcc -DDBG -O2 -std=gnu99 39034.c && ./a.out
laptop% /home/janis/tools/gcc-4.3.3-bid/bin/gcc -DDBG -O2 -std=gnu99 39034.c && ./a.out
line 29: runtime: d32 should be zero
line 42: runtime: d64 should be zero
line 56: runtime: d128 should be zero
Aborted (core dumped)
laptop% /home/janis/tools/gcc-4.3.3-dpd/bin/gcc -DDBG -O2 -std=gnu99 39034.c && ./a.out
line 29: runtime: d32 should be zero
line 42: runtime: d64 should be zero
line 56: runtime: d128 should be zero
Aborted (core dumped)
Comment 3 Ben Elliston 2009-02-02 02:35:29 UTC
Thanks for expanding the test case, Janis.  I think this is worthy of a test case in the regression testsuite, which I will submit now.
Comment 4 Ben Elliston 2009-02-02 23:03:30 UTC
Subject: Bug 39034

Author: bje
Date: Mon Feb  2 23:03:20 2009
New Revision: 143884

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143884
Log:
	PR c/39034
	* gcc.dg/dfp/pr39034.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/dfp/pr39034.c
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 5 Janis Johnson 2009-02-06 19:21:24 UTC
This was fixed in mainline by r141432, a fix for PR middle-end/36578.  That bug was a regression from 3.3 to 3.4.  I'm testing a backport of that fix to the 4.3 branch.
Comment 6 Janis Johnson 2010-01-13 23:18:15 UTC
This was fixed in the GCC 4.3 branch on 2009-02-25.
Comment 7 Vincent Lefèvre 2010-04-07 09:29:38 UTC
This bug is still open, though it appears to be fixed. Is there any reason?
Comment 8 Richard Biener 2010-04-07 09:32:23 UTC
Fixed.