ReactOS 0.4.15-dev-7953-g1f49173
acos.c File Reference
#include "libm.h"
#include "libm_util.h"
#include "libm_inlines.h"
#include "libm_errno.h"
Include dependency graph for acos.c:

Go to the source code of this file.

Macros

#define USE_VAL_WITH_FLAGS
 
#define USE_NAN_WITH_FLAGS
 
#define USE_HANDLE_ERROR
 

Functions

double FN_PROTOTYPE() acos (double x)
 

Macro Definition Documentation

◆ USE_HANDLE_ERROR

#define USE_HANDLE_ERROR

Definition at line 32 of file acos.c.

◆ USE_NAN_WITH_FLAGS

#define USE_NAN_WITH_FLAGS

Definition at line 31 of file acos.c.

◆ USE_VAL_WITH_FLAGS

#define USE_VAL_WITH_FLAGS

Definition at line 30 of file acos.c.

Function Documentation

◆ acos()

double FN_PROTOTYPE() acos ( double  x)

Definition at line 44 of file acos.c.

45{
46 /* Computes arccos(x).
47 The argument is first reduced by noting that arccos(x)
48 is invalid for abs(x) > 1. For denormal and small
49 arguments arccos(x) = pi/2 to machine accuracy.
50 Remaining argument ranges are handled as follows.
51 For abs(x) <= 0.5 use
52 arccos(x) = pi/2 - arcsin(x)
53 = pi/2 - (x + x^3*R(x^2))
54 where R(x^2) is a rational minimax approximation to
55 (arcsin(x) - x)/x^3.
56 For abs(x) > 0.5 exploit the identity:
57 arccos(x) = pi - 2*arcsin(sqrt(1-x)/2)
58 together with the above rational approximation, and
59 reconstruct the terms carefully.
60 */
61
62 /* Some constants and split constants. */
63
64 static const double
65 pi = 3.1415926535897933e+00, /* 0x400921fb54442d18 */
66 piby2 = 1.5707963267948965580e+00, /* 0x3ff921fb54442d18 */
67 piby2_head = 1.5707963267948965580e+00, /* 0x3ff921fb54442d18 */
68 piby2_tail = 6.12323399573676603587e-17; /* 0x3c91a62633145c07 */
69
70 double u, y, s=0.0, r;
71 int xexp, xnan, transform=0;
72
73 unsigned long long ux, aux, xneg;
74 GET_BITS_DP64(x, ux);
75 aux = ux & ~SIGNBIT_DP64;
76 xneg = (ux & SIGNBIT_DP64);
77 xnan = (aux > PINFBITPATT_DP64);
78 xexp = (int)((ux & EXPBITS_DP64) >> EXPSHIFTBITS_DP64) - EXPBIAS_DP64;
79
80 /* Special cases */
81
82 if (xnan)
83 {
84 return _handle_error("acos", OP_ACOS, ux|0x0008000000000000, _DOMAIN,
85 0, EDOM, x, 0.0, 1);
86 }
87 else if (xexp < -56)
88 { /* y small enough that arccos(x) = pi/2 */
89 return val_with_flags(piby2, AMD_F_INEXACT);
90 }
91 else if (xexp >= 0)
92 { /* abs(x) >= 1.0 */
93 if (x == 1.0)
94 return 0.0;
95 else if (x == -1.0)
96 return val_with_flags(pi, AMD_F_INEXACT);
97 else
98 return _handle_error("acos", OP_ACOS, INDEFBITPATT_DP64, _DOMAIN,
99 AMD_F_INVALID, EDOM, x, 0.0, 1);
100 }
101
102 if (xneg) y = -x;
103 else y = x;
104
105 transform = (xexp >= -1); /* abs(x) >= 0.5 */
106
107 if (transform)
108 { /* Transform y into the range [0,0.5) */
109 r = 0.5*(1.0 - y);
110 /* VC++ intrinsic call */
112 y = s;
113 }
114 else
115 r = y*y;
116
117 /* Use a rational approximation for [0.0, 0.5] */
118
119 u = r*(0.227485835556935010735943483075 +
120 (-0.445017216867635649900123110649 +
121 (0.275558175256937652532686256258 +
122 (-0.0549989809235685841612020091328 +
123 (0.00109242697235074662306043804220 +
124 0.0000482901920344786991880522822991*r)*r)*r)*r)*r)/
125 (1.36491501334161032038194214209 +
126 (-3.28431505720958658909889444194 +
127 (2.76568859157270989520376345954 +
128 (-0.943639137032492685763471240072 +
129 0.105869422087204370341222318533*r)*r)*r)*r);
130
131 if (transform)
132 { /* Reconstruct acos carefully in transformed region */
133 if (xneg) return pi - 2.0*(s+(y*u - piby2_tail));
134 else
135 {
136 double c, s1;
137 unsigned long long us;
139 PUT_BITS_DP64(0xffffffff00000000 & us, s1);
140 c = (r-s1*s1)/(s+s1);
141 return 2.0*s1 + (2.0*c+2.0*y*u);
142 }
143 }
144 else
145 return piby2_head - (x - (piby2_tail - x*u));
146}
double __cdecl _handle_error(char *fname, int opcode, unsigned long long value, int type, int flags, int error, double arg1, double arg2, int nargs)
Handles an error condition.
Definition: _handle_error.c:34
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define EDOM
Definition: errno.h:39
__m128d _mm_setzero_pd(void)
Definition: emmintrin.h:1048
__m128d _mm_sqrt_sd(__m128d a, __m128d b)
Definition: emmintrin.h:611
__m128d _mm_load_sd(double const *dp)
Definition: emmintrin.h:991
void _mm_store_sd(double *dp, __m128d a)
Definition: emmintrin.h:1059
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble s
Definition: gl.h:2039
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint GLenum GLenum transform
Definition: glext.h:9407
const GLubyte * c
Definition: glext.h:8905
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define _DOMAIN
Definition: math.h:39
#define c
Definition: ke_i.h:80
#define AMD_F_INEXACT
Definition: libm_new.h:82
#define AMD_F_INVALID
Definition: libm_new.h:86
#define INDEFBITPATT_DP64
Definition: libm_util.h:52
#define EXPSHIFTBITS_DP64
Definition: libm_util.h:56
#define GET_BITS_DP64(x, ux)
Definition: libm_util.h:118
#define PINFBITPATT_DP64
Definition: libm_util.h:53
#define SIGNBIT_DP64
Definition: libm_util.h:44
#define EXPBITS_DP64
Definition: libm_util.h:45
#define EXPBIAS_DP64
Definition: libm_util.h:55
#define PUT_BITS_DP64(ux, x)
Definition: libm_util.h:124
static const WCHAR aux[]
struct S1 s1
static const BYTE us[]
Definition: encode.c:689
static refpint_t pi[]
Definition: server.c:96