func_exponential.inl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  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:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  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
  21. /// THE SOFTWARE.
  22. ///
  23. /// @ref core
  24. /// @file glm/core/func_exponential.inl
  25. /// @date 2008-08-03 / 2011-06-15
  26. /// @author Christophe Riccio
  27. ///////////////////////////////////////////////////////////////////////////////////
  28. #include "_vectorize.hpp"
  29. namespace glm
  30. {
  31. // pow
  32. template <typename genType>
  33. GLM_FUNC_QUALIFIER genType pow
  34. (
  35. genType const & x,
  36. genType const & y
  37. )
  38. {
  39. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'pow' only accept floating-point input");
  40. return ::std::pow(x, y);
  41. }
  42. VECTORIZE_VEC_VEC(pow)
  43. // exp
  44. template <typename genType>
  45. GLM_FUNC_QUALIFIER genType exp
  46. (
  47. genType const & x
  48. )
  49. {
  50. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'exp' only accept floating-point input");
  51. return ::std::exp(x);
  52. }
  53. VECTORIZE_VEC(exp)
  54. // log
  55. template <typename genType>
  56. GLM_FUNC_QUALIFIER genType log
  57. (
  58. genType const & x
  59. )
  60. {
  61. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'log' only accept floating-point input");
  62. return ::std::log(x);
  63. }
  64. VECTORIZE_VEC(log)
  65. //exp2, ln2 = 0.69314718055994530941723212145818f
  66. template <typename genType>
  67. GLM_FUNC_QUALIFIER genType exp2
  68. (
  69. genType const & x
  70. )
  71. {
  72. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'exp2' only accept floating-point input");
  73. return ::std::exp(genType(0.69314718055994530941723212145818) * x);
  74. }
  75. VECTORIZE_VEC(exp2)
  76. namespace detail
  77. {
  78. template <int PATH = float_or_int_value::GLM_ERROR>
  79. struct compute_log2
  80. {
  81. template <typename T>
  82. T operator() (T const & Value) const
  83. {
  84. GLM_STATIC_ASSERT(0, "'log2' parameter has an invalid template parameter type. GLM core features only supports floating-point types, include <glm/gtx/integer.hpp> for integer types support. Others types are not supported.");
  85. return Value;
  86. }
  87. };
  88. template <>
  89. struct compute_log2<float_or_int_value::GLM_FLOAT>
  90. {
  91. template <typename T>
  92. T operator() (T const & Value) const
  93. {
  94. return ::std::log(Value) / T(0.69314718055994530941723212145818);
  95. }
  96. };
  97. }//namespace detail
  98. // log2, ln2 = 0.69314718055994530941723212145818f
  99. template <typename genType>
  100. GLM_FUNC_QUALIFIER genType log2
  101. (
  102. genType const & x
  103. )
  104. {
  105. assert(x > genType(0)); // log2 is only defined on the range (0, inf]
  106. return detail::compute_log2<detail::float_or_int_trait<genType>::ID>()(x);
  107. }
  108. VECTORIZE_VEC(log2)
  109. // sqrt
  110. template <typename genType>
  111. GLM_FUNC_QUALIFIER genType sqrt
  112. (
  113. genType const & x
  114. )
  115. {
  116. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sqrt' only accept floating-point input");
  117. return genType(::std::sqrt(x));
  118. }
  119. VECTORIZE_VEC(sqrt)
  120. template <typename genType>
  121. GLM_FUNC_QUALIFIER genType inversesqrt
  122. (
  123. genType const & x
  124. )
  125. {
  126. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'inversesqrt' only accept floating-point input");
  127. return genType(1) / ::std::sqrt(x);
  128. }
  129. VECTORIZE_VEC(inversesqrt)
  130. }//namespace glm