diff --git a/glm/detail/func_exponential.inl b/glm/detail/func_exponential.inl index 2040d41f..96407832 100644 --- a/glm/detail/func_exponential.inl +++ b/glm/detail/func_exponential.inl @@ -7,6 +7,12 @@ #include #include +// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. +#if GLM_ENABLE_CONSTEXPR_MATH == GLM_ENABLE +# include +#endif +// END @MEWIN + namespace glm{ namespace detail { @@ -34,10 +40,12 @@ namespace detail template struct compute_sqrt { - GLM_FUNC_QUALIFIER static vec call(vec const& x) + // BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. + GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR static vec call(vec const& x) { - return detail::functor1::call(std::sqrt, x); + return detail::functor1::call(GLM_MATH_BASE_NS::sqrt, x); } + // END @MEWIN }; template @@ -123,9 +131,13 @@ namespace detail } // sqrt - using std::sqrt; + // BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. + using GLM_MATH_BASE_NS::sqrt; + // END @MEWIN template - GLM_FUNC_QUALIFIER vec sqrt(vec const& x) + // BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. + GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR vec sqrt(vec const& x) + // END @MEWIN { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'sqrt' only accept floating-point inputs"); return detail::compute_sqrt::value>::call(x); diff --git a/glm/detail/func_geometric.inl b/glm/detail/func_geometric.inl index 404c9905..b0c3765e 100644 --- a/glm/detail/func_geometric.inl +++ b/glm/detail/func_geometric.inl @@ -7,7 +7,9 @@ namespace detail template struct compute_length { - GLM_FUNC_QUALIFIER static T call(vec const& v) + // BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. + GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR static T call(vec const& v) + // END @MEWIN { return sqrt(dot(v, v)); } @@ -16,7 +18,9 @@ namespace detail template struct compute_distance { - GLM_FUNC_QUALIFIER static T call(vec const& p0, vec const& p1) + // BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. + GLM_FUNC_QUALIFIER static GLM_MATH_CONSTEXPR T call(vec const& p0, vec const& p1) + // END @MEWIN { return length(p1 - p0); } @@ -125,7 +129,9 @@ namespace detail // length template - GLM_FUNC_QUALIFIER genType length(genType x) + // BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. + GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR genType length(genType x) + // END @MEWIN { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'length' accepts only floating-point inputs"); @@ -133,7 +139,9 @@ namespace detail } template - GLM_FUNC_QUALIFIER T length(vec const& v) + // BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. + GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR T length(vec const& v) + // END @MEWIN { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'length' accepts only floating-point inputs"); @@ -142,7 +150,9 @@ namespace detail // distance template - GLM_FUNC_QUALIFIER genType distance(genType const& p0, genType const& p1) + // BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. + GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR genType distance(genType const& p0, genType const& p1) + // END @MEWIN { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'distance' accepts only floating-point inputs"); @@ -150,7 +160,9 @@ namespace detail } template - GLM_FUNC_QUALIFIER T distance(vec const& p0, vec const& p1) + // BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. + GLM_FUNC_QUALIFIER GLM_MATH_CONSTEXPR T distance(vec const& p0, vec const& p1) + // END @MEWIN { return detail::compute_distance::value>::call(p0, p1); } diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index 77b1add3..fb82c209 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -308,7 +308,26 @@ # define GLM_CONSTEXPR #endif +// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. +#if !defined(GLM_ENABLE_CONSTEXPR_MATH) +# if (GLM_LANG & GLM_LANG_CXX17_FLAG) +# define GLM_ENABLE_CONSTEXPR_MATH __has_include() +# else +# define GLM_ENABLE_CONSTEXPR_MATH 0 +# endif +#endif + +#if GLM_ENABLE_CONSTEXPR_MATH == GLM_ENABLE +# define GLM_MATH_CONSTEXPR GLM_CONSTEXPR +# define GLM_MATH_BASE_NS gcem +#else +# define GLM_MATH_CONSTEXPR GLM_INLINE +# define GLM_MATH_BASE_NS std +#endif + +// END @MEWIN // + #if GLM_HAS_CONSTEXPR # if (GLM_COMPILER & GLM_COMPILER_CLANG) # if __has_feature(cxx_if_constexpr) diff --git a/glm/exponential.hpp b/glm/exponential.hpp index 1614f769..d8eae59a 100644 --- a/glm/exponential.hpp +++ b/glm/exponential.hpp @@ -20,6 +20,12 @@ #include "detail/type_vec4.hpp" #include +// BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. +#if GLM_ENABLE_CONSTEXPR_MATH == GLM_ENABLE +# include +#endif +// END @MEWIN + namespace glm { /// @addtogroup core_func_exponential @@ -91,7 +97,9 @@ namespace glm /// @see GLSL sqrt man page /// @see GLSL 4.20.8 specification, section 8.2 Exponential Functions template - GLM_FUNC_DECL vec sqrt(vec const& v); + // BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. + GLM_FUNC_DECL GLM_MATH_CONSTEXPR vec sqrt(vec const& v); + // END @MEWIN /// Returns the reciprocal of the positive square root of v. /// diff --git a/glm/geometric.hpp b/glm/geometric.hpp index ac857e69..86e9e020 100644 --- a/glm/geometric.hpp +++ b/glm/geometric.hpp @@ -27,7 +27,9 @@ namespace glm /// @see GLSL length man page /// @see GLSL 4.20.8 specification, section 8.5 Geometric Functions template - GLM_FUNC_DECL T length(vec const& x); + // BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. + GLM_FUNC_DECL GLM_MATH_CONSTEXPR T length(vec const& x); + // END @MEWIN /// Returns the distance between p0 and p1, i.e., length(p0 - p1). /// @@ -37,7 +39,9 @@ namespace glm /// @see GLSL distance man page /// @see GLSL 4.20.8 specification, section 8.5 Geometric Functions template - GLM_FUNC_DECL T distance(vec const& p0, vec const& p1); + // BEGIN @MEWIN - 2023-01-12 - Made some math functions constexpr using gcem. + GLM_FUNC_DECL GLM_MATH_CONSTEXPR T distance(vec const& p0, vec const& p1); + // END @MEWIN /// Returns the dot product of x and y, i.e., result = x * y. /// diff --git a/glm/gtx/spaceship.hpp b/glm/gtx/spaceship.hpp index c5d073cf..eb0b50d9 100644 --- a/glm/gtx/spaceship.hpp +++ b/glm/gtx/spaceship.hpp @@ -1,3 +1,4 @@ +// @MEWIN - 2023-01-02 - Added support for spaceship operator. #pragma once