casinh: Use symmetries also for default case. Signed-off-by: Martin Storsjö <martin@martin.st>
diff --git a/mingw-w64-crt/complex/casinh.def.h b/mingw-w64-crt/complex/casinh.def.h index cce2d86..40ff675 100644 --- a/mingw-w64-crt/complex/casinh.def.h +++ b/mingw-w64-crt/complex/casinh.def.h
@@ -47,6 +47,7 @@ { __complex__ __FLT_TYPE ret; __complex__ __FLT_TYPE x; + __FLT_TYPE arz, aiz; int r_class = fpclassify (__real__ z); int i_class = fpclassify (__imag__ z); @@ -89,32 +90,36 @@ /* casinh(z) = log(z + sqrt(z*z + 1)) */ - if (__FLT_ABI(fabs) (__real__ z) >= __FLT_CST(1.0)/__FLT_EPSILON - || __FLT_ABI(fabs) (__imag__ z) >= __FLT_CST(1.0)/__FLT_EPSILON) + /* Use symmetries to perform the calculation in the first quadrant. */ + arz = __FLT_ABI(fabs) (__real__ z); + aiz = __FLT_ABI(fabs) (__imag__ z); + + if (arz >= __FLT_CST(1.0)/__FLT_EPSILON + || aiz >= __FLT_CST(1.0)/__FLT_EPSILON) { /* For large z, z + sqrt(z*z + 1) is approximately 2*z. - Use that approximation to avoid overflow when squaring. - Additionally, use symmetries to perform the calculation in the first - quadrant. */ - __real__ x = __FLT_ABI(fabs) (__real__ z); - __imag__ x = __FLT_ABI(fabs) (__imag__ z); - x = __FLT_ABI(clog) (x); - __real__ x += M_LN2; + Use that approximation to avoid overflow when squaring. */ + __real__ x = arz; + __imag__ x = aiz; + ret = __FLT_ABI(clog) (x); + __real__ ret += M_LN2; + } + else + { + __real__ x = (arz - aiz) * (arz + aiz) + __FLT_CST(1.0); + __imag__ x = __FLT_CST(2.0) * arz * aiz; - /* adjust signs for input quadrant */ - __real__ ret = __FLT_ABI(copysign) (__real__ x, __real__ z); - __imag__ ret = __FLT_ABI(copysign) (__imag__ x, __imag__ z); + x = __FLT_ABI(csqrt) (x); - return ret; + __real__ x += arz; + __imag__ x += aiz; + + ret = __FLT_ABI(clog) (x); } - __real__ x = (__real__ z - __imag__ z) * (__real__ z + __imag__ z) + __FLT_CST(1.0); - __imag__ x = __FLT_CST(2.0) * __real__ z * __imag__ z; + /* adjust signs for input quadrant */ + __real__ ret = __FLT_ABI(copysign) (__real__ ret, __real__ z); + __imag__ ret = __FLT_ABI(copysign) (__imag__ ret, __imag__ z); - x = __FLT_ABI(csqrt) (x); - - __real__ x += __real__ z; - __imag__ x += __imag__ z; - - return __FLT_ABI(clog) (x); + return ret; }