fcomp: Fix build in C++98 mode

This commit is contained in:
Christophe 2024-02-06 16:24:25 +01:00 committed by Christophe
parent c9ca4dc77c
commit 4eb3fe1d7d
2 changed files with 16 additions and 8 deletions

View File

@ -1,5 +1,6 @@
/// @ref gtx_component_wise /// @ref gtx_component_wise
#include "../ext/scalar_common.hpp"
#include <limits> #include <limits>
#include <cmath> #include <cmath>
@ -126,21 +127,21 @@ namespace detail
return Result; return Result;
} }
template<length_t L, typename T, qualifier Q, typename = typename std::enable_if<std::is_floating_point<T>::value, T>::type> template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER T fcompMin(vec<L, T, Q> const& v) GLM_FUNC_QUALIFIER T fcompMin(vec<L, T, Q> const& v)
{ {
T Result(v[0]); T Result(v[0]);
for(length_t i = 1, n = v.length(); i < n; ++i) for(length_t i = 1, n = v.length(); i < n; ++i)
Result = std::fmin(Result, v[i]); Result = fmin(Result, v[i]);
return Result; return Result;
} }
template<length_t L, typename T, qualifier Q, typename = typename std::enable_if<std::is_floating_point<T>::value, T>::type> template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER T fcompMax(vec<L, T, Q> const& v) GLM_FUNC_QUALIFIER T fcompMax(vec<L, T, Q> const& v)
{ {
T Result(v[0]); T Result(v[0]);
for(length_t i = 1, n = v.length(); i < n; ++i) for(length_t i = 1, n = v.length(); i < n; ++i)
Result = std::fmax(Result, v[i]); Result = fmax(Result, v[i]);
return Result; return Result;
} }
}//namespace glm }//namespace glm

View File

@ -3,6 +3,8 @@
#include <glm/gtc/type_precision.hpp> #include <glm/gtc/type_precision.hpp>
#include <glm/gtc/epsilon.hpp> #include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp> #include <glm/gtc/constants.hpp>
#include <glm/ext/scalar_relational.hpp>
#include <glm/ext/scalar_constants.hpp>
#include <limits> #include <limits>
namespace compNormalize namespace compNormalize
@ -105,6 +107,7 @@ namespace compScale
} }
}// compScale }// compScale
#if ((GLM_LANG & GLM_LANG_CXX11_FLAG) || (GLM_COMPILER & GLM_COMPILER_VC))
namespace fcompMax namespace fcompMax
{ {
static int run() static int run()
@ -114,13 +117,13 @@ namespace fcompMax
{ {
float const A = glm::fcompMax(glm::vec4(NAN, 0.2f, 0.5f, 1.0f)); float const A = glm::fcompMax(glm::vec4(NAN, 0.2f, 0.5f, 1.0f));
Error += A == 1.0f ? 0 : 1; Error += glm::equal(A, 1.0f, glm::epsilon<float>()) ? 0 : 1;
} }
{ {
float const A = glm::fcompMax(glm::vec4(2.0f, NAN, 0.3f, 0.7f)); float const A = glm::fcompMax(glm::vec4(2.0f, NAN, 0.3f, 0.7f));
Error += A == 2.0f ? 0 : 1; Error += glm::equal(A, 2.0f, glm::epsilon<float>()) ? 0 : 1;
} }
{ {
@ -142,13 +145,13 @@ namespace fcompMin
{ {
float const A = glm::fcompMin(glm::vec4(NAN, 0.2f, 0.5f, 1.0f)); float const A = glm::fcompMin(glm::vec4(NAN, 0.2f, 0.5f, 1.0f));
Error += A == 0.2f ? 0 : 1; Error += glm::equal(A, 0.2f, glm::epsilon<float>()) ? 0 : 1;
} }
{ {
float const A = glm::fcompMin(glm::vec4(2.0f, NAN, 0.3f, 0.7f)); float const A = glm::fcompMin(glm::vec4(2.0f, NAN, 0.3f, 0.7f));
Error += A == 0.3f ? 0 : 1; Error += glm::equal(A, 0.3f, glm::epsilon<float>()) ? 0 : 1;
} }
{ {
@ -161,6 +164,7 @@ namespace fcompMin
return Error; return Error;
} }
}// fcompMin }// fcompMin
#endif//((GLM_LANG & GLM_LANG_CXX11_FLAG) || (GLM_COMPILER & GLM_COMPILER_VC))
int main() int main()
{ {
@ -168,8 +172,11 @@ int main()
Error += compNormalize::run(); Error += compNormalize::run();
Error += compScale::run(); Error += compScale::run();
#if ((GLM_LANG & GLM_LANG_CXX11_FLAG) || (GLM_COMPILER & GLM_COMPILER_VC))
Error += fcompMax::run(); Error += fcompMax::run();
Error += fcompMin::run(); Error += fcompMin::run();
#endif//((GLM_LANG & GLM_LANG_CXX11_FLAG) || (GLM_COMPILER & GLM_COMPILER_VC))
return Error; return Error;
} }