Multiplication by a decimal floating-point (DFP) value of one appears to be
"optimized" away, thereby producing the wrong value. In DFP, the value one has
many representations. Only one of them (1.DF) results in no change to values
for multiplication; the others change the quantum exponent.
/* DFP TR 24732 == WG14 / N1312 */
#define __STDC_WANT_DEC_FP__ /* Tell implementation that we want Decimal FP */
#include <stdio.h> /* printf() */
#include <string.h> /* memcmp() */
int main(void){
_Decimal32 f1 = 1.0DF;
_Decimal32 f2 = 2.0DF;
_Decimal32 f3;
f3 = f2 * f1; /* should change quantum exponent */
if( 0 == memcmp( &f3, &f2, sizeof(f3) ) ){
(void)printf("Fail 1\n");
}
f3 = f2 * 1.0DF; /* should change quantum exponent */
if( 0 == memcmp( &f3, &f2, sizeof(f3) ) ){
(void)printf("Fail 2\n");
}
return 0;
}
gets: Fail 2
--
Summary: x * 1.0DF gets wrong value
Product: gcc
Version: 4.3.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tydeman at tybor dot com
GCC build triplet: 4.3.2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39902