https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121729
Bug ID: 121729
Summary: DFP FP exception flags not raised as expected
Product: gcc
Version: 14.3.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 raises FE_INVALID and FE_INEXACT, but not the other three.
#define __STDC_WANT_DEC_FP__ 1
#define __STDC_WANT_IEC_60559_DFP_EXT__ 1
#include <assert.h>
#include <stdio.h>
#include <limits.h>
#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <math.h>
static _Decimal32 fpdiv( const _Decimal32 x, const _Decimal32 y ) { return x /
y; }
int main(void){
if(1){
_Decimal32 dfp26;
int flags = 0;
feclearexcept(FE_ALL_EXCEPT);
dfp26 = fpdiv( 1e0DF, 3e0DF ); /* inexact */
assert( 0.3333333DF == dfp26 );
flags |= fetestexcept(FE_ALL_EXCEPT);
dfp26 = fpdiv( DEC32_MIN, DEC32_MAX );/* underflow */
assert( 0e0DF == dfp26 );
flags |= fetestexcept(FE_ALL_EXCEPT);
dfp26 = fpdiv( DEC32_MAX, DEC32_MIN );/* overflow */
assert( DEC_INFINITY == dfp26 );
flags |= fetestexcept(FE_ALL_EXCEPT);
dfp26 = fpdiv( 1e0DF, 0e0DF ); /* div-by-0 */
assert( DEC_INFINITY == dfp26 );
flags |= fetestexcept(FE_ALL_EXCEPT);
dfp26 = fpdiv( 0e0DF, 0e0DF ); /* invalid */
assert( isnan(dfp26) );
flags |= fetestexcept(FE_ALL_EXCEPT);
(void)printf("%#x=flags\n", flags);
(void)printf("%#x=FE_INEXACT\n", FE_INEXACT );
(void)printf("%#x=FE_UNDERFLOW\n", FE_UNDERFLOW );
(void)printf("%#x=FE_OVERFLOW\n", FE_OVERFLOW );
(void)printf("%#x=FE_DIVBYZERO\n", FE_DIVBYZERO );
(void)printf("%#x=FE_INVALID\n", FE_INVALID );
(void)fflush(NULL);
assert( 0 != flags );
assert( FE_INEXACT & flags );
assert( FE_INVALID & flags );
assert( FE_UNDERFLOW & flags ); /* fails here */
assert( FE_OVERFLOW & flags );
assert( FE_DIVBYZERO & flags );
}
return 0;
}
Here are the flags being passed to gcc:
export CFLAGS="-H -std=gnu23 -O0 -march=native -mhard-float -mfpmath=387
-mieee-fp \
-enable-decimal-float=yes \
-fexcess-precision=standard \
-ffloat-store \
-ffp-contract=off \
-fmath-errno \
-fno-associative-math \
-fno-builtin \
-fno-cx-limited-range \
-fno-fast-math \
-fno-finite-math-only \
-fno-reciprocal-math \
-fno-unsafe-math-optimizations \
-frounding-math \
-fsignaling-nans \
-fsigned-zeros \
-ftrapping-math \
${INCS} \
-I/usr/include/dfp"
This is being run on Fedora Linux 41 on Intel Core i5 vPRO.