Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
5.1KB

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