mirror of
https://github.com/g-truc/glm.git
synced 2025-04-10 07:18:54 +00:00
Fixed epsilon for half types
This commit is contained in:
parent
1fb8bec873
commit
bfec0e2388
4 changed files with 21 additions and 13 deletions
|
@ -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));
|
||||
|
|
|
@ -34,6 +34,12 @@ namespace glm
|
|||
return std::numeric_limits<T>::epsilon();
|
||||
}
|
||||
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR half epsilon()
|
||||
{
|
||||
return half(1.19209290e-007);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T zero()
|
||||
{
|
||||
|
|
|
@ -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<float>::epsilon();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
|
|
@ -20,31 +20,31 @@ int test_equal()
|
|||
{
|
||||
T A = 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 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 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 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 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;
|
||||
|
|
Loading…
Add table
Reference in a new issue