1/// @ref core
2/// @file glm/detail/func_trigonometric.inl
3
4#include "_vectorize.hpp"
5#include <cmath>
6#include <limits>
7
8namespace glm
9{
10	// radians
11	template <typename genType>
12	GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType radians(genType degrees)
13	{
14		GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'radians' only accept floating-point input");
15
16		return degrees * static_cast<genType>(0.01745329251994329576923690768489);
17	}
18
19	template <typename T, precision P, template <typename, precision> class vecType>
20	GLM_FUNC_QUALIFIER GLM_CONSTEXPR vecType<T, P> radians(vecType<T, P> const & v)
21	{
22		return detail::functor1<T, T, P, vecType>::call(radians, v);
23	}
24
25	// degrees
26	template <typename genType>
27	GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType degrees(genType radians)
28	{
29		GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'degrees' only accept floating-point input");
30
31		return radians * static_cast<genType>(57.295779513082320876798154814105);
32	}
33
34	template <typename T, precision P, template <typename, precision> class vecType>
35	GLM_FUNC_QUALIFIER GLM_CONSTEXPR vecType<T, P> degrees(vecType<T, P> const & v)
36	{
37		return detail::functor1<T, T, P, vecType>::call(degrees, v);
38	}
39
40	// sin
41	using ::std::sin;
42
43	template <typename T, precision P, template <typename, precision> class vecType>
44	GLM_FUNC_QUALIFIER vecType<T, P> sin(vecType<T, P> const & v)
45	{
46		return detail::functor1<T, T, P, vecType>::call(sin, v);
47	}
48
49	// cos
50	using std::cos;
51
52	template <typename T, precision P, template <typename, precision> class vecType>
53	GLM_FUNC_QUALIFIER vecType<T, P> cos(vecType<T, P> const & v)
54	{
55		return detail::functor1<T, T, P, vecType>::call(cos, v);
56	}
57
58	// tan
59	using std::tan;
60
61	template <typename T, precision P, template <typename, precision> class vecType>
62	GLM_FUNC_QUALIFIER vecType<T, P> tan(vecType<T, P> const & v)
63	{
64		return detail::functor1<T, T, P, vecType>::call(tan, v);
65	}
66
67	// asin
68	using std::asin;
69
70	template <typename T, precision P, template <typename, precision> class vecType>
71	GLM_FUNC_QUALIFIER vecType<T, P> asin(vecType<T, P> const & v)
72	{
73		return detail::functor1<T, T, P, vecType>::call(asin, v);
74	}
75
76	// acos
77	using std::acos;
78
79	template <typename T, precision P, template <typename, precision> class vecType>
80	GLM_FUNC_QUALIFIER vecType<T, P> acos(vecType<T, P> const & v)
81	{
82		return detail::functor1<T, T, P, vecType>::call(acos, v);
83	}
84
85	// atan
86	template <typename genType>
87	GLM_FUNC_QUALIFIER genType atan(genType y, genType x)
88	{
89		GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'atan' only accept floating-point input");
90
91		return ::std::atan2(y, x);
92	}
93
94	template <typename T, precision P, template <typename, precision> class vecType>
95	GLM_FUNC_QUALIFIER vecType<T, P> atan(vecType<T, P> const & a, vecType<T, P> const & b)
96	{
97		return detail::functor2<T, P, vecType>::call(::std::atan2, a, b);
98	}
99
100	using std::atan;
101
102	template <typename T, precision P, template <typename, precision> class vecType>
103	GLM_FUNC_QUALIFIER vecType<T, P> atan(vecType<T, P> const & v)
104	{
105		return detail::functor1<T, T, P, vecType>::call(atan, v);
106	}
107
108	// sinh
109	using std::sinh;
110
111	template <typename T, precision P, template <typename, precision> class vecType>
112	GLM_FUNC_QUALIFIER vecType<T, P> sinh(vecType<T, P> const & v)
113	{
114		return detail::functor1<T, T, P, vecType>::call(sinh, v);
115	}
116
117	// cosh
118	using std::cosh;
119
120	template <typename T, precision P, template <typename, precision> class vecType>
121	GLM_FUNC_QUALIFIER vecType<T, P> cosh(vecType<T, P> const & v)
122	{
123		return detail::functor1<T, T, P, vecType>::call(cosh, v);
124	}
125
126	// tanh
127	using std::tanh;
128
129	template <typename T, precision P, template <typename, precision> class vecType>
130	GLM_FUNC_QUALIFIER vecType<T, P> tanh(vecType<T, P> const & v)
131	{
132		return detail::functor1<T, T, P, vecType>::call(tanh, v);
133	}
134
135	// asinh
136#	if GLM_HAS_CXX11_STL
137		using std::asinh;
138#	else
139		template <typename genType>
140		GLM_FUNC_QUALIFIER genType asinh(genType x)
141		{
142			GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'asinh' only accept floating-point input");
143
144			return (x < static_cast<genType>(0) ? static_cast<genType>(-1) : (x > static_cast<genType>(0) ? static_cast<genType>(1) : static_cast<genType>(0))) * log(std::abs(x) + sqrt(static_cast<genType>(1) + x * x));
145		}
146#	endif
147
148	template <typename T, precision P, template <typename, precision> class vecType>
149	GLM_FUNC_QUALIFIER vecType<T, P> asinh(vecType<T, P> const & v)
150	{
151		return detail::functor1<T, T, P, vecType>::call(asinh, v);
152	}
153
154	// acosh
155#	if GLM_HAS_CXX11_STL
156		using std::acosh;
157#	else
158		template <typename genType>
159		GLM_FUNC_QUALIFIER genType acosh(genType x)
160		{
161			GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'acosh' only accept floating-point input");
162
163			if(x < static_cast<genType>(1))
164				return static_cast<genType>(0);
165			return log(x + sqrt(x * x - static_cast<genType>(1)));
166		}
167#	endif
168
169	template <typename T, precision P, template <typename, precision> class vecType>
170	GLM_FUNC_QUALIFIER vecType<T, P> acosh(vecType<T, P> const & v)
171	{
172		return detail::functor1<T, T, P, vecType>::call(acosh, v);
173	}
174
175	// atanh
176#	if GLM_HAS_CXX11_STL
177		using std::atanh;
178#	else
179		template <typename genType>
180		GLM_FUNC_QUALIFIER genType atanh(genType x)
181		{
182			GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'atanh' only accept floating-point input");
183
184			if(std::abs(x) >= static_cast<genType>(1))
185				return 0;
186			return static_cast<genType>(0.5) * log((static_cast<genType>(1) + x) / (static_cast<genType>(1) - x));
187		}
188#	endif
189
190	template <typename T, precision P, template <typename, precision> class vecType>
191	GLM_FUNC_QUALIFIER vecType<T, P> atanh(vecType<T, P> const & v)
192	{
193		return detail::functor1<T, T, P, vecType>::call(atanh, v);
194	}
195}//namespace glm
196
197#if GLM_ARCH != GLM_ARCH_PURE && GLM_HAS_UNRESTRICTED_UNIONS
198#	include "func_trigonometric_simd.inl"
199#endif
200
201