Fixed epsilon for half types
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
/// OpenGL Mathematics (glm.g-truc.net)
|
/// OpenGL Mathematics (glm.g-truc.net)
|
||||||
///
|
///
|
||||||
/// Copyright (c) 2005 - 2012 G-Truc Creation (www.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
|
/// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
/// of this software and associated documentation files (the "Software"), to deal
|
/// of this software and associated documentation files (the "Software"), to deal
|
||||||
/// in the Software without restriction, including without limitation the rights
|
/// in the Software without restriction, including without limitation the rights
|
||||||
@@ -24,10 +28,6 @@
|
|||||||
/// @file glm/core/type_half.inl
|
/// @file glm/core/type_half.inl
|
||||||
/// @date 2008-08-17 / 2011-06-15
|
/// @date 2008-08-17 / 2011-06-15
|
||||||
/// @author Christophe Riccio
|
/// @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"
|
#include "_detail.hpp"
|
||||||
@@ -152,7 +152,7 @@ namespace detail
|
|||||||
// less than half_MIN (f may be a small normalized
|
// less than half_MIN (f may be a small normalized
|
||||||
// float, a denormalized float or a zero).
|
// float, a denormalized float or a zero).
|
||||||
//
|
//
|
||||||
// We convert f to a _halfGTX zero.
|
// We convert f to a half zero.
|
||||||
//
|
//
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -162,7 +162,7 @@ namespace detail
|
|||||||
// E is between -10 and 0. F is a normalized float,
|
// E is between -10 and 0. F is a normalized float,
|
||||||
// whose magnitude is less than __half_NRM_MIN.
|
// 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);
|
m = (m | 0x00800000) >> (1 - e);
|
||||||
@@ -180,7 +180,7 @@ namespace detail
|
|||||||
m += 0x00002000;
|
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));
|
return hdata(s | (m >> 13));
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ namespace glm
|
|||||||
return std::numeric_limits<T>::epsilon();
|
return std::numeric_limits<T>::epsilon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
GLM_FUNC_QUALIFIER GLM_CONSTEXPR half epsilon()
|
||||||
|
{
|
||||||
|
return half(1.19209290e-007);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T zero()
|
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T zero()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ int main()
|
|||||||
{
|
{
|
||||||
int Error(0);
|
int Error(0);
|
||||||
|
|
||||||
|
float MinHalf = 0.0f;
|
||||||
|
while (glm::half(MinHalf) == glm::half(0.0f))
|
||||||
|
MinHalf += std::numeric_limits<float>::epsilon();
|
||||||
|
|
||||||
return Error;
|
return Error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,31 +20,31 @@ int test_equal()
|
|||||||
{
|
{
|
||||||
T A = glm::epsilon<T>();
|
T A = glm::epsilon<T>();
|
||||||
T B = glm::epsilon<T>();
|
T B = glm::epsilon<T>();
|
||||||
Error += glm::epsilonEqual(A, B, glm::epsilon<T>()) ? 0 : 1;
|
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
T A(0);
|
T A(0);
|
||||||
T B = T(0) + glm::epsilon<T>();
|
T B = T(0) + glm::epsilon<T>();
|
||||||
Error += glm::epsilonEqual(A, B, glm::epsilon<T>()) ? 0 : 1;
|
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
T A(0);
|
T A(0);
|
||||||
T B = T(0) - glm::epsilon<T>();
|
T B = T(0) - glm::epsilon<T>();
|
||||||
Error += glm::epsilonEqual(A, B, glm::epsilon<T>()) ? 0 : 1;
|
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
T A = T(0) + glm::epsilon<T>();
|
T A = T(0) + glm::epsilon<T>();
|
||||||
T B = T(0);
|
T B = T(0);
|
||||||
Error += glm::epsilonEqual(A, B, glm::epsilon<T>()) ? 0 : 1;
|
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
T A = T(0) - glm::epsilon<T>();
|
T A = T(0) - glm::epsilon<T>();
|
||||||
T B = T(0);
|
T B = T(0);
|
||||||
Error += glm::epsilonEqual(A, B, glm::epsilon<T>()) ? 0 : 1;
|
Error += glm::epsilonEqual(A, B, glm::epsilon<T>() * T(2)) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Error;
|
return Error;
|
||||||
|
|||||||
Reference in New Issue
Block a user