amath  1.6.2
Simple command line calculator
acos.c File Reference
#include "prim.h"
#include "math.h"
Include dependency graph for acos.c:

Go to the source code of this file.

Functions

double acos (double x)
 Inverse trigonometric cosine function. More...
 

Variables

static const double one = 1.00000000000000000000e+00
 
static const double pi = 3.14159265358979311600e+00
 
static const double pio2_hi = 1.57079632679489655800e+00
 
static const double pio2_lo = 6.12323399573676603587e-17
 
static const double pS0 = 1.66666666666666657415e-01
 
static const double pS1 = -3.25565818622400915405e-01
 
static const double pS2 = 2.01212532134862925881e-01
 
static const double pS3 = -4.00555345006794114027e-02
 
static const double pS4 = 7.91534994289814532176e-04
 
static const double pS5 = 3.47933107596021167570e-05
 
static const double qS1 = -2.40339491173441421878e+00
 
static const double qS2 = 2.02094576023350569471e+00
 
static const double qS3 = -6.88283971605453293030e-01
 
static const double qS4 = 7.70381505559019352791e-02
 

Function Documentation

double acos ( double  x)

Inverse trigonometric cosine function.

Version
1.3
Date
95/01/18
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)
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))
    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)
Special cases:
 if x is NaN, return x itself;
 if |x|>1, return NaN with invalid signal.
Function needed: sqrt

Definition at line 96 of file acos.c.

References one, pi, pio2_hi, pio2_lo, pS0, pS1, pS2, pS3, pS4, pS5, qS1, qS2, qS3, qS4, and sqrt().

Referenced by RealNumber::ArcCosine(), and RealNumber::ArcSecant().

97 {
98  double z,p,q,r,w,s,c,df;
99  sword hx,ix;
100  GET_HIGH_WORD(hx,x);
101  ix = hx&0x7fffffff;
102  if(ix>=0x3ff00000) { /* |x| >= 1 */
103  sword lx;
104  GET_LOW_WORD(lx,x);
105  if(((ix-0x3ff00000)|lx)==0) { /* |x|==1 */
106  if(hx>0) return 0.0; /* acos(1) = 0 */
107  else return pi+2.0*pio2_lo; /* acos(-1)= pi */
108  }
109  return (x-x)/(x-x); /* acos(|x|>1) is NaN */
110  }
111  if(ix<0x3fe00000) { /* |x| < 0.5 */
112  if(ix<=0x3c600000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/
113  z = x*x;
114  p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
115  q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
116  r = p/q;
117  return pio2_hi - (x - (pio2_lo-x*r));
118  } else if (hx<0) { /* x < -0.5 */
119  z = (one+x)*0.5;
120  p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
121  q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
122  s = sqrt(z);
123  r = p/q;
124  w = r*s-pio2_lo;
125  return pi - 2.0*(s+w);
126  } else { /* x > 0.5 */
127  z = (one-x)*0.5;
128  s = sqrt(z);
129  df = s;
130  SET_LOW_WORD(df,0);
131  c = (z-df*df)/(s+df);
132  p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
133  q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
134  r = p/q;
135  w = r*s+c;
136  return 2.0*(df+w);
137  }
138 }
static const double pi
Definition: acos.c:49
static const double pS2
Definition: acos.c:54
#define GET_HIGH_WORD(i, d)
Get the more significant 32 bit int from a double.
Definition: prim.h:165
static const double pS4
Definition: acos.c:56
static const double pio2_hi
Definition: acos.c:50
#define GET_LOW_WORD(i, d)
Get the less significant 32 bit int from a double.
Definition: prim.h:176
signed int sword
32 bit signed integer.
Definition: prim.h:107
static const double pS5
Definition: acos.c:57
double sqrt(double x)
Square root function.
Definition: sqrt.c:127
static const double pS0
Definition: acos.c:52
static const double one
Definition: acos.c:48
static const double qS4
Definition: acos.c:61
#define SET_LOW_WORD(d, v)
Set the less significant 32 bits of a double from an int.
Definition: prim.h:211
static const double qS3
Definition: acos.c:60
static const double qS1
Definition: acos.c:58
static const double pS3
Definition: acos.c:55
static const double qS2
Definition: acos.c:59
static const double pio2_lo
Definition: acos.c:51
static const double pS1
Definition: acos.c:53

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const double one = 1.00000000000000000000e+00
static

Definition at line 48 of file acos.c.

Referenced by acos().

const double pi = 3.14159265358979311600e+00
static

Definition at line 49 of file acos.c.

Referenced by acos().

const double pio2_hi = 1.57079632679489655800e+00
static

Definition at line 50 of file acos.c.

Referenced by acos().

const double pio2_lo = 6.12323399573676603587e-17
static

Definition at line 51 of file acos.c.

Referenced by acos().

const double pS0 = 1.66666666666666657415e-01
static

Definition at line 52 of file acos.c.

Referenced by acos().

const double pS1 = -3.25565818622400915405e-01
static

Definition at line 53 of file acos.c.

Referenced by acos().

const double pS2 = 2.01212532134862925881e-01
static

Definition at line 54 of file acos.c.

Referenced by acos().

const double pS3 = -4.00555345006794114027e-02
static

Definition at line 55 of file acos.c.

Referenced by acos().

const double pS4 = 7.91534994289814532176e-04
static

Definition at line 56 of file acos.c.

Referenced by acos().

const double pS5 = 3.47933107596021167570e-05
static

Definition at line 57 of file acos.c.

Referenced by acos().

const double qS1 = -2.40339491173441421878e+00
static

Definition at line 58 of file acos.c.

Referenced by acos().

const double qS2 = 2.02094576023350569471e+00
static

Definition at line 59 of file acos.c.

Referenced by acos().

const double qS3 = -6.88283971605453293030e-01
static

Definition at line 60 of file acos.c.

Referenced by acos().

const double qS4 = 7.70381505559019352791e-02
static

Definition at line 61 of file acos.c.

Referenced by acos().