diff --git a/glm/detail/func_exponential.hpp b/glm/detail/func_exponential.hpp
index 5f016161..93820870 100644
--- a/glm/detail/func_exponential.hpp
+++ b/glm/detail/func_exponential.hpp
@@ -98,8 +98,8 @@ namespace glm
///
/// @see GLSL log2 man page
/// @see GLSL 4.20.8 specification, section 8.2 Exponential Functions
- template
- GLM_FUNC_DECL genType log2(genType const & x);
+ template
+ GLM_FUNC_DECL genType log2(genType x);
/// Returns the positive square root of x.
///
@@ -108,9 +108,12 @@ namespace glm
///
/// @see GLSL sqrt man page
/// @see GLSL 4.20.8 specification, section 8.2 Exponential Functions
- template
- GLM_FUNC_DECL genType sqrt(genType const & x);
+ //template
+ //GLM_FUNC_DECL genType sqrt(genType const & x);
+ template class vecType>
+ GLM_FUNC_DECL vecType sqrt(vecType const & x);
+
/// Returns the reciprocal of the positive square root of x.
///
/// @param x inversesqrt function is defined for input values of x defined in the range [0, inf+) in the limit of the type precision.
diff --git a/glm/detail/func_exponential.inl b/glm/detail/func_exponential.inl
index 805ce163..20fa45c9 100644
--- a/glm/detail/func_exponential.inl
+++ b/glm/detail/func_exponential.inl
@@ -158,21 +158,65 @@ namespace detail
VECTORIZE_VEC(log2)
- // sqrt
- template
- GLM_FUNC_QUALIFIER genType sqrt
- (
- genType const & x
- )
+ namespace detail
{
- GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'sqrt' only accept floating-point inputs");
-
- assert(x >= genType(0));
-
- return std::sqrt(x);
+ template class vecType, typename T, precision P>
+ struct compute_sqrt{};
+
+ template
+ struct compute_sqrt
+ {
+ static detail::tvec1 call(detail::tvec1 const & x)
+ {
+ return detail::tvec1(std::sqrt(x.x));
+ }
+ };
+
+ template
+ struct compute_sqrt
+ {
+ static detail::tvec2 call(detail::tvec2 const & x)
+ {
+ return detail::tvec2(std::sqrt(x.x), std::sqrt(x.y));
+ }
+ };
+
+ template
+ struct compute_sqrt
+ {
+ static detail::tvec3 call(detail::tvec3 const & x)
+ {
+ return detail::tvec3(std::sqrt(x.x), std::sqrt(x.y), std::sqrt(x.z));
+ }
+ };
+
+ template
+ struct compute_sqrt
+ {
+ static detail::tvec4 call(detail::tvec4 const & x)
+ {
+ return detail::tvec4(std::sqrt(x.x), std::sqrt(x.y), std::sqrt(x.z), std::sqrt(x.w));
+ }
+ };
+ }//namespace detail
+
+ // sqrt
+ GLM_FUNC_QUALIFIER float sqrt(float x)
+ {
+ return detail::compute_sqrt::call(x).x;
}
- VECTORIZE_VEC(sqrt)
+ GLM_FUNC_QUALIFIER double sqrt(double x)
+ {
+ return detail::compute_sqrt::call(x).x;
+ }
+
+ 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::call(x);
+ }
// inversesqrt
GLM_FUNC_QUALIFIER float inversesqrt(float const & x)