Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Jun 2015 20:40:45 +0000 (UTC)
From:      Tijl Coosemans <tijl@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r284427 - head/lib/msun/src
Message-ID:  <201506152040.t5FKejiB059636@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tijl
Date: Mon Jun 15 20:40:44 2015
New Revision: 284427
URL: https://svnweb.freebsd.org/changeset/base/284427

Log:
  - Change comments to be more consistent with s_ccosh.c and s_csinh.c.
  - Fix a case where NaNs were not mixed correctly and signalling NaNs were
    not converted to quiet NaNs.
  - Eliminate two negations from ctan(z).
  
  In collaboration with:	bde

Modified:
  head/lib/msun/src/s_ctanh.c
  head/lib/msun/src/s_ctanhf.c

Modified: head/lib/msun/src/s_ctanh.c
==============================================================================
--- head/lib/msun/src/s_ctanh.c	Mon Jun 15 20:16:53 2015	(r284426)
+++ head/lib/msun/src/s_ctanh.c	Mon Jun 15 20:40:44 2015	(r284427)
@@ -25,7 +25,7 @@
  */
 
 /*
- * Hyperbolic tangent of a complex argument z = x + i y.
+ * Hyperbolic tangent of a complex argument z = x + I y.
  *
  * The algorithm is from:
  *
@@ -44,15 +44,15 @@
  *
  *   tanh(z) = sinh(z) / cosh(z)
  *
- *             sinh(x) cos(y) + i cosh(x) sin(y)
+ *             sinh(x) cos(y) + I cosh(x) sin(y)
  *           = ---------------------------------
- *             cosh(x) cos(y) + i sinh(x) sin(y)
+ *             cosh(x) cos(y) + I sinh(x) sin(y)
  *
- *             cosh(x) sinh(x) / cos^2(y) + i tan(y)
+ *             cosh(x) sinh(x) / cos^2(y) + I tan(y)
  *           = -------------------------------------
  *                    1 + sinh^2(x) / cos^2(y)
  *
- *             beta rho s + i t
+ *             beta rho s + I t
  *           = ----------------
  *               1 + beta s^2
  *
@@ -85,16 +85,16 @@ ctanh(double complex z)
 	ix = hx & 0x7fffffff;
 
 	/*
-	 * ctanh(NaN + i 0) = NaN + i 0
+	 * ctanh(NaN +- I 0) = d(NaN) +- I 0
 	 *
-	 * ctanh(NaN + i y) = NaN + i NaN		for y != 0
+	 * ctanh(NaN + I y) = d(NaN,y) + I d(NaN,y)	for y != 0
 	 *
 	 * The imaginary part has the sign of x*sin(2*y), but there's no
 	 * special effort to get this right.
 	 *
-	 * ctanh(+-Inf +- i Inf) = +-1 +- 0
+	 * ctanh(+-Inf +- I Inf) = +-1 +- I 0
 	 *
-	 * ctanh(+-Inf + i y) = +-1 + 0 sin(2y)		for y finite
+	 * ctanh(+-Inf + I y) = +-1 + I 0 sin(2y)	for y finite
 	 *
 	 * The imaginary part of the sign is unspecified.  This special
 	 * case is only needed to avoid a spurious invalid exception when
@@ -102,24 +102,25 @@ ctanh(double complex z)
 	 */
 	if (ix >= 0x7ff00000) {
 		if ((ix & 0xfffff) | lx)	/* x is NaN */
-			return (CMPLX(x, (y == 0 ? y : x * y)));
+			return (CMPLX((x + 0) * (y + 0),
+			    y == 0 ? y : (x + 0) * (y + 0)));
 		SET_HIGH_WORD(x, hx - 0x40000000);	/* x = copysign(1, x) */
 		return (CMPLX(x, copysign(0, isinf(y) ? y : sin(y) * cos(y))));
 	}
 
 	/*
-	 * ctanh(x + i NAN) = NaN + i NaN
-	 * ctanh(x +- i Inf) = NaN + i NaN
+	 * ctanh(x + I NaN) = d(NaN) + I d(NaN)
+	 * ctanh(x +- I Inf) = dNaN + I dNaN
 	 */
 	if (!isfinite(y))
 		return (CMPLX(y - y, y - y));
 
 	/*
-	 * ctanh(+-huge + i +-y) ~= +-1 +- i 2sin(2y)/exp(2x), using the
+	 * ctanh(+-huge +- I y) ~= +-1 +- I 2sin(2y)/exp(2x), using the
 	 * approximation sinh^2(huge) ~= exp(2*huge) / 4.
 	 * We use a modified formula to avoid spurious overflow.
 	 */
-	if (ix >= 0x40360000) {	/* x >= 22 */
+	if (ix >= 0x40360000) {	/* |x| >= 22 */
 		double exp_mx = exp(-fabs(x));
 		return (CMPLX(copysign(1, x),
 		    4 * sin(y) * cos(y) * exp_mx * exp_mx));
@@ -138,7 +139,7 @@ double complex
 ctan(double complex z)
 {
 
-	/* ctan(z) = -I * ctanh(I * z) */
-	z = ctanh(CMPLX(-cimag(z), creal(z)));
-	return (CMPLX(cimag(z), -creal(z)));
+	/* ctan(z) = -I * ctanh(I * z) = I * conj(ctanh(I * conj(z))) */
+	z = ctanh(CMPLX(cimag(z), creal(z)));
+	return (CMPLX(cimag(z), creal(z)));
 }

Modified: head/lib/msun/src/s_ctanhf.c
==============================================================================
--- head/lib/msun/src/s_ctanhf.c	Mon Jun 15 20:16:53 2015	(r284426)
+++ head/lib/msun/src/s_ctanhf.c	Mon Jun 15 20:40:44 2015	(r284427)
@@ -60,7 +60,7 @@ ctanhf(float complex z)
 	if (!isfinite(y))
 		return (CMPLXF(y - y, y - y));
 
-	if (ix >= 0x41300000) {	/* x >= 11 */
+	if (ix >= 0x41300000) {	/* |x| >= 11 */
 		float exp_mx = expf(-fabsf(x));
 		return (CMPLXF(copysignf(1, x),
 		    4 * sinf(y) * cosf(y) * exp_mx * exp_mx));
@@ -78,7 +78,7 @@ float complex
 ctanf(float complex z)
 {
 
-	z = ctanhf(CMPLXF(-cimagf(z), crealf(z)));
-	return (CMPLXF(cimagf(z), -crealf(z)));
+	z = ctanhf(CMPLXF(cimagf(z), crealf(z)));
+	return (CMPLXF(cimagf(z), crealf(z)));
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201506152040.t5FKejiB059636>