Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Jun 2015 20:11:06 +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: r284423 - head/lib/msun/src
Message-ID:  <201506152011.t5FKB65U046410@svn.freebsd.org>

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

Log:
  Fix some exceptional cases where the sign of the result is unspecified
  but must still satisfy ccosh(conj(z)) == conj(ccosh(z)) and ccosh(-z) ==
  ccosh(z).
  
  In collaboration with:	bde

Modified:
  head/lib/msun/src/s_ccosh.c
  head/lib/msun/src/s_ccoshf.c

Modified: head/lib/msun/src/s_ccosh.c
==============================================================================
--- head/lib/msun/src/s_ccosh.c	Mon Jun 15 19:48:28 2015	(r284422)
+++ head/lib/msun/src/s_ccosh.c	Mon Jun 15 20:11:06 2015	(r284423)
@@ -32,6 +32,8 @@
  *
  * Exceptional values are noted in the comments within the source code.
  * These values and the return value were taken from n1124.pdf.
+ * The sign of the result for some exceptional values is unspecified but
+ * must satisfy both cosh(conj(z)) == conj(cosh(z)) and cosh(-z) == cosh(z).
  */
 
 #include <sys/cdefs.h>
@@ -63,7 +65,7 @@ ccosh(double complex z)
 	if (ix < 0x7ff00000 && iy < 0x7ff00000) {
 		if ((iy | ly) == 0)
 			return (CMPLX(cosh(x), x * y));
-		if (ix < 0x40360000)	/* small x: normal case */
+		if (ix < 0x40360000)	/* |x| < 22: normal case */
 			return (CMPLX(cosh(x) * cos(y), sinh(x) * sin(y)));
 
 		/* |x| >= 22, so cosh(x) ~= exp(|x|) */
@@ -83,28 +85,27 @@ ccosh(double complex z)
 	}
 
 	/*
-	 * cosh(+-0 +- I Inf) = dNaN + I sign(d(+-0, dNaN))0.
-	 * The sign of 0 in the result is unspecified.  Choice = normally
-	 * the same as dNaN.  Raise the invalid floating-point exception.
-	 *
-	 * cosh(+-0 +- I NaN) = d(NaN) + I sign(d(+-0, NaN))0.
-	 * The sign of 0 in the result is unspecified.  Choice = normally
-	 * the same as d(NaN).
+	 * cosh(+-0 +- I Inf) = dNaN + I (+-)(+-)0.
+	 * The sign of 0 in the result is unspecified.  Choice = product
+	 * of the signs of the argument.  Raise the invalid floating-point
+	 * exception.
+	 *
+	 * cosh(+-0 +- I NaN) = d(NaN) + I (+-)(+-)0.
+	 * The sign of 0 in the result is unspecified.  Choice = product
+	 * of the signs of the argument.
 	 */
-	if ((ix | lx) == 0 && iy >= 0x7ff00000)
-		return (CMPLX(y - y, copysign(0, x * (y - y))));
+	if ((ix | lx) == 0)		/* && iy >= 0x7ff00000 */
+		return (CMPLX(y - y, x * copysign(0, y)));
 
 	/*
 	 * cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0.
 	 *
-	 * cosh(NaN +- I 0)   = d(NaN) + I sign(d(NaN, +-0))0.
-	 * The sign of 0 in the result is unspecified.
+	 * cosh(NaN +- I 0)   = d(NaN) + I (+-)(+-)0.
+	 * The sign of 0 in the result is unspecified.  Choice = product
+	 * of the signs of the argument.
 	 */
-	if ((iy | ly) == 0 && ix >= 0x7ff00000) {
-		if (((hx & 0xfffff) | lx) == 0)
-			return (CMPLX(x * x, copysign(0, x) * y));
-		return (CMPLX(x * x, copysign(0, (x + x) * y)));
-	}
+	if ((iy | ly) == 0)		/* && ix >= 0x7ff00000 */
+		return (CMPLX(x * x, copysign(0, x) * y));
 
 	/*
 	 * cosh(x +- I Inf) = dNaN + I dNaN.
@@ -114,7 +115,7 @@ ccosh(double complex z)
 	 * Optionally raises the invalid floating-point exception for finite
 	 * nonzero x.  Choice = don't raise (except for signaling NaNs).
 	 */
-	if (ix < 0x7ff00000 && iy >= 0x7ff00000)
+	if (ix < 0x7ff00000)		/* && iy >= 0x7ff00000 */
 		return (CMPLX(y - y, x * (y - y)));
 
 	/*
@@ -126,10 +127,10 @@ ccosh(double complex z)
 	 *
 	 * cosh(+-Inf + I y)   = +Inf cos(y) +- I Inf sin(y)
 	 */
-	if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) {
+	if (ix == 0x7ff00000 && lx == 0) {
 		if (iy >= 0x7ff00000)
-			return (CMPLX(x * x, x * (y - y)));
-		return (CMPLX((x * x) * cos(y), x * sin(y)));
+			return (CMPLX(INFINITY, x * (y - y)));
+		return (CMPLX(INFINITY * cos(y), x * sin(y)));
 	}
 
 	/*

Modified: head/lib/msun/src/s_ccoshf.c
==============================================================================
--- head/lib/msun/src/s_ccoshf.c	Mon Jun 15 19:48:28 2015	(r284422)
+++ head/lib/msun/src/s_ccoshf.c	Mon Jun 15 20:11:06 2015	(r284423)
@@ -25,7 +25,7 @@
  */
 
 /*
- * Hyperbolic cosine of a complex argument.  See s_ccosh.c for details.
+ * Float version of ccosh().  See s_ccosh.c for details.
  */
 
 #include <sys/cdefs.h>
@@ -56,13 +56,13 @@ ccoshf(float complex z)
 	if (ix < 0x7f800000 && iy < 0x7f800000) {
 		if (iy == 0)
 			return (CMPLXF(coshf(x), x * y));
-		if (ix < 0x41100000)	/* small x: normal case */
+		if (ix < 0x41100000)	/* |x| < 9: normal case */
 			return (CMPLXF(coshf(x) * cosf(y), sinhf(x) * sinf(y)));
 
 		/* |x| >= 9, so cosh(x) ~= exp(|x|) */
 		if (ix < 0x42b17218) {
 			/* x < 88.7: expf(|x|) won't overflow */
-			h = expf(fabsf(x)) * 0.5f;
+			h = expf(fabsf(x)) * 0.5F;
 			return (CMPLXF(h * cosf(y), copysignf(h, x) * sinf(y)));
 		} else if (ix < 0x4340b1e7) {
 			/* x < 192.7: scale to avoid overflow */
@@ -75,22 +75,19 @@ ccoshf(float complex z)
 		}
 	}
 
-	if (ix == 0 && iy >= 0x7f800000)
-		return (CMPLXF(y - y, copysignf(0, x * (y - y))));
+	if (ix == 0)			/* && iy >= 0x7f800000 */
+		return (CMPLXF(y - y, x * copysignf(0, y)));
 
-	if (iy == 0 && ix >= 0x7f800000) {
-		if ((hx & 0x7fffff) == 0)
-			return (CMPLXF(x * x, copysignf(0, x) * y));
-		return (CMPLXF(x * x, copysignf(0, (x + x) * y)));
-	}
+	if (iy == 0)			/* && ix >= 0x7f800000 */
+		return (CMPLXF(x * x, copysignf(0, x) * y));
 
-	if (ix < 0x7f800000 && iy >= 0x7f800000)
+	if (ix < 0x7f800000)		/* && iy >= 0x7f800000 */
 		return (CMPLXF(y - y, x * (y - y)));
 
-	if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) {
+	if (ix == 0x7f800000) {
 		if (iy >= 0x7f800000)
-			return (CMPLXF(x * x, x * (y - y)));
-		return (CMPLXF((x * x) * cosf(y), x * sinf(y)));
+			return (CMPLXF(INFINITY, x * (y - y)));
+		return (CMPLXF(INFINITY * cosf(y), x * sinf(y)));
 	}
 
 	return (CMPLXF((x * x) * (y - y), (x + x) * (y - y)));



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