svn commit: r226413 - head/lib/msun/src
David Schultz
das at FreeBSD.org
Sun Oct 16 05:37:02 UTC 2011
Author: das
Date: Sun Oct 16 05:37:01 2011
New Revision: 226413
URL: http://svn.freebsd.org/changeset/base/226413
Log:
Optimize the case of pure imaginary arguments. Calls like this are
common, e.g., in DFT implementations.
Discussed with: bde, kargl
Modified:
head/lib/msun/src/s_cexp.c
head/lib/msun/src/s_cexpf.c
Modified: head/lib/msun/src/s_cexp.c
==============================================================================
--- head/lib/msun/src/s_cexp.c Sun Oct 16 05:36:39 2011 (r226412)
+++ head/lib/msun/src/s_cexp.c Sun Oct 16 05:37:01 2011 (r226413)
@@ -56,8 +56,12 @@ cexp(double complex z)
/* cexp(x + I 0) = exp(x) + I 0 */
if ((hy | ly) == 0)
return (cpack(exp(x), y));
+ EXTRACT_WORDS(hx, lx, x);
+ /* cexp(0 + I y) = cos(y) + I sin(y) */
+ if (((hx & 0x7fffffff) | lx) == 0)
+ return (cpack(cos(y), sin(y)));
+
if (hy >= 0x7ff00000) {
- EXTRACT_WORDS(hx, lx, x);
if (lx != 0 || (hx & 0x7fffffff) != 0x7ff00000) {
/* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */
return (cpack(y - y, y - y));
@@ -70,7 +74,6 @@ cexp(double complex z)
}
}
- GET_HIGH_WORD(hx, x);
if (hx >= exp_ovfl && hx <= cexp_ovfl) {
/*
* x is between 709.7 and 1454.3, so we must scale to avoid
Modified: head/lib/msun/src/s_cexpf.c
==============================================================================
--- head/lib/msun/src/s_cexpf.c Sun Oct 16 05:36:39 2011 (r226412)
+++ head/lib/msun/src/s_cexpf.c Sun Oct 16 05:37:01 2011 (r226413)
@@ -57,6 +57,10 @@ cexpf(float complex z)
if (hy == 0)
return (cpackf(expf(x), y));
GET_FLOAT_WORD(hx, x);
+ /* cexp(0 + I y) = cos(y) + I sin(y) */
+ if ((hx & 0x7fffffff) == 0)
+ return (cpackf(cosf(y), sinf(y)));
+
if (hy >= 0x7f800000) {
if ((hx & 0x7fffffff) != 0x7f800000) {
/* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */
More information about the svn-src-head
mailing list