mirror of
https://github.com/g-truc/glm.git
synced 2024-12-01 20:24:38 +00:00
Updated naming conventions
This commit is contained in:
parent
7a1cc47897
commit
58d2d282f2
@ -23,7 +23,7 @@ namespace ulp
|
|||||||
std::size_t Count = 0;
|
std::size_t Count = 0;
|
||||||
float TempA(a);
|
float TempA(a);
|
||||||
float TempB(b);
|
float TempB(b);
|
||||||
while((TempA = _nextafterf(TempA, TempB)) != TempB)
|
//while((TempA = _nextafterf(TempA, TempB)) != TempB)
|
||||||
++Count;
|
++Count;
|
||||||
return Count;
|
return Count;
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ namespace ulp
|
|||||||
{
|
{
|
||||||
std::size_t Count = 0;
|
std::size_t Count = 0;
|
||||||
float Temp = a;
|
float Temp = a;
|
||||||
while((Temp = _nextafterf(Temp, b)) != b)
|
//while((Temp = _nextafterf(Temp, b)) != b)
|
||||||
{
|
{
|
||||||
std::cout << Temp << " " << b << std::endl;
|
std::cout << Temp << " " << b << std::endl;
|
||||||
++Count;
|
++Count;
|
||||||
@ -52,7 +52,7 @@ namespace ulp
|
|||||||
{
|
{
|
||||||
std::size_t Count = 0;
|
std::size_t Count = 0;
|
||||||
double Temp = a;
|
double Temp = a;
|
||||||
while((Temp = _nextafter(Temp, b)) != b)
|
//while((Temp = _nextafter(Temp, b)) != b)
|
||||||
{
|
{
|
||||||
std::cout << Temp << " " << b << std::endl;
|
std::cout << Temp << " " << b << std::endl;
|
||||||
++Count;
|
++Count;
|
||||||
|
@ -15,51 +15,80 @@
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T next(T const & x);
|
T next_float(T const & x);
|
||||||
|
|
||||||
#if(GLM_COMPILER & GLM_COMPILER_VC)
|
#if(GLM_COMPILER & GLM_COMPILER_VC)
|
||||||
# include <cfloat>
|
# include <cfloat>
|
||||||
GLM_FUNC_QUALIFIER float next(float const & x)
|
# define GLM_NEXT_AFTER _nextafterf
|
||||||
{
|
|
||||||
return _nextafterf(x, std::numeric_limits<float>::max());
|
|
||||||
}
|
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER double next(double const & x)
|
|
||||||
{
|
|
||||||
return _nextafter(x, std::numeric_limits<double>::max());
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
# include <cmath>
|
# include <cmath>
|
||||||
GLM_FUNC_QUALIFIER float next(float const & x)
|
# define GLM_NEXT_AFTER nextafterf
|
||||||
{
|
|
||||||
return nextafterf(x, std::numeric_limits<float>::max());
|
|
||||||
}
|
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER double next(double const & x)
|
|
||||||
{
|
|
||||||
return nextafter(x, std::numeric_limits<double>::max());
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER float next_float(float const & x)
|
||||||
|
{
|
||||||
|
return GLM_NEXT_AFTER(x, std::numeric_limits<float>::max());
|
||||||
|
}
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER double next_float(double const & x)
|
||||||
|
{
|
||||||
|
return GLM_NEXT_AFTER(x, std::numeric_limits<double>::max());
|
||||||
|
}
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER float prev_float(float const & x)
|
||||||
|
{
|
||||||
|
return GLM_NEXT_AFTER(x, std::numeric_limits<float>::min());
|
||||||
|
}
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER double prev_float(double const & x)
|
||||||
|
{
|
||||||
|
return GLM_NEXT_AFTER(x, std::numeric_limits<double>::min());
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER T next(T const & x, std::size_t const & Steps)
|
GLM_FUNC_QUALIFIER T next_float(T const & x, std::size_t const & ulps)
|
||||||
{
|
{
|
||||||
T temp = x;
|
T temp = x;
|
||||||
for(std::size_t i = 0; i < Steps; ++i)
|
for(std::size_t i = 0; i < ulps; ++i)
|
||||||
temp = next(temp);
|
temp = next_float(temp);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER std::size_t ulp_distance(T const & x, T const & y)
|
GLM_FUNC_QUALIFIER T prev_float(T const & x, std::size_t const & ulps)
|
||||||
|
{
|
||||||
|
T temp = x;
|
||||||
|
for(std::size_t i = 0; i < ulps; ++i)
|
||||||
|
temp = prev_float(temp);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
GLM_FUNC_QUALIFIER std::size_t float_distance(T const & x, T const & y)
|
||||||
{
|
{
|
||||||
std::size_t ulp = 0;
|
std::size_t ulp = 0;
|
||||||
T temp = x;
|
|
||||||
|
|
||||||
while(temp != y)
|
if(x < y)
|
||||||
|
{
|
||||||
|
T temp = x;
|
||||||
|
while(temp != y && ulp < std::numeric_limits<std::size_t>::max())
|
||||||
{
|
{
|
||||||
++ulp;
|
++ulp;
|
||||||
temp = next(temp);
|
temp = next_float(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(y < x)
|
||||||
|
{
|
||||||
|
T temp = y;
|
||||||
|
while(temp != x && ulp < std::numeric_limits<std::size_t>::max())
|
||||||
|
{
|
||||||
|
++ulp;
|
||||||
|
temp = next_float(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // ==
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ulp;
|
return ulp;
|
||||||
@ -71,18 +100,27 @@ int test_ulp_float()
|
|||||||
std::cout.precision(std::numeric_limits<double>::digits10 + 1);
|
std::cout.precision(std::numeric_limits<double>::digits10 + 1);
|
||||||
|
|
||||||
float W = 1.0f;
|
float W = 1.0f;
|
||||||
float X = next(W);
|
float X = next_float(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 Y = 1.0;
|
||||||
double Z = next(Y);
|
double Z = next_float(Y);
|
||||||
|
|
||||||
|
bool TestX = W != X;
|
||||||
bool TestZ = Y != Z;
|
bool TestZ = Y != Z;
|
||||||
|
|
||||||
|
std::cout << "1.0f, Next: " << float_distance(W, X)<< std::endl;
|
||||||
|
std::cout << "1.0f, Next(1000): " << float_distance(W, next_float(W, 1000)) << std::endl;
|
||||||
|
|
||||||
|
std::cout << "1.0f, Next: " << float_distance(X, W)<< std::endl;
|
||||||
|
std::cout << "1.0f, Next(1000): " << float_distance(next_float(W, 1000), W) << std::endl;
|
||||||
|
|
||||||
|
std::cout << "1.0, Next: " << float_distance(Y, Z) << std::endl;
|
||||||
|
std::cout << "1.0, Next(1000): " << float_distance(next_float(Y, 1000), Y) << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::cout << Z << " 0.01, 0.011" << std::endl;
|
std::cout << Z << " 0.01, 0.011" << std::endl;
|
||||||
std::cout << " 1.0, Next(1000000): " << next(Y, 1000000)<< std::endl;
|
std::cout << " 1.0, Next(1000000): " << next_float(Y, 1000000)<< std::endl;
|
||||||
|
|
||||||
std::size_t A = glm::ulp(0.01, 0.02);
|
std::size_t A = glm::ulp(0.01, 0.02);
|
||||||
std::size_t B = glm::ulp(glm::vec2(0.01), glm::vec2(0.02));
|
std::size_t B = glm::ulp(glm::vec2(0.01), glm::vec2(0.02));
|
||||||
|
Loading…
Reference in New Issue
Block a user