From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 398633857007; Thu, 4 Aug 2022 10:56:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 398633857007 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] casinh: Use approximation for large input. X-Act-Checkin: newlib-cygwin X-Git-Author: =?utf-8?q?Markus_M=C3=BCtzel?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 70c7e8c1baaf5aa3a1e7327cd21463f4fa5b336b X-Git-Newrev: d939b16adc9d05d225970de1281684fa097565eb Message-Id: <20220804105642.398633857007@sourceware.org> Date: Thu, 4 Aug 2022 10:56:42 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Aug 2022 10:56:42 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dd939b16adc9= d05d225970de1281684fa097565eb commit d939b16adc9d05d225970de1281684fa097565eb Author: Markus M=C3=BCtzel Date: Thu Aug 4 12:55:17 2022 +0200 casinh: Use approximation for large input. =20 Signed-off-by: Martin Storsj=C3=B6 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/math/casinh.def.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/winsup/cygwin/math/casinh.def.h b/winsup/cygwin/math/casinh.de= f.h index 0cf46980d..3d04d483b 100644 --- a/winsup/cygwin/math/casinh.def.h +++ b/winsup/cygwin/math/casinh.def.h @@ -87,6 +87,27 @@ __FLT_ABI(casinh) (__FLT_TYPE __complex__ z) if (r_class =3D=3D FP_ZERO && i_class =3D=3D FP_ZERO) return z; =20 + /* casinh(z) =3D log(z + sqrt(z*z + 1)) */ + + if (__FLT_ABI(fabs) (__real__ z) >=3D __FLT_CST(1.0)/__FLT_EPSILON + || __FLT_ABI(fabs) (__imag__ z) >=3D __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 =3D __FLT_ABI(fabs) (__real__ z); + __imag__ x =3D __FLT_ABI(fabs) (__imag__ z); + x =3D __FLT_ABI(clog) (x); + __real__ x +=3D M_LN2; + + /* adjust signs for input quadrant */ + __real__ ret =3D __FLT_ABI(copysign) (__real__ x, __real__ z); + __imag__ ret =3D __FLT_ABI(copysign) (__imag__ x, __imag__ z); + + return ret; + } + __real__ x =3D (__real__ z - __imag__ z) * (__real__ z + __imag__ z) + _= _FLT_CST(1.0); __imag__ x =3D __FLT_CST(2.0) * __real__ z * __imag__ z;