Replace calls to sin(x) and cos(x) with a single call to sincos().
Replace calls to sinf(x) and cosf(x) with a single call to sincosf(). Submitted by: Steve Kargl <sgk@troutmask.apl.washington.edu> Reviewed by: bde Approved by: grog MFC after: 3 days
This commit is contained in:
parent
a8ffff1898
commit
cd5c424771
@ -93,8 +93,7 @@ __ieee754_j0(double x)
|
|||||||
if(ix>=0x7ff00000) return one/(x*x);
|
if(ix>=0x7ff00000) return one/(x*x);
|
||||||
x = fabs(x);
|
x = fabs(x);
|
||||||
if(ix >= 0x40000000) { /* |x| >= 2.0 */
|
if(ix >= 0x40000000) { /* |x| >= 2.0 */
|
||||||
s = sin(x);
|
sincos(x, &s, &c);
|
||||||
c = cos(x);
|
|
||||||
ss = s-c;
|
ss = s-c;
|
||||||
cc = s+c;
|
cc = s+c;
|
||||||
if(ix<0x7fe00000) { /* Make sure x+x does not overflow. */
|
if(ix<0x7fe00000) { /* Make sure x+x does not overflow. */
|
||||||
@ -173,8 +172,7 @@ __ieee754_y0(double x)
|
|||||||
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
|
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
|
||||||
* to compute the worse one.
|
* to compute the worse one.
|
||||||
*/
|
*/
|
||||||
s = sin(x);
|
sincos(x, &s, &c);
|
||||||
c = cos(x);
|
|
||||||
ss = s-c;
|
ss = s-c;
|
||||||
cc = s+c;
|
cc = s+c;
|
||||||
/*
|
/*
|
||||||
|
@ -55,8 +55,7 @@ __ieee754_j0f(float x)
|
|||||||
if(ix>=0x7f800000) return one/(x*x);
|
if(ix>=0x7f800000) return one/(x*x);
|
||||||
x = fabsf(x);
|
x = fabsf(x);
|
||||||
if(ix >= 0x40000000) { /* |x| >= 2.0 */
|
if(ix >= 0x40000000) { /* |x| >= 2.0 */
|
||||||
s = sinf(x);
|
sincosf(x, &s, &c);
|
||||||
c = cosf(x);
|
|
||||||
ss = s-c;
|
ss = s-c;
|
||||||
cc = s+c;
|
cc = s+c;
|
||||||
if(ix<0x7f000000) { /* Make sure x+x does not overflow. */
|
if(ix<0x7f000000) { /* Make sure x+x does not overflow. */
|
||||||
@ -128,8 +127,7 @@ __ieee754_y0f(float x)
|
|||||||
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
|
* sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
|
||||||
* to compute the worse one.
|
* to compute the worse one.
|
||||||
*/
|
*/
|
||||||
s = sinf(x);
|
sincosf(x, &s, &c);
|
||||||
c = cosf(x);
|
|
||||||
ss = s-c;
|
ss = s-c;
|
||||||
cc = s+c;
|
cc = s+c;
|
||||||
/*
|
/*
|
||||||
|
@ -94,8 +94,7 @@ __ieee754_j1(double x)
|
|||||||
if(ix>=0x7ff00000) return one/x;
|
if(ix>=0x7ff00000) return one/x;
|
||||||
y = fabs(x);
|
y = fabs(x);
|
||||||
if(ix >= 0x40000000) { /* |x| >= 2.0 */
|
if(ix >= 0x40000000) { /* |x| >= 2.0 */
|
||||||
s = sin(y);
|
sincos(y, &s, &c);
|
||||||
c = cos(y);
|
|
||||||
ss = -s-c;
|
ss = -s-c;
|
||||||
cc = s-c;
|
cc = s-c;
|
||||||
if(ix<0x7fe00000) { /* make sure y+y not overflow */
|
if(ix<0x7fe00000) { /* make sure y+y not overflow */
|
||||||
@ -159,8 +158,7 @@ __ieee754_y1(double x)
|
|||||||
/* y1(x<0) = NaN and raise invalid exception. */
|
/* y1(x<0) = NaN and raise invalid exception. */
|
||||||
if(hx<0) return vzero/vzero;
|
if(hx<0) return vzero/vzero;
|
||||||
if(ix >= 0x40000000) { /* |x| >= 2.0 */
|
if(ix >= 0x40000000) { /* |x| >= 2.0 */
|
||||||
s = sin(x);
|
sincos(x, &s, &c);
|
||||||
c = cos(x);
|
|
||||||
ss = -s-c;
|
ss = -s-c;
|
||||||
cc = s-c;
|
cc = s-c;
|
||||||
if(ix<0x7fe00000) { /* make sure x+x not overflow */
|
if(ix<0x7fe00000) { /* make sure x+x not overflow */
|
||||||
|
@ -56,8 +56,7 @@ __ieee754_j1f(float x)
|
|||||||
if(ix>=0x7f800000) return one/x;
|
if(ix>=0x7f800000) return one/x;
|
||||||
y = fabsf(x);
|
y = fabsf(x);
|
||||||
if(ix >= 0x40000000) { /* |x| >= 2.0 */
|
if(ix >= 0x40000000) { /* |x| >= 2.0 */
|
||||||
s = sinf(y);
|
sincosf(y, &s, &c);
|
||||||
c = cosf(y);
|
|
||||||
ss = -s-c;
|
ss = -s-c;
|
||||||
cc = s-c;
|
cc = s-c;
|
||||||
if(ix<0x7f000000) { /* make sure y+y not overflow */
|
if(ix<0x7f000000) { /* make sure y+y not overflow */
|
||||||
@ -114,8 +113,7 @@ __ieee754_y1f(float x)
|
|||||||
if(ix==0) return -one/vzero;
|
if(ix==0) return -one/vzero;
|
||||||
if(hx<0) return vzero/vzero;
|
if(hx<0) return vzero/vzero;
|
||||||
if(ix >= 0x40000000) { /* |x| >= 2.0 */
|
if(ix >= 0x40000000) { /* |x| >= 2.0 */
|
||||||
s = sinf(x);
|
sincosf(x, &s, &c);
|
||||||
c = cosf(x);
|
|
||||||
ss = -s-c;
|
ss = -s-c;
|
||||||
cc = s-c;
|
cc = s-c;
|
||||||
if(ix<0x7f000000) { /* make sure x+x not overflow */
|
if(ix<0x7f000000) { /* make sure x+x not overflow */
|
||||||
|
@ -54,7 +54,7 @@ double
|
|||||||
__ieee754_jn(int n, double x)
|
__ieee754_jn(int n, double x)
|
||||||
{
|
{
|
||||||
int32_t i,hx,ix,lx, sgn;
|
int32_t i,hx,ix,lx, sgn;
|
||||||
double a, b, temp, di;
|
double a, b, c, s, temp, di;
|
||||||
double z, w;
|
double z, w;
|
||||||
|
|
||||||
/* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
|
/* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
|
||||||
@ -91,11 +91,12 @@ __ieee754_jn(int n, double x)
|
|||||||
* 2 -s+c -c-s
|
* 2 -s+c -c-s
|
||||||
* 3 s+c c-s
|
* 3 s+c c-s
|
||||||
*/
|
*/
|
||||||
|
sincos(x, &s, &c);
|
||||||
switch(n&3) {
|
switch(n&3) {
|
||||||
case 0: temp = cos(x)+sin(x); break;
|
case 0: temp = c+s; break;
|
||||||
case 1: temp = -cos(x)+sin(x); break;
|
case 1: temp = -c+s; break;
|
||||||
case 2: temp = -cos(x)-sin(x); break;
|
case 2: temp = -c-s; break;
|
||||||
case 3: temp = cos(x)-sin(x); break;
|
case 3: temp = c-s; break;
|
||||||
}
|
}
|
||||||
b = invsqrtpi*temp/sqrt(x);
|
b = invsqrtpi*temp/sqrt(x);
|
||||||
} else {
|
} else {
|
||||||
@ -216,7 +217,7 @@ __ieee754_yn(int n, double x)
|
|||||||
{
|
{
|
||||||
int32_t i,hx,ix,lx;
|
int32_t i,hx,ix,lx;
|
||||||
int32_t sign;
|
int32_t sign;
|
||||||
double a, b, temp;
|
double a, b, c, s, temp;
|
||||||
|
|
||||||
EXTRACT_WORDS(hx,lx,x);
|
EXTRACT_WORDS(hx,lx,x);
|
||||||
ix = 0x7fffffff&hx;
|
ix = 0x7fffffff&hx;
|
||||||
@ -248,11 +249,12 @@ __ieee754_yn(int n, double x)
|
|||||||
* 2 -s+c -c-s
|
* 2 -s+c -c-s
|
||||||
* 3 s+c c-s
|
* 3 s+c c-s
|
||||||
*/
|
*/
|
||||||
|
sincos(x, &s, &c);
|
||||||
switch(n&3) {
|
switch(n&3) {
|
||||||
case 0: temp = sin(x)-cos(x); break;
|
case 0: temp = s-c; break;
|
||||||
case 1: temp = -sin(x)-cos(x); break;
|
case 1: temp = -s-c; break;
|
||||||
case 2: temp = -sin(x)+cos(x); break;
|
case 2: temp = -s+c; break;
|
||||||
case 3: temp = sin(x)+cos(x); break;
|
case 3: temp = s+c; break;
|
||||||
}
|
}
|
||||||
b = invsqrtpi*temp/sqrt(x);
|
b = invsqrtpi*temp/sqrt(x);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user