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.

156 lines
4.1 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2013 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. namespace glm
  29. {
  30. // pow
  31. template <typename genType>
  32. GLM_FUNC_QUALIFIER genType pow
  33. (
  34. genType const & x,
  35. genType const & y
  36. )
  37. {
  38. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'pow' only accept floating-point input");
  39. return genType(::std::pow(x, y));
  40. }
  41. VECTORIZE_VEC_VEC(pow)
  42. // exp
  43. template <typename genType>
  44. GLM_FUNC_QUALIFIER genType exp
  45. (
  46. genType const & x
  47. )
  48. {
  49. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'exp' only accept floating-point input");
  50. return genType(::std::exp(x));
  51. }
  52. VECTORIZE_VEC(exp)
  53. // log
  54. template <typename genType>
  55. GLM_FUNC_QUALIFIER genType log
  56. (
  57. genType const & x
  58. )
  59. {
  60. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'log' only accept floating-point input");
  61. return genType(::std::log(x));
  62. }
  63. VECTORIZE_VEC(log)
  64. //exp2, ln2 = 0.69314718055994530941723212145818f
  65. template <typename genType>
  66. GLM_FUNC_QUALIFIER genType exp2
  67. (
  68. genType const & x
  69. )
  70. {
  71. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'exp2' only accept floating-point input");
  72. return genType(::std::exp(genType(0.69314718055994530941723212145818) * x));
  73. }
  74. VECTORIZE_VEC(exp2)
  75. namespace _detail
  76. {
  77. template <int _PATH = detail::float_or_int_value::GLM_ERROR>
  78. struct _compute_log2
  79. {
  80. template <typename T>
  81. T operator() (T const & Value) const;
  82. /*
  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. };
  89. template <>
  90. struct _compute_log2<detail::float_or_int_value::GLM_FLOAT>
  91. {
  92. template <typename T>
  93. T operator() (T const & Value) const
  94. {
  95. return T(::std::log(Value)) / T(0.69314718055994530941723212145818);
  96. }
  97. };
  98. }//namespace _detail
  99. // log2, ln2 = 0.69314718055994530941723212145818f
  100. template <typename genType>
  101. GLM_FUNC_QUALIFIER genType log2
  102. (
  103. genType const & x
  104. )
  105. {
  106. assert(x > genType(0)); // log2 is only defined on the range (0, inf]
  107. return _detail::_compute_log2<detail::float_or_int_trait<genType>::ID>()(x);
  108. }
  109. VECTORIZE_VEC(log2)
  110. // sqrt
  111. template <typename genType>
  112. GLM_FUNC_QUALIFIER genType sqrt
  113. (
  114. genType const & x
  115. )
  116. {
  117. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sqrt' only accept floating-point input");
  118. return genType(::std::sqrt(x));
  119. }
  120. VECTORIZE_VEC(sqrt)
  121. template <typename genType>
  122. GLM_FUNC_QUALIFIER genType inversesqrt
  123. (
  124. genType const & x
  125. )
  126. {
  127. GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'inversesqrt' only accept floating-point input");
  128. assert(x > genType(0));
  129. return genType(1) / ::std::sqrt(x);
  130. }
  131. VECTORIZE_VEC(inversesqrt)
  132. }//namespace glm