ReactOS 0.4.15-dev-7906-g1b85a5f
asinf.c
Go to the documentation of this file.
1
2/*******************************************************************************
3MIT License
4-----------
5
6Copyright (c) 2002-2019 Advanced Micro Devices, Inc.
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this Software and associated documentaon files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24THE SOFTWARE.
25*******************************************************************************/
26
27#include "libm.h"
28#include "libm_util.h"
29
30#define USE_VALF_WITH_FLAGS
31#define USE_NANF_WITH_FLAGS
32#define USE_HANDLE_ERRORF
33#include "libm_inlines.h"
34#undef USE_NANF_WITH_FLAGS
35#undef USE_VALF_WITH_FLAGS
36#undef USE_HANDLE_ERRORF
37
38#include "libm_errno.h"
39
40#ifdef _MSC_VER
41// Disable "C4163: not available as intrinsic function" warning that older
42// compilers may issue here.
43#pragma warning(disable:4163)
44#pragma function(asinf)
45#endif
46
47float FN_PROTOTYPE(asinf)(float x)
48{
49 /* Computes arcsin(x).
50 The argument is first reduced by noting that arcsin(x)
51 is invalid for abs(x) > 1 and arcsin(-x) = -arcsin(x).
52 For denormal and small arguments arcsin(x) = x to machine
53 accuracy. Remaining argument ranges are handled as follows.
54 For abs(x) <= 0.5 use
55 arcsin(x) = x + x^3*R(x^2)
56 where R(x^2) is a rational minimax approximation to
57 (arcsin(x) - x)/x^3.
58 For abs(x) > 0.5 exploit the identity:
59 arcsin(x) = pi/2 - 2*arcsin(sqrt(1-x)/2)
60 together with the above rational approximation, and
61 reconstruct the terms carefully.
62 */
63
64 /* Some constants and split constants. */
65
66 static const float
67 piby2_tail = 7.5497894159e-08F, /* 0x33a22168 */
68 hpiby2_head = 7.8539812565e-01F, /* 0x3f490fda */
69 piby2 = 1.5707963705e+00F; /* 0x3fc90fdb */
70 float u, v, y, s = 0.0F, r;
71 int xexp, xnan, transform = 0;
72
73 unsigned int ux, aux, xneg;
74 GET_BITS_SP32(x, ux);
75 aux = ux & ~SIGNBIT_SP32;
76 xneg = (ux & SIGNBIT_SP32);
77 xnan = (aux > PINFBITPATT_SP32);
78 xexp = (int)((ux & EXPBITS_SP32) >> EXPSHIFTBITS_SP32) - EXPBIAS_SP32;
79
80 /* Special cases */
81
82 if (xnan)
83 {
84 return _handle_errorf("asinf", OP_ASIN, ux|0x00400000, _DOMAIN, 0,
85 EDOM, x, 0.0F, 1);
86 }
87 else if (xexp < -14)
88 /* y small enough that arcsin(x) = x */
89 return valf_with_flags(x, AMD_F_INEXACT);
90 else if (xexp >= 0)
91 {
92 /* abs(x) >= 1.0 */
93 if (x == 1.0F)
94 return valf_with_flags(piby2, AMD_F_INEXACT);
95 else if (x == -1.0F)
96 return valf_with_flags(-piby2, AMD_F_INEXACT);
97 else
98 return _handle_errorf("asinf", OP_ASIN, INDEFBITPATT_SP32, _DOMAIN,
99 AMD_F_INVALID, EDOM, x, 0.0F, 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.5F*(1.0F - 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.184161606965100694821398249421F +
120 (-0.0565298683201845211985026327361F +
121 (-0.0133819288943925804214011424456F -
122 0.00396137437848476485201154797087F*r)*r)*r)/
123 (1.10496961524520294485512696706F -
124 0.836411276854206731913362287293F*r);
125
126 if (transform)
127 {
128 /* Reconstruct asin carefully in transformed region */
129 float c, s1, p, q;
130 unsigned int us;
132 PUT_BITS_SP32(0xffff0000 & us, s1);
133 c = (r-s1*s1)/(s+s1);
134 p = 2.0F*s*u - (piby2_tail-2.0F*c);
135 q = hpiby2_head - 2.0F*s1;
136 v = hpiby2_head - (p-q);
137 }
138 else
139 {
140 /* Use a temporary variable to prevent VC++ rearranging
141 y + y*u
142 into
143 y * (1 + u)
144 and getting an incorrectly rounded result */
145 float tmp;
146 tmp = y * u;
147 v = y + tmp;
148 }
149
150 if (xneg) return -v;
151 else return v;
152}
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
_Check_return_ float __cdecl asinf(_In_ float x)
Definition: asinf.c:11
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
const GLdouble * v
Definition: gl.h:2040
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
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLuint GLenum GLenum transform
Definition: glext.h:9407
const GLubyte * c
Definition: glext.h:8905
GLfloat GLfloat p
Definition: glext.h:8902
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 FN_PROTOTYPE(fname)
Definition: libm.h:29
#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
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