When exp(real(z)) overflows, cexp() currently falls through to the generic infinite-result path. That path derives both components from the sincos() results, which is appropriate for non-zero imaginary arguments but not for the real-axis case.
For z = x + 0i with x > MAXLOG, the mathematically expected result is Inf + 0i. Handle i_class == FP_ZERO before the generic overflow case so the function returns the overflowing real part unchanged and preserves the signed zero imaginary part from the input. Add a regression test covering cexp(MAXLOG + 1 + 0i) to lock in the Inf + 0i result. Signed-off-by: Oleg Tolmatcev <[email protected]> --- mingw-w64-crt/complex/cexp.def.h | 5 +++++ mingw-w64-crt/testcases/complex/cexp.c | 1 + 2 files changed, 6 insertions(+) diff --git a/mingw-w64-crt/complex/cexp.def.h b/mingw-w64-crt/complex/cexp.def.h index c0c97b70..198b6e1c 100644 --- a/mingw-w64-crt/complex/cexp.def.h +++ b/mingw-w64-crt/complex/cexp.def.h @@ -102,6 +102,11 @@ __FLT_ABI(cexp) (__FLT_TYPE __complex__ z) __real__ ret = exp_val * c_x; __imag__ ret = exp_val * s_x; } + else if (i_class == FP_ZERO) + { + __real__ ret = exp_val; + __imag__ ret = __imag__ z; + } else { __real__ ret = __FLT_ABI(copysign) (exp_val, c_x); diff --git a/mingw-w64-crt/testcases/complex/cexp.c b/mingw-w64-crt/testcases/complex/cexp.c index 6cd37317..d924d125 100644 --- a/mingw-w64-crt/testcases/complex/cexp.c +++ b/mingw-w64-crt/testcases/complex/cexp.c @@ -88,6 +88,7 @@ int __FLT_ABI(test_function_cexp) () DEFINE_TEST ( __FLT_NAN, __FLT_CST(42.42), __FLT_NAN, __FLT_NAN, 0, 0) DEFINE_TEST ( __FLT_NAN, INFINITY, __FLT_NAN, __FLT_NAN, 0, 0) DEFINE_TEST ( __FLT_NAN, __FLT_NAN, __FLT_NAN, __FLT_NAN, 0, 0) + DEFINE_TEST (__FLT_MAXLOG + __FLT_CST(1.0), __FLT_CST(0.0), INFINITY, __FLT_CST(0.0), 0, 0) TESTS_END -- 2.55.0.windows.1 _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
