-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtanf.hpp
More file actions
108 lines (80 loc) · 2.85 KB
/
tanf.hpp
File metadata and controls
108 lines (80 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef VXL_TANF_HPP
# define VXL_TANF_HPP
# pragma once
#include "sinf.hpp"
namespace vxl
{
template <unsigned N>
inline constexpr vector<float, N> tan(vector<float, N> xx) noexcept
{
using int_value_type = typename vector_traits<float, N>::int_value_type;
using int_vector_type = typename vector_traits<float, N>::int_vector_type;
auto& x(xx.ref());
auto& xi((int_vector_type&)(x));
auto sign(int_vector_type(x) & cvector<int_value_type, N>(1 << 31));
xi &= cvector<int_value_type, N>(~(1 << 31));
auto j(convert<int_value_type, N>(
cvector<float, N>(detail::constantsf::FOPI) * x));
j += j & cvector<int_value_type, N>(1);
auto y(convert<float, N>(j));
auto const z(((x - y * cvector<float, N>(detail::constantsf::DP1)) -
y * cvector<float, N>(detail::constantsf::DP2)) -
y * cvector<float, N>(detail::constantsf::DP3));
auto const zz(z * z);
y = select(
(((((cvector<float, N>(9.38540185543e-3f) * zz +
cvector<float, N>(3.11992232697e-3f)) * zz +
cvector<float, N>(2.44301354525e-2f)) * zz +
cvector<float, N>(5.34112807005e-2f)) * zz +
cvector<float, N>(1.33387994085e-1f)) * zz +
cvector<float, N>(3.33331568548e-1f)) * zz * z + z,
z,
int_vector_type(x > cvector<float, N>(1e-4f))
);
auto r(select(
cvector<float, N>(-1.f) / y,
y,
int_vector_type(cvector<int_value_type, N>(0) <
(j & cvector<int_value_type, N>(2))))
);
(int_vector_type&)(r) ^= sign;
return {r};
}
template <unsigned N>
inline constexpr vector<float, N> cot(vector<float, N> xx) noexcept
{
using int_value_type = typename vector_traits<float, N>::int_value_type;
using int_vector_type = typename vector_traits<float, N>::int_vector_type;
auto& x(xx.ref());
auto& xi((int_vector_type&)(x));
auto sign(int_vector_type(x) & cvector<int_value_type, N>(1 << 31));
xi &= cvector<int_value_type, N>(~(1 << 31));
auto j(convert<int_value_type, N>(
cvector<float, N>(detail::constantsf::FOPI) * x));
j += j & cvector<int_value_type, N>(1);
auto y(convert<float, N>(j));
auto const z(((x - y * cvector<float, N>(detail::constantsf::DP1)) -
y * cvector<float, N>(detail::constantsf::DP2)) -
y * cvector<float, N>(detail::constantsf::DP3));
auto const zz(z * z);
y = select(
(((((cvector<float, N>(9.38540185543e-3f) * zz +
cvector<float, N>(3.11992232697e-3f)) * zz +
cvector<float, N>(2.44301354525e-2f)) * zz +
cvector<float, N>(5.34112807005e-2f)) * zz +
cvector<float, N>(1.33387994085e-1f)) * zz +
cvector<float, N>(3.33331568548e-1f)) * zz * z + z,
z,
int_vector_type(x > cvector<float, N>(1e-4f))
);
auto r(select(
-y,
cvector<float, N>(1.f) / y,
int_vector_type(cvector<int_value_type, N>(0) <
(j & cvector<int_value_type, N>(2))))
);
(int_vector_type&)(r) ^= sign;
return {r};
}
}
#endif // VXL_TANF_HPP