From bfec0e2388d08b5cfa270f924b0f1f2a49b6cd22 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Tue, 6 Nov 2012 02:26:31 +0100 Subject: [PATCH] Fixed epsilon for half types --- glm/core/type_half.inl | 14 +++++++------- glm/gtc/constants.inl | 6 ++++++ test/gtc/gtc_constants.cpp | 4 +++- test/gtc/gtc_epsilon.cpp | 10 +++++----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/glm/core/type_half.inl b/glm/core/type_half.inl index 845369d2..cda7f79a 100644 --- a/glm/core/type_half.inl +++ b/glm/core/type_half.inl @@ -2,6 +2,10 @@ /// OpenGL Mathematics (glm.g-truc.net) /// /// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net) +/// +/// This half implementation is based on OpenEXR which is Copyright (c) 2002, +/// Industrial Light & Magic, a division of Lucas Digital Ltd. LLC +/// /// 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 @@ -24,10 +28,6 @@ /// @file glm/core/type_half.inl /// @date 2008-08-17 / 2011-06-15 /// @author Christophe Riccio -/// -/// Copyright: -/// This half implementation is based on OpenEXR which is Copyright (c) 2002, -/// Industrial Light & Magic, a division of Lucas Digital Ltd. LLC /////////////////////////////////////////////////////////////////////////////////// #include "_detail.hpp" @@ -152,7 +152,7 @@ namespace detail // less than half_MIN (f may be a small normalized // float, a denormalized float or a zero). // - // We convert f to a _halfGTX zero. + // We convert f to a half zero. // return 0; @@ -162,7 +162,7 @@ namespace detail // E is between -10 and 0. F is a normalized float, // whose magnitude is less than __half_NRM_MIN. // - // We convert f to a denormalized _halfGTX. + // We convert f to a denormalized half. // m = (m | 0x00800000) >> (1 - e); @@ -180,7 +180,7 @@ namespace detail m += 0x00002000; // - // Assemble the _halfGTX from s, e (zero) and m. + // Assemble the half from s, e (zero) and m. // return hdata(s | (m >> 13)); diff --git a/glm/gtc/constants.inl b/glm/gtc/constants.inl index 63b7b123..f40c1b40 100644 --- a/glm/gtc/constants.inl +++ b/glm/gtc/constants.inl @@ -34,6 +34,12 @@ namespace glm return std::numeric_limits::epsilon(); } + template <> + GLM_FUNC_QUALIFIER GLM_CONSTEXPR half epsilon() + { + return half(1.19209290e-007); + } + template GLM_FUNC_QUALIFIER GLM_CONSTEXPR T zero() { diff --git a/test/gtc/gtc_constants.cpp b/test/gtc/gtc_constants.cpp index 3120aef4..37ee8258 100644 --- a/test/gtc/gtc_constants.cpp +++ b/test/gtc/gtc_constants.cpp @@ -14,7 +14,9 @@ int main() { int Error(0); - + float MinHalf = 0.0f; + while (glm::half(MinHalf) == glm::half(0.0f)) + MinHalf += std::numeric_limits::epsilon(); return Error; } diff --git a/test/gtc/gtc_epsilon.cpp b/test/gtc/gtc_epsilon.cpp index f6b28586..8ff810a6 100644 --- a/test/gtc/gtc_epsilon.cpp +++ b/test/gtc/gtc_epsilon.cpp @@ -20,31 +20,31 @@ int test_equal() { T A = glm::epsilon(); T B = glm::epsilon(); - Error += glm::epsilonEqual(A, B, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(A, B, glm::epsilon() * T(2)) ? 0 : 1; } { T A(0); T B = T(0) + glm::epsilon(); - Error += glm::epsilonEqual(A, B, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(A, B, glm::epsilon() * T(2)) ? 0 : 1; } { T A(0); T B = T(0) - glm::epsilon(); - Error += glm::epsilonEqual(A, B, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(A, B, glm::epsilon() * T(2)) ? 0 : 1; } { T A = T(0) + glm::epsilon(); T B = T(0); - Error += glm::epsilonEqual(A, B, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(A, B, glm::epsilon() * T(2)) ? 0 : 1; } { T A = T(0) - glm::epsilon(); T B = T(0); - Error += glm::epsilonEqual(A, B, glm::epsilon()) ? 0 : 1; + Error += glm::epsilonEqual(A, B, glm::epsilon() * T(2)) ? 0 : 1; } return Error;