/* asin.c
*
* Inverse circular sine
*
*
*
* SYNOPSIS :
*
* double x , y , asin ( ) ;
*
* y = asin ( x ) ;
*
*
*
* DESCRIPTION :
*
* Returns radian angle between - pi / 2 and + pi / 2 whose sine is x .
*
* A rational function of the form x + x * * 3 P ( x * * 2 ) / Q ( x * * 2 )
* is used for | x | in the interval [ 0 , 0 . 5 ] . If | x | > 0 . 5 it is
* transformed by the identity
*
* asin ( x ) = pi / 2 - 2 asin ( sqrt ( ( 1 - x ) / 2 ) ) .
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC - 1 , 1 40000 2 . 6 e - 17 7 . 1 e - 18
* IEEE - 1 , 1 10 ^ 6 1 . 9 e - 16 5 . 4 e - 17
*
*
* ERROR MESSAGES :
*
* message condition value returned
* asin domain | x | > 1 NAN
*
*/
/* acos()
*
* Inverse circular cosine
*
*
*
* SYNOPSIS :
*
* double x , y , acos ( ) ;
*
* y = acos ( x ) ;
*
*
*
* DESCRIPTION :
*
* Returns radian angle between 0 and pi whose cosine
* is x .
*
* Analytically , acos ( x ) = pi / 2 - asin ( x ) . However if | x | is
* near 1 , there is cancellation error in subtracting asin ( x )
* from pi / 2 . Hence if x < - 0 . 5 ,
*
* acos ( x ) = pi - 2 . 0 * asin ( sqrt ( ( 1 + x ) / 2 ) ) ;
*
* or if x > + 0 . 5 ,
*
* acos ( x ) = 2 . 0 * asin ( sqrt ( ( 1 - x ) / 2 ) ) .
*
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC - 1 , 1 50000 3 . 3 e - 17 8 . 2 e - 18
* IEEE - 1 , 1 10 ^ 6 2 . 2 e - 16 6 . 5 e - 17
*
*
* ERROR MESSAGES :
*
* message condition value returned
* asin domain | x | > 1 NAN
*/
/* asin.c */
/*
Cephes Math Library Release 2 . 8 : June , 2000
Copyright 1984 , 1995 , 2000 by Stephen L . Moshier
*/
#include "mconf.h"
/* arcsin(x) = x + x^3 P(x^2)/Q(x^2)
0 < = x < = 0 . 625
Peak relative error = 1.2e-18 */
#if UNK
static double P[6 ] = {
4 .253011369004428248960 E-3 , -6 .019598008014123785661 E-1 ,
5 .444622390564711410273 E0, -1 .626247967210700244449 E1,
1 .956261983317594739197 E1, -8 .198089802484824371615 E0,
};
static double Q[5 ] = {
/* 1.000000000000000000000E0, */
-1 .474091372988853791896 E1, 7 .049610280856842141659 E1,
-1 .471791292232726029859 E2, 1 .395105614657485689735 E2,
-4 .918853881490881290097 E1,
};
#endif
#if DEC
static short P[24 ] = {
0036213 , 0056330 , 0057244 , 0053234 , 0140032 , 0015011 , 0114762 , 0160255 ,
0040656 , 0035130 , 0136121 , 0067313 , 0141202 , 0014616 , 0170474 , 0101731 ,
0041234 , 0100076 , 0151674 , 0111310 , 0141003 , 0025540 , 0033165 , 0077246 ,
};
static short Q[20 ] = {
/* 0040200,0000000,0000000,0000000, */
0141153 , 0155310 , 0055360 , 0072530 , 0041614 , 0177001 , 0027764 ,
0101237 , 0142023 , 0026733 , 0064653 , 0133266 , 0042013 , 0101264 ,
0023775 , 0176351 , 0141504 , 0140420 , 0050660 , 0036543 ,
};
#endif
#if IBMPC
static short P[24 ] = {
0 x8ad3, 0 x0bd4, 0 x6b9b, 0 x3f71, 0 x5c16, 0 x333e, 0 x4341, 0 xbfe3,
0 x2dd9, 0 x178a, 0 xc74b, 0 x4015, 0 x907b, 0 xde27, 0 x4331, 0 xc030,
0 x9259, 0 xda77, 0 x9007, 0 x4033, 0 xafd5, 0 x06ce, 0 x656c, 0 xc020,
};
static short Q[20 ] = {
/* 0x0000,0x0000,0x0000,0x3ff0, */
0 x0eab, 0 x0b5e, 0 x7b59, 0 xc02d, 0 x9054, 0 x25fe, 0 x9fc0,
0 x4051, 0 x76d7, 0 x6d35, 0 x65bb, 0 xc062, 0 xbf9d, 0 x84ff,
0 x7056, 0 x4061, 0 x07ac, 0 x0a36, 0 x9822, 0 xc048,
};
#endif
#if MIEEE
static short P[24 ] = {
0 x3f71, 0 x6b9b, 0 x0bd4, 0 x8ad3, 0 xbfe3, 0 x4341, 0 x333e, 0 x5c16,
0 x4015, 0 xc74b, 0 x178a, 0 x2dd9, 0 xc030, 0 x4331, 0 xde27, 0 x907b,
0 x4033, 0 x9007, 0 xda77, 0 x9259, 0 xc020, 0 x656c, 0 x06ce, 0 xafd5,
};
static short Q[20 ] = {
/* 0x3ff0,0x0000,0x0000,0x0000, */
0 xc02d, 0 x7b59, 0 x0b5e, 0 x0eab, 0 x4051, 0 x9fc0, 0 x25fe,
0 x9054, 0 xc062, 0 x65bb, 0 x6d35, 0 x76d7, 0 x4061, 0 x7056,
0 x84ff, 0 xbf9d, 0 xc048, 0 x9822, 0 x0a36, 0 x07ac,
};
#endif
/* arcsin(1-x) = pi/2 - sqrt(2x)(1+R(x))
0 < = x < = 0 . 5
Peak relative error = 4.2e-18 */
#if UNK
static double R[5 ] = {
2 .967721961301243206100 E-3 , -5 .634242780008963776856 E-1 ,
6 .968710824104713396794 E0, -2 .556901049652824852289 E1,
2 .853665548261061424989 E1,
};
static double S[4 ] = {
/* 1.000000000000000000000E0, */
-2 .194779531642920639778 E1,
1 .470656354026814941758 E2,
-3 .838770957603691357202 E2,
3 .424398657913078477438 E2,
};
#endif
#if DEC
static short R[20 ] = {
0036102 , 0077034 , 0142164 , 0174103 , 0140020 , 0036222 , 0147711 ,
0044173 , 0040736 , 0177655 , 0153631 , 0171523 , 0141314 , 0106525 ,
0060015 , 0055474 , 0041344 , 0045422 , 0003630 , 0040344 ,
};
static short S[16 ] = {
/* 0040200,0000000,0000000,0000000, */
0141257 , 0112425 , 0132772 , 0166136 , 0042023 , 0010315 , 0075523 , 0175020 ,
0142277 , 0170104 , 0126203 , 0017563 , 0042253 , 0034115 , 0102662 , 0022757 ,
};
#endif
#if IBMPC
static short R[20 ] = {
0 x9f08, 0 x988e, 0 x4fc3, 0 x3f68, 0 x290f, 0 x59f9, 0 x0792,
0 xbfe2, 0 x3e6a, 0 xbaf3, 0 xdff5, 0 x401b, 0 xab68, 0 xac01,
0 x91aa, 0 xc039, 0 x081d, 0 x40f3, 0 x8962, 0 x403c,
};
static short S[16 ] = {
/* 0x0000,0x0000,0x0000,0x3ff0, */
0 x5d8c, 0 xb6bf, 0 xf2a2, 0 xc035, 0 x7f42, 0 xaf6a, 0 x6219, 0 x4062,
0 x63ee, 0 x9590, 0 xfe08, 0 xc077, 0 x44be, 0 xb0b6, 0 x6709, 0 x4075,
};
#endif
#if MIEEE
static short R[20 ] = {
0 x3f68, 0 x4fc3, 0 x988e, 0 x9f08, 0 xbfe2, 0 x0792, 0 x59f9,
0 x290f, 0 x401b, 0 xdff5, 0 xbaf3, 0 x3e6a, 0 xc039, 0 x91aa,
0 xac01, 0 xab68, 0 x403c, 0 x8962, 0 x40f3, 0 x081d,
};
static short S[16 ] = {
/* 0x3ff0,0x0000,0x0000,0x0000, */
0 xc035, 0 xf2a2, 0 xb6bf, 0 x5d8c, 0 x4062, 0 x6219, 0 xaf6a, 0 x7f42,
0 xc077, 0 xfe08, 0 x9590, 0 x63ee, 0 x4075, 0 x6709, 0 xb0b6, 0 x44be,
};
#endif
/* pi/2 = PIO2 + MOREBITS. */
#ifdef DEC
#define MOREBITS 5 .721188726109831840122 E-18
#else
#define MOREBITS 6 .123233995736765886130 E-17
#endif
#ifdef ANSIPROT
extern double polevl(double , void *, int );
extern double p1evl(double , void *, int );
extern double sqrt(double );
double asin(double );
#else
double sqrt(), polevl(), p1evl();
double asin();
#endif
extern double PIO2, PIO4, NAN;
double asin(x) double x;
{
double a, p, z, zz;
short sign;
if (x > 0 ) {
sign = 1 ;
a = x;
} else {
sign = -1 ;
a = -x;
}
if (a > 1 .0 ) {
mtherr("asin" , DOMAIN);
return (NAN);
}
if (a > 0 .625 ) {
/* arcsin(1-x) = pi/2 - sqrt(2x)(1+R(x)) */
zz = 1 .0 - a;
p = zz * polevl(zz, R, 4 ) / p1evl(zz, S, 4 );
zz = sqrt(zz + zz);
z = PIO4 - zz;
zz = zz * p - MOREBITS;
z = z - zz;
z = z + PIO4;
} else {
if (a < 1 .0 e-8 ) {
return (x);
}
zz = a * a;
z = zz * polevl(zz, P, 5 ) / p1evl(zz, Q, 5 );
z = a * z + a;
}
if (sign < 0 )
z = -z;
return (z);
}
double acos(x) double x;
{
double z;
if ((x < -1 .0 ) || (x > 1 .0 )) {
mtherr("acos" , DOMAIN);
return (NAN);
}
if (x > 0 .5 ) {
return (2 .0 * asin(sqrt(0 .5 - 0 .5 * x)));
}
z = PIO4 - asin(x);
z = z + MOREBITS;
z = z + PIO4;
return (z);
}
Messung V0.5 in Prozent C=73 H=93 G=83
¤ Dauer der Verarbeitung: 0.6 Sekunden
¤
*© Formatika GbR, Deutschland