1
///////////////////////////////////////////////////////////////////////////////////
2
/// OpenGL Mathematics (glm.g-truc.net)
4
/// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
5
/// Permission is hereby granted, free of charge, to any person obtaining a copy
6
/// of this software and associated documentation files (the "Software"), to deal
7
/// in the Software without restriction, including without limitation the rights
8
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
/// copies of the Software, and to permit persons to whom the Software is
10
/// furnished to do so, subject to the following conditions:
12
/// The above copyright notice and this permission notice shall be included in
13
/// all copies or substantial portions of the Software.
15
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
/// @file glm/core/func_trigonometric.inl
25
/// @date 2008-08-03 / 2011-06-15
26
/// @author Christophe Riccio
27
///////////////////////////////////////////////////////////////////////////////////
29
#include "_vectorize.hpp"
34
template <typename genType>
35
GLM_FUNC_QUALIFIER genType radians
37
genType const & degrees
40
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'radians' only accept floating-point input");
42
genType const pi = genType(3.1415926535897932384626433832795);
43
return degrees * (pi / genType(180));
46
VECTORIZE_VEC(radians)
49
template <typename genType>
50
GLM_FUNC_QUALIFIER genType degrees
52
genType const & radians
55
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'degrees' only accept floating-point input");
57
const genType pi = genType(3.1415926535897932384626433832795);
58
return radians * (genType(180) / pi);
61
VECTORIZE_VEC(degrees)
64
template <typename genType>
65
GLM_FUNC_QUALIFIER genType sin
70
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sin' only accept floating-point input");
72
return ::std::sin(angle);
78
template <typename genType>
79
GLM_FUNC_QUALIFIER genType cos(genType const & angle)
81
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'cos' only accept floating-point input");
83
return ::std::cos(angle);
89
template <typename genType>
90
GLM_FUNC_QUALIFIER genType tan
95
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'tan' only accept floating-point input");
97
return ::std::tan(angle);
103
template <typename genType>
104
GLM_FUNC_QUALIFIER genType asin
109
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'asin' only accept floating-point input");
111
return ::std::asin(x);
117
template <typename genType>
118
GLM_FUNC_QUALIFIER genType acos
123
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'acos' only accept floating-point input");
125
return ::std::acos(x);
131
template <typename genType>
132
GLM_FUNC_QUALIFIER genType atan
138
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atan' only accept floating-point input");
140
return ::std::atan2(y, x);
143
VECTORIZE_VEC_VEC(atan)
145
template <typename genType>
146
GLM_FUNC_QUALIFIER genType atan
151
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atan' only accept floating-point input");
153
return ::std::atan(x);
159
template <typename genType>
160
GLM_FUNC_QUALIFIER genType sinh
162
genType const & angle
165
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sinh' only accept floating-point input");
167
return std::sinh(angle);
173
template <typename genType>
174
GLM_FUNC_QUALIFIER genType cosh
176
genType const & angle
179
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'cosh' only accept floating-point input");
181
return std::cosh(angle);
187
template <typename genType>
188
GLM_FUNC_QUALIFIER genType tanh
190
genType const & angle
193
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'tanh' only accept floating-point input");
195
return std::tanh(angle);
201
template <typename genType>
202
GLM_FUNC_QUALIFIER genType asinh
207
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'asinh' only accept floating-point input");
209
return (x < genType(0) ? genType(-1) : (x > genType(0) ? genType(1) : genType(0))) * log(abs(x) + sqrt(genType(1) + x * x));
215
template <typename genType>
216
GLM_FUNC_QUALIFIER genType acosh
221
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'acosh' only accept floating-point input");
225
return log(x + sqrt(x * x - genType(1)));
231
template <typename genType>
232
GLM_FUNC_QUALIFIER genType atanh
237
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atanh' only accept floating-point input");
239
if(abs(x) >= genType(1))
241
return genType(0.5) * log((genType(1) + x) / (genType(1) - x));