ReactOS 0.4.15-dev-8349-g6f277e9
atanf.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_NAN_WITH_FLAGS
32#define USE_HANDLE_ERRORF
33#include "libm_inlines.h"
34#undef USE_VALF_WITH_FLAGS
35#undef USE_NAN_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(atanf)
45#endif
46
47float FN_PROTOTYPE(atanf)(float fx)
48{
49
50 /* Some constants and split constants. */
51
52 static double piby2 = 1.5707963267948966e+00; /* 0x3ff921fb54442d18 */
53
54 double c, v, s, q, z;
55 unsigned int xnan;
56
57 double x = fx;
58
59 /* Find properties of argument fx. */
60
61 unsigned long long ux, aux, xneg;
62
63 GET_BITS_DP64(x, ux);
64 aux = ux & ~SIGNBIT_DP64;
65 xneg = ux & SIGNBIT_DP64;
66
67 v = x;
68 if (xneg) v = -x;
69
70 /* Argument reduction to range [-7/16,7/16] */
71
72 if (aux < 0x3fdc000000000000) /* v < 7./16. */
73 {
74 x = v;
75 c = 0.0;
76 }
77 else if (aux < 0x3fe6000000000000) /* v < 11./16. */
78 {
79 x = (2.0*v-1.0)/(2.0+v);
80 /* c = arctan(0.5) */
81 c = 4.63647609000806093515e-01; /* 0x3fddac670561bb4f */
82 }
83 else if (aux < 0x3ff3000000000000) /* v < 19./16. */
84 {
85 x = (v-1.0)/(1.0+v);
86 /* c = arctan(1.) */
87 c = 7.85398163397448278999e-01; /* 0x3fe921fb54442d18 */
88 }
89 else if (aux < 0x4003800000000000) /* v < 39./16. */
90 {
91 x = (v-1.5)/(1.0+1.5*v);
92 /* c = arctan(1.5) */
93 c = 9.82793723247329054082e-01; /* 0x3fef730bd281f69b */
94 }
95 else
96 {
97
98 xnan = (aux > PINFBITPATT_DP64);
99
100 if (xnan)
101 {
102 /* x is NaN */
103 unsigned int uhx;
104 GET_BITS_SP32(fx, uhx);
105 return _handle_errorf("atanf", OP_ATAN, uhx|0x00400000, _DOMAIN,
106 0, EDOM, fx, 0.0F, 1);
107 }
108 else if (v > 0x4c80000000000000)
109 { /* abs(x) > 2^26 => arctan(1/x) is
110 insignificant compared to piby2 */
111 if (xneg)
112 return valf_with_flags((float)-piby2, AMD_F_INEXACT);
113 else
114 return valf_with_flags((float)piby2, AMD_F_INEXACT);
115 }
116
117 x = -1.0/v;
118 /* c = arctan(infinity) */
119 c = 1.57079632679489655800e+00; /* 0x3ff921fb54442d18 */
120 }
121
122 /* Core approximation: Remez(2,2) on [-7/16,7/16] */
123
124 s = x*x;
125 q = x*s*
126 (0.296528598819239217902158651186e0 +
127 (0.192324546402108583211697690500e0 +
128 0.470677934286149214138357545549e-2*s)*s)/
129 (0.889585796862432286486651434570e0 +
130 (0.111072499995399550138837673349e1 +
131 0.299309699959659728404442796915e0*s)*s);
132
133 z = c - (q - x);
134
135 if (xneg) z = -z;
136 return (float)z;
137}
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 atanf(_In_ float x)
Definition: atanf.c:11
#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
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
const GLubyte * c
Definition: glext.h:8905
GLdouble GLdouble z
Definition: glext.h:5874
#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 GET_BITS_SP32(x, ux)
Definition: libm_util.h:105
#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
static const WCHAR aux[]
GLfixed fx
Definition: tritemp.h:484