1 /*
2 (C) Copyright 2001,2006,
3 International Business Machines Corporation,
4 Sony Computer Entertainment, Incorporated,
5 Toshiba Corporation,
6
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11
12 * Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17 * Neither the names of the copyright holders nor the names of their
18 contributors may be used to endorse or promote products derived from this
19 software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 #ifndef _ATANF_H_
34 #define _ATANF_H_ 1
35
36 #ifndef M_PI_2
37 #define M_PI_2 1.5707963267949f
38 #endif /* M_PI_2 */
39
40 /*
41 * FUNCTION
42 * float _atanf(float x)
43 *
44 * DESCRIPTION
45 * _atanf computes the arc tangent of the value x; that is the value
46 * whose tangent is x.
47 *
48 * _atanf returns the arc tangent in radians and the value is
49 * mathematically defined to be in the range -PI/2 to PI/2.
50 *
51 * The arc tangent function is computed using a polynomial approximation
52 * (B. Carlson, M. Goldstein, Los Alamos Scientific Laboratiry, 1955).
53 * __8__
54 * \
55 * \
56 * atanf(x) = / Ci*x^(2*i+1)
57 * /____
58 * i=0
59 *
60 * for x in the range -1 to 1. The remaining regions are defined to be:
61 *
62 * [1, infinity] : PI/2 + atanf(-1/x)
63 * [-infinity, -1] : -PI/2 + atanf(-1/x)
64 */
65
_atanf(float x)66 static __inline float _atanf(float x)
67 {
68 float xabs;
69 float bias;
70 float x2, x3, x4, x8, x9;
71 float hi, lo;
72 float result;
73
74 bias = 0.0f;
75 xabs = (x < 0.0f) ? -x : x;
76
77 if (xabs >= 1.0f) {
78 bias = M_PI_2;
79 if (x < 0.0f) {
80 bias = -bias;
81 }
82 x = -1.0f / x;
83 }
84 /* Instruction counts can be reduced if the polynomial was
85 * computed entirely from nested (dependent) fma's. However,
86 * to reduce the number of pipeline stalls, the polygon is evaluated
87 * in two halves(hi and lo).
88 */
89 bias += x;
90
91 x2 = x * x;
92 x3 = x2 * x;
93 x4 = x2 * x2;
94 x8 = x4 * x4;
95 x9 = x8 * x;
96 hi = 0.0028662257f * x2 - 0.0161657367f;
97 hi = hi * x2 + 0.0429096138f;
98 hi = hi * x2 - 0.0752896400f;
99 hi = hi * x2 + 0.1065626393f;
100 lo = -0.1420889944f * x2 + 0.1999355085f;
101 lo = lo * x2 - 0.3333314528f;
102 lo = lo * x3 + bias;
103
104 result = hi * x9 + lo;
105
106 return (result);
107 }
108
109 #endif /* _ATANF_H_ */
110
111
112
113