Fixed sqrt ambiguity

This commit is contained in:
Christophe Riccio 2014-02-08 20:21:24 +01:00
parent 31ec3eed97
commit 7ce6df4078
2 changed files with 63 additions and 16 deletions

View File

@ -99,7 +99,7 @@ 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/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
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.
///
@ -108,8 +108,11 @@ 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/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.2 Exponential Functions</a>
template <typename genType>
GLM_FUNC_DECL genType sqrt(genType const & x);
//template <typename genType>
//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.
///

View File

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