Fixed sqrt ambiguity

master
Christophe Riccio ago%!(EXTRA string=11 years)
parent 31ec3eed97
commit 7ce6df4078
  1. 11
      glm/detail/func_exponential.hpp
  2. 66
      glm/detail/func_exponential.inl

@ -98,8 +98,8 @@ namespace glm
/// ///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/log2.xml">GLSL log2 man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/log2.xml">GLSL log2 man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
template <typename genType> template <typename genType>
GLM_FUNC_DECL genType log2(genType const & x); GLM_FUNC_DECL genType log2(genType x);
/// Returns the positive square root of x. /// Returns the positive square root of x.
/// ///
@ -108,9 +108,12 @@ namespace glm
/// ///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/sqrt.xml">GLSL sqrt man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/sqrt.xml">GLSL sqrt man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
template <typename genType> //template <typename genType>
GLM_FUNC_DECL genType sqrt(genType const & x); //GLM_FUNC_DECL genType sqrt(genType const & x);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> sqrt(vecType<T, P> const & x);
/// Returns the reciprocal of the positive square root of 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. /// @param x inversesqrt function is defined for input values of x defined in the range [0, inf+) in the limit of the type precision.

@ -158,21 +158,65 @@ namespace detail
VECTORIZE_VEC(log2) VECTORIZE_VEC(log2)
namespace detail
{
template <template <class, precision> class vecType, typename T, precision P>
struct compute_sqrt{};
template <typename T, precision P>
struct compute_sqrt<detail::tvec1, T, P>
{
static detail::tvec1<T, P> call(detail::tvec1<T, P> const & x)
{
return detail::tvec1<T, P>(std::sqrt(x.x));
}
};
template <typename T, precision P>
struct compute_sqrt<detail::tvec2, T, P>
{
static detail::tvec2<T, P> call(detail::tvec2<T, P> const & x)
{
return detail::tvec2<T, P>(std::sqrt(x.x), std::sqrt(x.y));
}
};
template <typename T, precision P>
struct compute_sqrt<detail::tvec3, T, P>
{
static detail::tvec3<T, P> call(detail::tvec3<T, P> const & x)
{
return detail::tvec3<T, P>(std::sqrt(x.x), std::sqrt(x.y), std::sqrt(x.z));
}
};
template <typename T, precision P>
struct compute_sqrt<detail::tvec4, T, P>
{
static detail::tvec4<T, P> call(detail::tvec4<T, P> const & x)
{
return detail::tvec4<T, P>(std::sqrt(x.x), std::sqrt(x.y), std::sqrt(x.z), std::sqrt(x.w));
}
};
}//namespace detail
// sqrt // sqrt
template <typename genType> GLM_FUNC_QUALIFIER float sqrt(float x)
GLM_FUNC_QUALIFIER genType sqrt
(
genType const & x
)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'sqrt' only accept floating-point inputs"); return detail::compute_sqrt<detail::tvec1, float, highp>::call(x).x;
assert(x >= genType(0));
return std::sqrt(x);
} }
VECTORIZE_VEC(sqrt) GLM_FUNC_QUALIFIER double sqrt(double x)
{
return detail::compute_sqrt<detail::tvec1, double, highp>::call(x).x;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> sqrt(vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'sqrt' only accept floating-point inputs");
return detail::compute_sqrt<vecType, T, P>::call(x);
}
// inversesqrt // inversesqrt
GLM_FUNC_QUALIFIER float inversesqrt(float const & x) GLM_FUNC_QUALIFIER float inversesqrt(float const & x)

Loading…
Cancel
Save