/// @ref core /// @file glm/detail/func_exponential.inl #include "func_vector_relational.hpp" #include "_vectorize.hpp" #include #include #include namespace glm{ namespace detail { # if GLM_HAS_CXX11_STL using std::log2; # else template genType log2(genType Value) { return std::log(Value) * static_cast(1.4426950408889634073599246810019); } # endif template class vecType, bool isFloat, bool Aligned> struct compute_log2 { GLM_FUNC_QUALIFIER static vec call(vec const& v) { return detail::functor1::call(log2, v); } }; template struct compute_sqrt { GLM_FUNC_QUALIFIER static vec call(vec const& x) { return detail::functor1::call(std::sqrt, x); } }; template struct compute_inversesqrt { GLM_FUNC_QUALIFIER static vec call(vec const & x) { return static_cast(1) / sqrt(x); } }; template struct compute_inversesqrt { GLM_FUNC_QUALIFIER static vec call(vec const & x) { vec tmp(x); vec xhalf(tmp * 0.5f); vec* p = reinterpret_cast*>(const_cast*>(&x)); vec i = vec(0x5f375a86) - (*p >> vec(1)); vec* ptmp = reinterpret_cast*>(&i); tmp = *ptmp; tmp = tmp * (1.5f - xhalf * tmp * tmp); return tmp; } }; }//namespace detail // pow using std::pow; template class vecType> GLM_FUNC_QUALIFIER vecType pow(vecType const & base, vecType const& exponent) { return detail::functor2::call(pow, base, exponent); } // exp using std::exp; template class vecType> GLM_FUNC_QUALIFIER vecType exp(vecType const& x) { return detail::functor1::call(exp, x); } // log using std::log; template class vecType> GLM_FUNC_QUALIFIER vecType log(vecType const& x) { return detail::functor1::call(log, x); } //exp2, ln2 = 0.69314718055994530941723212145818f template GLM_FUNC_QUALIFIER genType exp2(genType x) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'exp2' only accept floating-point inputs"); return std::exp(static_cast(0.69314718055994530941723212145818) * x); } template class vecType> GLM_FUNC_QUALIFIER vecType exp2(vecType const& x) { return detail::functor1::call(exp2, x); } // log2, ln2 = 0.69314718055994530941723212145818f template GLM_FUNC_QUALIFIER genType log2(genType x) { return log2(vec<1, genType>(x)).x; } template class vecType> GLM_FUNC_QUALIFIER vecType log2(vecType const& x) { return detail::compute_log2::is_iec559, detail::is_aligned

::value>::call(x); } // sqrt using std::sqrt; template class vecType> GLM_FUNC_QUALIFIER vecType sqrt(vecType const& x) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'sqrt' only accept floating-point inputs"); return detail::compute_sqrt::value>::call(x); } // inversesqrt template GLM_FUNC_QUALIFIER genType inversesqrt(genType x) { return static_cast(1) / sqrt(x); } template class vecType> GLM_FUNC_QUALIFIER vecType inversesqrt(vecType const& x) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'inversesqrt' only accept floating-point inputs"); return detail::compute_inversesqrt::value>::call(x); } }//namespace glm #if GLM_ARCH != GLM_ARCH_PURE && GLM_HAS_UNRESTRICTED_UNIONS # include "func_exponential_simd.inl" #endif