https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107967
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Ok, I can reproduce this, disabling all the +-*/ handlers fixes it. It isn libm.so.6 that matters for the failures, not the tests themselves. So far I've looked at the expm1 stuff, the failures are: Failure: expm1 (0x1.86ap+16): Exception "Overflow" not set Failure: expm1 (0x2.c5c4p+12): Exception "Overflow" not set Failure: expm1 (0xf.ffffffffffff8p+1020): Exception "Overflow" not set Failure: expm1 (0xf.fffffp+124): Exception "Overflow" not set Failure: expm1_downward (0x1.86ap+16): Exception "Overflow" not set Failure: Test: expm1_downward (0x1.86ap+16) Result: is: inf inf should be: 1.7976931348623157e+308 0x1.fffffffffffffp+1023 Failure: expm1_downward (0x2.c5c4p+12): Exception "Overflow" not set Failure: Test: expm1_downward (0x2.c5c4p+12) Result: is: inf inf should be: 1.7976931348623157e+308 0x1.fffffffffffffp+1023 ... Failure: expm1_upward (0x1.86ap+16): Exception "Overflow" not set Failure: expm1_upward (0x2.c5c4p+12): Exception "Overflow" not set Failure: expm1_upward (0xf.ffffffffffff8p+1020): Exception "Overflow" not set Failure: expm1_upward (0xf.fffffp+124): Exception "Overflow" not set For all the arguments >= 710.0 or so (non-inf/nan), the path in the source is: static const double huge = 1.0e+300, tiny = 1.0e-300, o_threshold = 7.09782712893383973096e+02; /* 0x40862E42, 0xFEFA39EF */ ... if (x > o_threshold) { __set_errno (ERANGE); return huge * huge; /* overflow */ } and the file is compiled with -frounding-math. So the reduced testcase for at least part of this PR is: double foo (void) { const double huge = 1.0e+300; return huge * huge; } GCC 12 would compile this into return __builtin_inf (); only with -fno-trapping-math, not without it nor with -frounding-math. Now, GCC trunk compiles this into return __builtin_inf (); with all of -fno-trapping-math, default or -frounding-math. For the default case, the problem is the same as in PR107608. But with -frounding-math, we have an extra problem with the value, which actually shouldn't be +INF but DBL_MAX. E.g. #include <fenv.h> #include <stdio.h> int main () { volatile double huge = 1.0e+308; volatile double inf = __builtin_inf (); fesetround (FE_DOWNWARD); volatile double r1 = huge + huge; volatile double r2 = huge * huge; volatile double r3 = huge + inf; volatile double r4 = r2 + huge; volatile double r5 = inf - 1.0; volatile double r6 = inf - huge; fesetround (FE_TONEAREST); printf ("%e %e %e %e %e %e\n", r1, r2, r3, r4, r5, r6); } prints 1.797693e+308 1.797693e+308 inf 1.797693e+308 inf inf, so the behavior seems to be if either operand is already inf, then the result should be inf even when rounding to -inf (except special cases when it is nan), but if neither operand is inf, when rounding downward it shouldn't be +inf but max representable (or when rounding upward not -inf but min representable). So I assume we should tweak frange_arithmetics for this behavior when flag_rounding_math.