public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] casinh: Use approximation for large input. Date: Thu, 4 Aug 2022 10:56:42 +0000 (GMT) [thread overview] Message-ID: <20220804105642.398633857007@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=d939b16adc9d05d225970de1281684fa097565eb commit d939b16adc9d05d225970de1281684fa097565eb Author: Markus Mützel <markus.muetzel@gmx.de> Date: Thu Aug 4 12:55:17 2022 +0200 casinh: Use approximation for large input. Signed-off-by: Martin Storsjö <martin@martin.st> Signed-off-by: Corinna Vinschen <corinna@vinschen.de> 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.def.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 == FP_ZERO && i_class == FP_ZERO) return z; + /* 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) + { + /* 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; + + /* adjust signs for input quadrant */ + __real__ ret = __FLT_ABI(copysign) (__real__ x, __real__ z); + __imag__ ret = __FLT_ABI(copysign) (__imag__ x, __imag__ z); + + return ret; + } + __real__ x = (__real__ z - __imag__ z) * (__real__ z + __imag__ z) + __FLT_CST(1.0); __imag__ x = __FLT_CST(2.0) * __real__ z * __imag__ z;
reply other threads:[~2022-08-04 10:56 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220804105642.398633857007@sourceware.org \ --to=corinna@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).