From ec513f44662c75f57314780c4737547c27d2fae1 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 7 Sep 2014 20:53:35 +0200 Subject: [PATCH] Added GTX_common with isdenomal #223 --- glm/gtx/common.hpp | 70 ++++++++++++++++++++++++++++ glm/gtx/common.inl | 98 +++++++++++++++++++++++++++++++++++++++ glm/gtx/compatibility.hpp | 2 +- readme.txt | 9 ++-- test/gtx/CMakeLists.txt | 1 + test/gtx/gtx_common.cpp | 33 +++++++++++++ 6 files changed, 208 insertions(+), 5 deletions(-) create mode 100644 glm/gtx/common.hpp create mode 100644 glm/gtx/common.inl create mode 100644 test/gtx/gtx_common.cpp diff --git a/glm/gtx/common.hpp b/glm/gtx/common.hpp new file mode 100644 index 00000000..da035553 --- /dev/null +++ b/glm/gtx/common.hpp @@ -0,0 +1,70 @@ +/////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @ref gtx_common +/// @file glm/gtx/common.hpp +/// @date 2014-09-08 / 2014-09-08 +/// @author Christophe Riccio +/// +/// @see core (dependence) +/// @see gtc_half_float (dependence) +/// +/// @defgroup gtx_common GLM_GTX_common +/// @ingroup gtx +/// +/// @brief Provide functions to increase the compatibility with Cg and HLSL languages +/// +/// need to be included to use these functionalities. +/////////////////////////////////////////////////////////////////////////////////// + +#pragma once + +// Dependencies: +#include "../vec2.hpp" +#include "../vec3.hpp" +#include "../vec4.hpp" +#include "../gtx/vec1.hpp" + +#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED)) +# pragma message("GLM: GLM_GTX_common extension included") +#endif + +namespace glm +{ + /// @addtogroup gtx_common + /// @{ + + /// Returns true if x is a denormalized number + /// Numbers whose absolute value is too small to be represented in the normal format are represented in an alternate, denormalized format. + /// This format is less precise but can represent values closer to zero. + /// + /// @tparam genType Floating-point scalar or vector types. + /// + /// @see GLSL isnan man page + /// @see GLSL 4.20.8 specification, section 8.3 Common Functions + template + GLM_FUNC_DECL typename genType::bool_type isdenormal(genType const & x); + + /// @} +}//namespace glm + +#include "common.inl" diff --git a/glm/gtx/common.inl b/glm/gtx/common.inl new file mode 100644 index 00000000..c493b350 --- /dev/null +++ b/glm/gtx/common.inl @@ -0,0 +1,98 @@ +/////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @ref gtx_common +/// @file glm/gtx/common.inl +/// @date 2014-09-08 / 2014-09-08 +/// @author Christophe Riccio +/////////////////////////////////////////////////////////////////////////////////// + +#include + +namespace glm +{ + template + GLM_FUNC_QUALIFIER bool isdenormal(T const & x) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'isdenormal' only accept floating-point inputs"); + +# if(GLM_LANG & GLM_LANG_CXX11_FLAG) + return std::fpclassify(x) == FP_SUBNORMAL; +# else + return x != static_cast(0) && std::fabs(x) < std::numeric_limits::min(); +# endif + } + + template + GLM_FUNC_QUALIFIER typename detail::tvec1::bool_type isdenormal + ( + detail::tvec1 const & x + ) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'isdenormal' only accept floating-point inputs"); + + return typename detail::tvec1::bool_type( + isdenormal(x.x)); + } + + template + GLM_FUNC_QUALIFIER typename detail::tvec2::bool_type isdenormal + ( + detail::tvec2 const & x + ) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'isdenormal' only accept floating-point inputs"); + + return typename detail::tvec2::bool_type( + isdenormal(x.x), + isdenormal(x.y)); + } + + template + GLM_FUNC_QUALIFIER typename detail::tvec3::bool_type isdenormal + ( + detail::tvec3 const & x + ) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'isdenormal' only accept floating-point inputs"); + + return typename detail::tvec3::bool_type( + isdenormal(x.x), + isdenormal(x.y), + isdenormal(x.z)); + } + + template + GLM_FUNC_QUALIFIER typename detail::tvec4::bool_type isdenormal + ( + detail::tvec4 const & x + ) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'isdenormal' only accept floating-point inputs"); + + return typename detail::tvec4::bool_type( + isdenormal(x.x), + isdenormal(x.y), + isdenormal(x.z), + isdenormal(x.w)); + } +}//namespace glm diff --git a/glm/gtx/compatibility.hpp b/glm/gtx/compatibility.hpp index 3435405d..2f36ed35 100644 --- a/glm/gtx/compatibility.hpp +++ b/glm/gtx/compatibility.hpp @@ -39,7 +39,7 @@ #pragma once // Dependency: -#include "../glm.hpp" +#include "../glm.hpp" #include "../gtc/quaternion.hpp" #if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED)) diff --git a/readme.txt b/readme.txt index dcc6d907..4063d34b 100644 --- a/readme.txt +++ b/readme.txt @@ -42,13 +42,14 @@ GLM 0.9.6.0: 2014-XX-XX - Added transparent use of SIMD instructions for vec4 and mat4 types - Removed degrees for function parameters - Removed GLM_FORCE_RADIANS, active by default -- Added move contructors and assignment operators (#141) +- Added move contructors and assignment operators #141 - Use pragma once - Fixed Visual Studio 14 compiler warnings - Added *vec1 support to *vec2 types -- Limited extended integer type redifinition (#233) -- Improved linearRand: support precision and integers (#230) -- Added vec3 slerp (#237) +- Limited extended integer type redifinition #233 +- Improved linearRand: support precision and integers #230 +- Added vec3 slerp #237 +- Added GTX_common with isdenomal #223 ================================================================================ GLM 0.9.5.5: 2014-XX-XX diff --git a/test/gtx/CMakeLists.txt b/test/gtx/CMakeLists.txt index 9b8674bd..e93fa17c 100644 --- a/test/gtx/CMakeLists.txt +++ b/test/gtx/CMakeLists.txt @@ -3,6 +3,7 @@ glmCreateTestGTC(gtx_bit) glmCreateTestGTC(gtx_closest_point) glmCreateTestGTC(gtx_color_space_YCoCg) glmCreateTestGTC(gtx_color_space) +glmCreateTestGTC(gtx_common) glmCreateTestGTC(gtx_compatibility) glmCreateTestGTC(gtx_component_wise) glmCreateTestGTC(gtx_euler_angle) diff --git a/test/gtx/gtx_common.cpp b/test/gtx/gtx_common.cpp new file mode 100644 index 00000000..2bd3b025 --- /dev/null +++ b/test/gtx/gtx_common.cpp @@ -0,0 +1,33 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////// +// OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net) +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Created : 2014-09-08 +// Updated : 2014-09-08 +// Licence : This source is under MIT licence +// File : test/gtx/common.cpp +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#include +#include + +int test_isdenormal() +{ + int Error(0); + + bool A = glm::isdenormal(1.0f); + glm::bvec1 B = glm::isdenormal(glm::vec1(1.0f)); + glm::bvec2 C = glm::isdenormal(glm::vec2(1.0f)); + glm::bvec3 D = glm::isdenormal(glm::vec3(1.0f)); + glm::bvec4 E = glm::isdenormal(glm::vec4(1.0f)); + + return Error; +} + +int main() +{ + int Error(0); + + Error += test_isdenormal(); + + return Error; +}