@@ -11,66 +11,79 @@ where
11
11
{
12
12
#[ inline]
13
13
fn asin ( self ) -> Self {
14
- let PI_BY_2 = Self :: splat ( 1.5707964f32 ) ;
15
- let LIM : Self = Self :: splat ( 0.9f32 ) ;
16
- let c: Self = ( ( self ) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( -PI_BY_2 , PI_BY_2 ) ;
17
- let s: Self =
18
- ( ( self ) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( -Self :: splat ( 1f32 ) , Self :: splat ( 1f32 ) ) ;
19
- let x: Self = ( ( self * self ) . lanes_lt ( LIM * LIM ) )
20
- . select ( self , ( Self :: splat ( 1f32 ) - self * self ) . sqrt ( ) ) ;
21
- let y: Self = ( Self :: splat ( 4374.977f32 ) )
22
- . mul_add ( x * x, -Self :: splat ( 13781.558f32 ) )
23
- . mul_add ( x * x, Self :: splat ( 17105.695f32 ) )
24
- . mul_add ( x * x, -Self :: splat ( 10486.649f32 ) )
25
- . mul_add ( x * x, Self :: splat ( 3231.7603f32 ) )
26
- . mul_add ( x * x, -Self :: splat ( 447.56482f32 ) )
27
- . mul_add ( x * x, Self :: splat ( 21.78206f32 ) )
28
- . mul_add ( x * x, Self :: splat ( 0.84158415f32 ) )
29
- * x;
30
- ( ( self * self ) . lanes_lt ( LIM * LIM ) ) . select ( y, c - y * s)
14
+ let arg = self ;
15
+ arg. atan2 ( ( Self :: splat ( 1f32 ) - arg * arg) . sqrt ( ) )
31
16
}
32
17
#[ inline]
33
18
fn acos ( self ) -> Self {
34
19
let PI_BY_2 = Self :: splat ( 1.5707964f32 ) ;
35
20
let PI = Self :: splat ( 3.1415927f32 ) ;
21
+ let arg = self ;
36
22
let LIM : Self = Self :: splat ( 0.9f32 ) ;
37
- let c: Self = ( ( self ) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( PI , Self :: splat ( 0f32 ) ) ;
23
+ let c: Self = ( ( arg ) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( PI , Self :: splat ( 0f32 ) ) ;
38
24
let s: Self =
39
- ( ( self ) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( Self :: splat ( 1f32 ) , -Self :: splat ( 1f32 ) ) ;
40
- let x: Self = ( ( self * self ) . lanes_lt ( LIM * LIM ) )
41
- . select ( self , ( Self :: splat ( 1f32 ) - self * self ) . sqrt ( ) ) ;
42
- let y: Self = ( Self :: splat ( 4374.977f32 ) )
43
- . mul_add ( x * x, -Self :: splat ( 13781.558f32 ) )
44
- . mul_add ( x * x, Self :: splat ( 17105.695f32 ) )
45
- . mul_add ( x * x, -Self :: splat ( 10486.649f32 ) )
46
- . mul_add ( x * x, Self :: splat ( 3231.7603f32 ) )
47
- . mul_add ( x * x, - Self :: splat ( 447.56482f32 ) )
48
- . mul_add ( x * x, Self :: splat ( 21.78206f32 ) )
49
- . mul_add ( x * x, Self :: splat ( 0.84158415f32 ) )
25
+ ( ( arg ) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( Self :: splat ( 1f32 ) , -Self :: splat ( 1f32 ) ) ;
26
+ let x: Self =
27
+ ( ( arg * arg ) . lanes_lt ( LIM * LIM ) ) . select ( arg , ( Self :: splat ( 1f32 ) - arg * arg ) . sqrt ( ) ) ;
28
+ let y: Self = ( Self :: splat ( 1.3740137f32 ) )
29
+ . mul_add ( x * x, -Self :: splat ( 3.1993167f32 ) )
30
+ . mul_add ( x * x, Self :: splat ( 3.103398f32 ) )
31
+ . mul_add ( x * x, -Self :: splat ( 1.4533828f32 ) )
32
+ . mul_add ( x * x, Self :: splat ( 0.41395915f32 ) )
33
+ . mul_add ( x * x, Self :: splat ( 0.03113007f32 ) )
34
+ . mul_add ( x * x, Self :: splat ( 0.16861732f32 ) )
35
+ . mul_add ( x * x, Self :: splat ( 0.99998593f32 ) )
50
36
* x;
51
- ( ( self * self ) . lanes_lt ( LIM * LIM ) ) . select ( PI_BY_2 - y, c - y * s)
37
+ ( ( arg * arg ) . lanes_lt ( LIM * LIM ) ) . select ( PI_BY_2 - y, c - y * s)
52
38
}
53
39
#[ inline]
54
40
fn atan ( self ) -> Self {
55
41
let PI_BY_2 = Self :: splat ( 1.5707964f32 ) ;
42
+ let arg = self ;
56
43
let LIM : Self = Self :: splat ( 1f32 ) ;
57
- let c: Self = ( ( self ) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( -PI_BY_2 , PI_BY_2 ) ;
58
- let x: Self = ( ( self . abs ( ) ) . lanes_lt ( LIM ) ) . select ( self , self . recip ( ) ) ;
59
- let y: Self = ( -Self :: splat ( 95.70126f32 ) )
60
- . mul_add ( x * x, Self :: splat ( 424.99908f32 ) )
61
- . mul_add ( x * x, -Self :: splat ( 767.4826f32 ) )
62
- . mul_add ( x * x, Self :: splat ( 714.51953f32 ) )
63
- . mul_add ( x * x, -Self :: splat ( 354.32654f32 ) )
64
- . mul_add ( x * x, Self :: splat ( 83.9618f32 ) )
65
- . mul_add ( x * x, -Self :: splat ( 6.2395816f32 ) )
66
- . mul_add ( x * x, Self :: splat ( 1.0549852f32 ) )
44
+ let c: Self = ( ( arg ) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( -PI_BY_2 , PI_BY_2 ) ;
45
+ let x: Self = ( ( arg . abs ( ) ) . lanes_lt ( LIM ) ) . select ( arg , arg . recip ( ) ) ;
46
+ let y: Self = ( -Self :: splat ( 0.0039602574f32 ) )
47
+ . mul_add ( x * x, Self :: splat ( 0.021659138f32 ) )
48
+ . mul_add ( x * x, -Self :: splat ( 0.05587457f32 ) )
49
+ . mul_add ( x * x, Self :: splat ( 0.09664151f32 ) )
50
+ . mul_add ( x * x, -Self :: splat ( 0.13930209f32 ) )
51
+ . mul_add ( x * x, Self :: splat ( 0.19954468f32 ) )
52
+ . mul_add ( x * x, -Self :: splat ( 0.33331004f32 ) )
53
+ . mul_add ( x * x, Self :: splat ( 0.9999998f32 ) )
67
54
* x;
68
- ( ( self . abs ( ) ) . lanes_lt ( LIM ) ) . select ( y, c - y)
55
+ ( ( arg. abs ( ) ) . lanes_lt ( LIM ) ) . select ( y, c - y)
56
+ }
57
+ #[ inline]
58
+ fn atan2 ( self , x : Self ) -> Self {
59
+ let PI_BY_2 = Self :: splat ( 1.5707964f32 ) ;
60
+ let PI = Self :: splat ( 3.1415927f32 ) ;
61
+ let y = self ;
62
+ let offset180: Self = ( ( y) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( -PI , PI ) ;
63
+ let x1: Self = ( ( x) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( -x, x) ;
64
+ let y1: Self = ( ( x) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( -y, y) ;
65
+ let offset1: Self = ( ( x) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( offset180, Self :: splat ( 0f32 ) ) ;
66
+ let offset90: Self = ( ( y) . lanes_lt ( Self :: splat ( 0f32 ) ) ) . select ( -PI_BY_2 , PI_BY_2 ) ;
67
+ let x2: Self = ( ( y1. abs ( ) ) . lanes_gt ( x1) ) . select ( y1, x1) ;
68
+ let y2: Self = ( ( y1. abs ( ) ) . lanes_gt ( x1) ) . select ( -x1, y1) ;
69
+ let offset2: Self = ( ( y1. abs ( ) ) . lanes_gt ( x1) ) . select ( offset1 + offset90, offset1) ;
70
+ let x3: Self = y2 / x2;
71
+ let y3: Self = ( -Self :: splat ( 0.0039602574f32 ) )
72
+ . mul_add ( x3 * x3, Self :: splat ( 0.021659138f32 ) )
73
+ . mul_add ( x3 * x3, -Self :: splat ( 0.05587457f32 ) )
74
+ . mul_add ( x3 * x3, Self :: splat ( 0.09664151f32 ) )
75
+ . mul_add ( x3 * x3, -Self :: splat ( 0.13930209f32 ) )
76
+ . mul_add ( x3 * x3, Self :: splat ( 0.19954468f32 ) )
77
+ . mul_add ( x3 * x3, -Self :: splat ( 0.33331004f32 ) )
78
+ . mul_add ( x3 * x3, Self :: splat ( 0.9999998f32 ) )
79
+ * x3;
80
+ y3 + offset2
69
81
}
70
82
#[ inline]
71
83
fn sin ( self ) -> Self {
72
84
let RECIP_2PI = Self :: splat ( 0.15915494f32 ) ;
73
- let scaled: Self = self * RECIP_2PI ;
85
+ let arg = self ;
86
+ let scaled: Self = arg * RECIP_2PI ;
74
87
let x: Self = scaled - scaled. round ( ) ;
75
88
( -Self :: splat ( 12.26886f32 ) )
76
89
. mul_add ( x * x, Self :: splat ( 41.21624f32 ) )
83
96
#[ inline]
84
97
fn cos ( self ) -> Self {
85
98
let RECIP_2PI = Self :: splat ( 0.15915494f32 ) ;
86
- let scaled: Self = self * RECIP_2PI ;
99
+ let arg = self ;
100
+ let scaled: Self = arg * RECIP_2PI ;
87
101
let x: Self = scaled - scaled. round ( ) ;
88
102
( Self :: splat ( 6.5286584f32 ) )
89
103
. mul_add ( x * x, -Self :: splat ( 25.973276f32 ) )
96
110
#[ inline]
97
111
fn tan ( self ) -> Self {
98
112
let RECIP_PI = Self :: splat ( 0.31830987f32 ) ;
99
- let scaled: Self = self * RECIP_PI ;
113
+ let arg = self ;
114
+ let scaled: Self = arg * RECIP_PI ;
100
115
let x: Self = scaled - scaled. round ( ) ;
101
116
let recip: Self = Self :: splat ( 1f32 ) / ( x * x - Self :: splat ( 0.25f32 ) ) ;
102
117
let y: Self = ( Self :: splat ( 0.014397301f32 ) )
0 commit comments