Skip to content

Commit

Permalink
fcomp: Fix build in C++98 mode
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Feb 7, 2024
1 parent c9ca4dc commit 4eb3fe1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
9 changes: 5 additions & 4 deletions glm/gtx/component_wise.inl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// @ref gtx_component_wise

#include "../ext/scalar_common.hpp"
#include <limits>
#include <cmath>

Expand Down Expand Up @@ -126,21 +127,21 @@ namespace detail
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)
{
T Result(v[0]);
for(length_t i = 1, n = v.length(); i < n; ++i)
Result = std::fmin(Result, v[i]);
Result = fmin(Result, v[i]);
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)
{
T Result(v[0]);
for(length_t i = 1, n = v.length(); i < n; ++i)
Result = std::fmax(Result, v[i]);
Result = fmax(Result, v[i]);
return Result;
}
}//namespace glm
15 changes: 11 additions & 4 deletions test/gtx/gtx_component_wise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <glm/gtc/type_precision.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/ext/scalar_relational.hpp>
#include <glm/ext/scalar_constants.hpp>
#include <limits>

namespace compNormalize
Expand Down Expand Up @@ -105,6 +107,7 @@ namespace compScale
}
}// compScale

#if ((GLM_LANG & GLM_LANG_CXX11_FLAG) || (GLM_COMPILER & GLM_COMPILER_VC))
namespace fcompMax
{
static int run()
Expand All @@ -114,13 +117,13 @@ namespace fcompMax
{
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));

Error += A == 2.0f ? 0 : 1;
Error += glm::equal(A, 2.0f, glm::epsilon<float>()) ? 0 : 1;
}

{
Expand All @@ -142,13 +145,13 @@ namespace fcompMin
{
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));

Error += A == 0.3f ? 0 : 1;
Error += glm::equal(A, 0.3f, glm::epsilon<float>()) ? 0 : 1;
}

{
Expand All @@ -161,15 +164,19 @@ namespace fcompMin
return Error;
}
}// fcompMin
#endif//((GLM_LANG & GLM_LANG_CXX11_FLAG) || (GLM_COMPILER & GLM_COMPILER_VC))

int main()
{
int Error(0);

Error += compNormalize::run();
Error += compScale::run();

#if ((GLM_LANG & GLM_LANG_CXX11_FLAG) || (GLM_COMPILER & GLM_COMPILER_VC))
Error += fcompMax::run();
Error += fcompMin::run();
#endif//((GLM_LANG & GLM_LANG_CXX11_FLAG) || (GLM_COMPILER & GLM_COMPILER_VC))

return Error;
}

0 comments on commit 4eb3fe1

Please sign in to comment.