Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mützel <markus.muetzel@gmx.de>2022-08-04 13:55:17 +0300
committerCorinna Vinschen <corinna@vinschen.de>2022-08-04 13:55:17 +0300
commitd939b16adc9d05d225970de1281684fa097565eb (patch)
treeb064bd5191cfd9538fd5dca7a9ec493ef1e57f19
parent70c7e8c1baaf5aa3a1e7327cd21463f4fa5b336b (diff)
casinh: Use approximation for large input.
Signed-off-by: Martin Storsjö <martin@martin.st> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
-rw-r--r--winsup/cygwin/math/casinh.def.h21
1 files changed, 21 insertions, 0 deletions
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;