From 7a1cc47897a40a63b501fcce0f1749fc4e191102 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 4 May 2011 00:54:35 +0100 Subject: [PATCH] Added development tests --- test/gtx/gtx-ulp.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/test/gtx/gtx-ulp.cpp b/test/gtx/gtx-ulp.cpp index 5dbdb01c..48fe148b 100644 --- a/test/gtx/gtx-ulp.cpp +++ b/test/gtx/gtx-ulp.cpp @@ -10,11 +10,79 @@ #include #include #include +#include + +namespace +{ + template + T next(T const & x); + +#if(GLM_COMPILER & GLM_COMPILER_VC) +# include + GLM_FUNC_QUALIFIER float next(float const & x) + { + return _nextafterf(x, std::numeric_limits::max()); + } + + GLM_FUNC_QUALIFIER double next(double const & x) + { + return _nextafter(x, std::numeric_limits::max()); + } +#else +# include + GLM_FUNC_QUALIFIER float next(float const & x) + { + return nextafterf(x, std::numeric_limits::max()); + } + + GLM_FUNC_QUALIFIER double next(double const & x) + { + return nextafter(x, std::numeric_limits::max()); + } +#endif + + template + GLM_FUNC_QUALIFIER T next(T const & x, std::size_t const & Steps) + { + T temp = x; + for(std::size_t i = 0; i < Steps; ++i) + temp = next(temp); + return temp; + } + + template + GLM_FUNC_QUALIFIER std::size_t ulp_distance(T const & x, T const & y) + { + std::size_t ulp = 0; + T temp = x; + + while(temp != y) + { + ++ulp; + temp = next(temp); + } + + return ulp; + } +}//namespace int test_ulp_float() { - double Temp = _nextafter(0.01, 0.011); - std::cout << Temp << " 0.01, 0.011" << std::endl; + std::cout.precision(std::numeric_limits::digits10 + 1); + + float W = 1.0f; + float X = next(W); + bool TestX = W != X; + std::cout << " 1.0f, Next: " << ulp_distance(W, X)<< std::endl; + std::cout << " 1.0f, Nextt(1000): " << next(W, 1000)<< std::endl; + //std::cout << " 0.01, 0.011: " << ulp_distance(0.00000000001f, 0.000000000011f) << std::endl; + //std::cout << " 0.01, 0.011: " << ulp_distance(0.00000000001, 0.000000000011) << std::endl; + + double Y = 1.0; + double Z = next(Y); + bool TestZ = Y != Z; + std::cout << Z << " 0.01, 0.011" << std::endl; + std::cout << " 1.0, Next(1000000): " << next(Y, 1000000)<< std::endl; std::size_t A = glm::ulp(0.01, 0.02); std::size_t B = glm::ulp(glm::vec2(0.01), glm::vec2(0.02));