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