Re-style fdlibm to conform to jerry guidelines
* First re-style was done automatically by indent to minimize the
chance of errors during rewrite.
* Manual changes were applied to non-critical places only (comments
and spaces):
* Replaced all tabs with spaces.
* Fixed tab stops in formulae in function comments.
(Note: ASCII art for math formulae (especially for super- and
subscripts) is a terrible idea.)
* Unified the style of function comments.
* Moved some in-code comments to their right places, which indent
couldn't handle.
* Added spaces to formulae of in-code comments to make them more
readable.
* Added braces mandated by jerry style guidelines.
* Added parentheses to multiline #ifdef.
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Vendored
+72
-53
@@ -6,31 +6,32 @@
|
||||
*
|
||||
* Developed at SunSoft, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
/* acos(x)
|
||||
* Method :
|
||||
* acos(x) = pi/2 - asin(x)
|
||||
* acos(-x) = pi/2 + asin(x)
|
||||
*
|
||||
* Method:
|
||||
* acos(x) = pi/2 - asin(x)
|
||||
* acos(-x) = pi/2 + asin(x)
|
||||
* For |x|<=0.5
|
||||
* acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c)
|
||||
* acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c)
|
||||
* For x>0.5
|
||||
* acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2)))
|
||||
* = 2asin(sqrt((1-x)/2))
|
||||
* = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z)
|
||||
* = 2f + (2c + 2s*z*R(z))
|
||||
* acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2)))
|
||||
* = 2asin(sqrt((1-x)/2))
|
||||
* = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z)
|
||||
* = 2f + (2c + 2s*z*R(z))
|
||||
* where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term
|
||||
* for f so that f+c ~ sqrt(z).
|
||||
* For x<-0.5
|
||||
* acos(x) = pi - 2asin(sqrt((1-|x|)/2))
|
||||
* = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z)
|
||||
* acos(x) = pi - 2asin(sqrt((1-|x|)/2))
|
||||
* = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z)
|
||||
*
|
||||
* Special cases:
|
||||
* if x is NaN, return x itself;
|
||||
* if |x|>1, return NaN with invalid signal.
|
||||
* if x is NaN, return x itself;
|
||||
* if |x|>1, return NaN with invalid signal.
|
||||
*
|
||||
* Function needed: sqrt
|
||||
*/
|
||||
@@ -52,44 +53,62 @@
|
||||
#define qS3 -6.88283971605453293030e-01 /* 0xBFE6066C, 0x1B8D0159 */
|
||||
#define qS4 7.70381505559019352791e-02 /* 0x3FB3B8C5, 0xB12E9282 */
|
||||
|
||||
double acos(double x)
|
||||
double
|
||||
acos (double x)
|
||||
{
|
||||
double z,p,q,r,w,s,c,df;
|
||||
int hx,ix;
|
||||
hx = __HI(x);
|
||||
ix = hx&0x7fffffff;
|
||||
if(ix>=0x3ff00000) { /* |x| >= 1 */
|
||||
if(((ix-0x3ff00000)|__LO(x))==0) { /* |x|==1 */
|
||||
if(hx>0) return 0.0; /* acos(1) = 0 */
|
||||
else return pi+2.0*pio2_lo; /* acos(-1)= pi */
|
||||
}
|
||||
return (x-x)/(x-x); /* acos(|x|>1) is NaN */
|
||||
}
|
||||
if(ix<0x3fe00000) { /* |x| < 0.5 */
|
||||
if(ix<=0x3c600000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/
|
||||
z = x*x;
|
||||
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
|
||||
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
|
||||
r = p/q;
|
||||
return pio2_hi - (x - (pio2_lo-x*r));
|
||||
} else if (hx<0) { /* x < -0.5 */
|
||||
z = (one+x)*0.5;
|
||||
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
|
||||
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
|
||||
s = sqrt(z);
|
||||
r = p/q;
|
||||
w = r*s-pio2_lo;
|
||||
return pi - 2.0*(s+w);
|
||||
} else { /* x > 0.5 */
|
||||
z = (one-x)*0.5;
|
||||
s = sqrt(z);
|
||||
df = s;
|
||||
__LO(df) = 0;
|
||||
c = (z-df*df)/(s+df);
|
||||
p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
|
||||
q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
|
||||
r = p/q;
|
||||
w = r*s+c;
|
||||
return 2.0*(df+w);
|
||||
}
|
||||
}
|
||||
double z, p, q, r, w, s, c, df;
|
||||
int hx, ix;
|
||||
|
||||
hx = __HI (x);
|
||||
ix = hx & 0x7fffffff;
|
||||
if (ix >= 0x3ff00000) /* |x| >= 1 */
|
||||
{
|
||||
if (((ix - 0x3ff00000) | __LO (x)) == 0) /* |x| == 1 */
|
||||
{
|
||||
if (hx > 0) /* acos(1) = 0 */
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
else /* acos(-1) = pi */
|
||||
{
|
||||
return pi + 2.0 * pio2_lo;
|
||||
}
|
||||
}
|
||||
return (x - x) / (x - x); /* acos(|x|>1) is NaN */
|
||||
}
|
||||
if (ix < 0x3fe00000) /* |x| < 0.5 */
|
||||
{
|
||||
if (ix <= 0x3c600000) /* if |x| < 2**-57 */
|
||||
{
|
||||
return pio2_hi + pio2_lo;
|
||||
}
|
||||
z = x * x;
|
||||
p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
|
||||
q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
|
||||
r = p / q;
|
||||
return pio2_hi - (x - (pio2_lo - x * r));
|
||||
}
|
||||
else if (hx < 0) /* x < -0.5 */
|
||||
{
|
||||
z = (one + x) * 0.5;
|
||||
p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
|
||||
q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
|
||||
s = sqrt (z);
|
||||
r = p / q;
|
||||
w = r * s - pio2_lo;
|
||||
return pi - 2.0 * (s + w);
|
||||
}
|
||||
else /* x > 0.5 */
|
||||
{
|
||||
z = (one - x) * 0.5;
|
||||
s = sqrt (z);
|
||||
df = s;
|
||||
__LO (df) = 0;
|
||||
c = (z - df * df) / (s + df);
|
||||
p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
|
||||
q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
|
||||
r = p / q;
|
||||
w = r * s + c;
|
||||
return 2.0 * (df + w);
|
||||
}
|
||||
} /* acos */
|
||||
|
||||
Reference in New Issue
Block a user