func_trigonometric.inl 5.3 KB

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