ReactOS 0.4.15-dev-8349-g6f277e9
acosf.c File Reference
#include "libm.h"
#include "libm_util.h"
#include "libm_inlines.h"
#include "libm_errno.h"
Include dependency graph for acosf.c:

Go to the source code of this file.

Macros

#define USE_VALF_WITH_FLAGS
 
#define USE_NANF_WITH_FLAGS
 
#define USE_HANDLE_ERRORF
 

Functions

float FN_PROTOTYPE() acosf (float x)
 

Macro Definition Documentation

◆ USE_HANDLE_ERRORF

#define USE_HANDLE_ERRORF

Definition at line 32 of file acosf.c.

◆ USE_NANF_WITH_FLAGS

#define USE_NANF_WITH_FLAGS

Definition at line 31 of file acosf.c.

◆ USE_VALF_WITH_FLAGS

#define USE_VALF_WITH_FLAGS

Definition at line 30 of file acosf.c.

Function Documentation

◆ acosf()

float FN_PROTOTYPE() acosf ( float  x)

Definition at line 47 of file acosf.c.

48{
49 /* Computes arccos(x).
50 The argument is first reduced by noting that arccos(x)
51 is invalid for abs(x) > 1. For denormal and small
52 arguments arccos(x) = pi/2 to machine accuracy.
53 Remaining argument ranges are handled as follows.
54 For abs(x) <= 0.5 use
55 arccos(x) = pi/2 - arcsin(x)
56 = pi/2 - (x + x^3*R(x^2))
57 where R(x^2) is a rational minimax approximation to
58 (arcsin(x) - x)/x^3.
59 For abs(x) > 0.5 exploit the identity:
60 arccos(x) = pi - 2*arcsin(sqrt(1-x)/2)
61 together with the above rational approximation, and
62 reconstruct the terms carefully.
63 */
64
65 /* Some constants and split constants. */
66
67 static const float
68 piby2 = 1.5707963705e+00F; /* 0x3fc90fdb */
69 static const double
70 pi = 3.1415926535897933e+00, /* 0x400921fb54442d18 */
71 piby2_head = 1.5707963267948965580e+00, /* 0x3ff921fb54442d18 */
72 piby2_tail = 6.12323399573676603587e-17; /* 0x3c91a62633145c07 */
73
74 float u, y, s = 0.0F, r;
75 int xexp, xnan, transform = 0;
76
77 unsigned int ux, aux, xneg;
78
79 GET_BITS_SP32(x, ux);
80 aux = ux & ~SIGNBIT_SP32;
81 xneg = (ux & SIGNBIT_SP32);
82 xnan = (aux > PINFBITPATT_SP32);
83 xexp = (int)((ux & EXPBITS_SP32) >> EXPSHIFTBITS_SP32) - EXPBIAS_SP32;
84
85 /* Special cases */
86
87 if (xnan)
88 {
89 return _handle_errorf("acosf", OP_ACOS, ux|0x00400000, _DOMAIN, 0,
90 EDOM, x, 0.0F, 1);
91 }
92 else if (xexp < -26)
93 /* y small enough that arccos(x) = pi/2 */
94 return valf_with_flags(piby2, AMD_F_INEXACT);
95 else if (xexp >= 0)
96 { /* abs(x) >= 1.0 */
97 if (x == 1.0F)
98 return 0.0F;
99 else if (x == -1.0F)
100 return valf_with_flags((float)pi, AMD_F_INEXACT);
101 else
102 return _handle_errorf("acosf", OP_ACOS, INDEFBITPATT_SP32, _DOMAIN,
103 AMD_F_INVALID, EDOM, x, 0.0F, 1);
104 }
105
106 if (xneg) y = -x;
107 else y = x;
108
109 transform = (xexp >= -1); /* abs(x) >= 0.5 */
110
111 if (transform)
112 { /* Transform y into the range [0,0.5) */
113 r = 0.5F*(1.0F - y);
114 /* VC++ intrinsic call */
116 y = s;
117 }
118 else
119 r = y*y;
120
121 /* Use a rational approximation for [0.0, 0.5] */
122
123 u=r*(0.184161606965100694821398249421F +
124 (-0.0565298683201845211985026327361F +
125 (-0.0133819288943925804214011424456F -
126 0.00396137437848476485201154797087F*r)*r)*r)/
127 (1.10496961524520294485512696706F -
128 0.836411276854206731913362287293F*r);
129
130 if (transform)
131 {
132 /* Reconstruct acos carefully in transformed region */
133 if (xneg)
134 return (float)(pi - 2.0*(s+(y*u - piby2_tail)));
135 else
136 {
137 float c, s1;
138 unsigned int us;
140 PUT_BITS_SP32(0xffff0000 & us, s1);
141 c = (r-s1*s1)/(s+s1);
142 return 2.0F*s1 + (2.0F*c+2.0F*y*u);
143 }
144 }
145 else
146 return (float)(piby2_head - (x - (piby2_tail - x*u)));
147}
float __cdecl _handle_errorf(char *fname, int opcode, unsigned long long value, int type, int flags, int error, float arg1, float arg2, int nargs)
Definition: _handle_error.c:56
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define EDOM
Definition: errno.h:39
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_SP32
Definition: libm_util.h:76
#define GET_BITS_SP32(x, ux)
Definition: libm_util.h:105
#define EXPBITS_SP32
Definition: libm_util.h:69
#define SIGNBIT_SP32
Definition: libm_util.h:68
#define EXPBIAS_SP32
Definition: libm_util.h:79
#define PUT_BITS_SP32(ux, x)
Definition: libm_util.h:111
#define PINFBITPATT_SP32
Definition: libm_util.h:77
#define EXPSHIFTBITS_SP32
Definition: libm_util.h:80
static const WCHAR aux[]
struct S1 s1
static const BYTE us[]
Definition: encode.c:689
static refpint_t pi[]
Definition: server.c:96
void _mm_store_ss(float *p, __m128 a)
Definition: xmmintrin.h:1052
__m128 _mm_load_ss(float const *p)
Definition: xmmintrin.h:956
__m128 _mm_sqrt_ss(__m128 a)
Definition: xmmintrin.h:592