[Bug c/95300] New: Decimal floating-point constants suffer double rounding

tydeman at tybor dot com gcc-bugzilla@gcc.gnu.org
Sun May 24 05:32:46 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95300

            Bug ID: 95300
           Summary: Decimal floating-point constants suffer double
                    rounding
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tydeman at tybor dot com
  Target Milestone: ---

The following code prints failures for 35 and 36 digit numbers.

/*
 * Decimal floating-point constants suffer double rounding => get wrong value.
 * It appears that first the constant is convert to 34 digit _Decimal128 (1st
rounding)
 * and then converted to _Decimal32 (2nd rounding).
 */

#define __STDC_WANT_IEC_60559_DFP_EXT__ 1 /* Tell implementation that we want
Decimal FP */
#define __STDC_WANT_DEC_FP__    /* Tell implementation that we want Decimal FP
*/

#include <stdio.h>

int main(void){
  _Decimal32 d7, d33, d34, d35, d36;
  d7  = 1234567.DF;
  d33 = 1234567.49999999999999999999999999DF;
  d34 = 1234567.499999999999999999999999999DF;
  /*    1234567 89-123456789-123456789-123456789 */
  d35 = 1234567.4999999999999999999999999999DF;
  d36 = 1234567.49999999999999999999999999999DF;
  if( d7 != d33 ) (void)printf("d33 bad\n");
  if( d7 != d34 ) (void)printf("d34 bad\n");
  if( d7 != d35 ) (void)printf("d35 bad\n");
  if( d7 != d36 ) (void)printf("d36 bad\n");
  return 0;
}


More information about the Gcc-bugs mailing list