Added vector retionnal with max ULPs arguments and fixed double support
This commit is contained in:
parent
311f59ed7e
commit
b2a7f1093c
@ -206,18 +206,5 @@ namespace detail
|
|||||||
return genType(1);
|
return genType(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
|
|
||||||
union float_t
|
|
||||||
{
|
|
||||||
GLM_CONSTEXPR float_t(float Num = 0.0f) : f(Num) {}
|
|
||||||
// Portable extraction of components.
|
|
||||||
GLM_CONSTEXPR bool negative() const { return i < 0; }
|
|
||||||
GLM_CONSTEXPR int mantissa() const { return i & ((1 << 23) - 1); }
|
|
||||||
GLM_CONSTEXPR int exponent() const { return (i >> 23) & 0xFF; }
|
|
||||||
|
|
||||||
int const i;
|
|
||||||
float const f;
|
|
||||||
};
|
|
||||||
}//namespace detail
|
}//namespace detail
|
||||||
}//namespace glm
|
}//namespace glm
|
||||||
|
48
glm/detail/type_float.hpp
Normal file
48
glm/detail/type_float.hpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "setup.hpp"
|
||||||
|
|
||||||
|
namespace glm{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
union float_t
|
||||||
|
{};
|
||||||
|
|
||||||
|
// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
|
||||||
|
template <>
|
||||||
|
union float_t<float>
|
||||||
|
{
|
||||||
|
typedef int int_type;
|
||||||
|
typedef float float_type;
|
||||||
|
|
||||||
|
GLM_CONSTEXPR float_t(float_type Num = 0.0f) : f(Num) {}
|
||||||
|
|
||||||
|
// Portable extraction of components.
|
||||||
|
GLM_CONSTEXPR bool negative() const { return i < 0; }
|
||||||
|
GLM_CONSTEXPR int_type mantissa() const { return i & ((1 << 23) - 1); }
|
||||||
|
GLM_CONSTEXPR int_type exponent() const { return (i >> 23) & ((1 << 8) - 1); }
|
||||||
|
|
||||||
|
int_type const i;
|
||||||
|
float_type const f;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
union float_t<double>
|
||||||
|
{
|
||||||
|
typedef detail::int64 int_type;
|
||||||
|
typedef double float_type;
|
||||||
|
|
||||||
|
GLM_CONSTEXPR float_t(float_type Num = static_cast<float_type>(0)) : f(Num) {}
|
||||||
|
|
||||||
|
// Portable extraction of components.
|
||||||
|
GLM_CONSTEXPR bool negative() const { return i < 0; }
|
||||||
|
GLM_CONSTEXPR int_type mantissa() const { return i & ((int_type(1) << 52) - 1); }
|
||||||
|
GLM_CONSTEXPR int_type exponent() const { return (i >> 52) & ((int_type(1) << 11) - 1); }
|
||||||
|
|
||||||
|
int_type const i;
|
||||||
|
float_type const f;
|
||||||
|
};
|
||||||
|
}//namespace detail
|
||||||
|
}//namespace glm
|
||||||
|
|
@ -1,6 +1,7 @@
|
|||||||
#include "../common.hpp"
|
#include "../common.hpp"
|
||||||
#include "../ext/scalar_int_sized.hpp"
|
#include "../ext/scalar_int_sized.hpp"
|
||||||
#include "../ext/scalar_uint_sized.hpp"
|
#include "../ext/scalar_uint_sized.hpp"
|
||||||
|
#include "../detail/type_float.hpp"
|
||||||
|
|
||||||
namespace glm
|
namespace glm
|
||||||
{
|
{
|
||||||
@ -19,8 +20,8 @@ namespace glm
|
|||||||
template<typename genType>
|
template<typename genType>
|
||||||
GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool equal(genType const& x, genType const& y, int MaxULPs)
|
GLM_FUNC_QUALIFIER GLM_CONSTEXPR bool equal(genType const& x, genType const& y, int MaxULPs)
|
||||||
{
|
{
|
||||||
detail::float_t const a(x);
|
detail::float_t<genType> const a(x);
|
||||||
detail::float_t const b(y);
|
detail::float_t<genType> const b(y);
|
||||||
|
|
||||||
// Different signs means they do not match.
|
// Different signs means they do not match.
|
||||||
if(a.negative() != b.negative())
|
if(a.negative() != b.negative())
|
||||||
@ -30,7 +31,7 @@ namespace glm
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the difference in ULPs.
|
// Find the difference in ULPs.
|
||||||
int const DiffULPs = abs(a.i - b.i);
|
typename detail::float_t<genType>::int_type const DiffULPs = abs(a.i - b.i);
|
||||||
return DiffULPs <= MaxULPs;
|
return DiffULPs <= MaxULPs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "../vector_relational.hpp"
|
#include "../vector_relational.hpp"
|
||||||
#include "../common.hpp"
|
#include "../common.hpp"
|
||||||
#include "../detail/qualifier.hpp"
|
#include "../detail/qualifier.hpp"
|
||||||
|
#include "../detail/type_float.hpp"
|
||||||
|
|
||||||
namespace glm
|
namespace glm
|
||||||
{
|
{
|
||||||
@ -41,8 +42,8 @@ namespace glm
|
|||||||
vec<L, bool, Q> Result;
|
vec<L, bool, Q> Result;
|
||||||
for(length_t i = 0; i < L; ++i)
|
for(length_t i = 0; i < L; ++i)
|
||||||
{
|
{
|
||||||
detail::float_t const a(x[i]);
|
detail::float_t<T> const a(x[i]);
|
||||||
detail::float_t const b(y[i]);
|
detail::float_t<T> const b(y[i]);
|
||||||
|
|
||||||
// Different signs means they do not match.
|
// Different signs means they do not match.
|
||||||
if(a.negative() != b.negative())
|
if(a.negative() != b.negative())
|
||||||
@ -52,7 +53,7 @@ namespace glm
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the difference in ULPs.
|
// Find the difference in ULPs.
|
||||||
int const DiffULPs = abs(a.i - b.i);
|
typename detail::float_t<T>::int_type const DiffULPs = abs(a.i - b.i);
|
||||||
Result[i] = DiffULPs <= MaxULPs;
|
Result[i] = DiffULPs <= MaxULPs;
|
||||||
}
|
}
|
||||||
return Result;
|
return Result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user