mirror of
https://github.com/g-truc/glm.git
synced 2024-11-27 02:34:35 +00:00
Fixed abs function for half based types
This commit is contained in:
parent
cdf5d19275
commit
1fb8bec873
@ -60,19 +60,19 @@ namespace detail
|
|||||||
|
|
||||||
// abs
|
// abs
|
||||||
template <typename genFIType>
|
template <typename genFIType>
|
||||||
GLM_FUNC_QUALIFIER genFIType abs
|
GLM_FUNC_QUALIFIER genFIType abs
|
||||||
(
|
(
|
||||||
genFIType const & x
|
genFIType const & x
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::Abs_<genFIType, std::numeric_limits<genFIType>::is_signed>::get(x);
|
return detail::Abs_<genFIType, std::numeric_limits<genFIType>::is_signed>::get(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
VECTORIZE_VEC(abs)
|
VECTORIZE_VEC(abs)
|
||||||
|
|
||||||
// sign
|
// sign
|
||||||
//Try something like based on x >> 31 to get the sign bit
|
//Try something like based on x >> 31 to get the sign bit
|
||||||
template <typename genFIType>
|
template <typename genFIType>
|
||||||
GLM_FUNC_QUALIFIER genFIType sign
|
GLM_FUNC_QUALIFIER genFIType sign
|
||||||
(
|
(
|
||||||
genFIType const & x
|
genFIType const & x
|
||||||
@ -81,43 +81,43 @@ namespace detail
|
|||||||
GLM_STATIC_ASSERT(
|
GLM_STATIC_ASSERT(
|
||||||
detail::type<genFIType>::is_float ||
|
detail::type<genFIType>::is_float ||
|
||||||
detail::type<genFIType>::is_int, "'sign' only accept signed inputs");
|
detail::type<genFIType>::is_int, "'sign' only accept signed inputs");
|
||||||
|
|
||||||
genFIType result;
|
genFIType result;
|
||||||
if(x > genFIType(0))
|
if(x > genFIType(0))
|
||||||
result = genFIType(1);
|
result = genFIType(1);
|
||||||
else if(x < genFIType(0))
|
else if(x < genFIType(0))
|
||||||
result = genFIType(-1);
|
result = genFIType(-1);
|
||||||
else
|
else
|
||||||
result = genFIType(0);
|
result = genFIType(0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
VECTORIZE_VEC(sign)
|
VECTORIZE_VEC(sign)
|
||||||
|
|
||||||
// floor
|
// floor
|
||||||
template <>
|
template <>
|
||||||
GLM_FUNC_QUALIFIER detail::half floor<detail::half>(detail::half const & x)
|
GLM_FUNC_QUALIFIER detail::half floor<detail::half>(detail::half const & x)
|
||||||
{
|
{
|
||||||
return detail::half(::std::floor(float(x)));
|
return detail::half(::std::floor(float(x)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename genType>
|
template <typename genType>
|
||||||
GLM_FUNC_QUALIFIER genType floor(genType const & x)
|
GLM_FUNC_QUALIFIER genType floor(genType const & x)
|
||||||
{
|
{
|
||||||
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'floor' only accept floating-point inputs");
|
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'floor' only accept floating-point inputs");
|
||||||
|
|
||||||
return ::std::floor(x);
|
return ::std::floor(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
VECTORIZE_VEC(floor)
|
VECTORIZE_VEC(floor)
|
||||||
|
|
||||||
// trunc
|
// trunc
|
||||||
template <typename genType>
|
template <typename genType>
|
||||||
GLM_FUNC_QUALIFIER genType trunc(genType const & x)
|
GLM_FUNC_QUALIFIER genType trunc(genType const & x)
|
||||||
{
|
{
|
||||||
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'trunc' only accept floating-point inputs");
|
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'trunc' only accept floating-point inputs");
|
||||||
return x < 0 ? -floor(-x) : floor(x);
|
return x < 0 ? -floor(-x) : floor(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
VECTORIZE_VEC(trunc)
|
VECTORIZE_VEC(trunc)
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
///
|
///
|
||||||
/// @ref gtc_half_float
|
/// @ref gtc_half_float
|
||||||
/// @file glm/gtc/half_float.hpp
|
/// @file glm/gtc/half_float.hpp
|
||||||
/// @date 2009-04-29 / 2011-06-05
|
/// @date 2009-04-29 / 2012-11-06
|
||||||
/// @author Christophe Riccio
|
/// @author Christophe Riccio
|
||||||
///
|
///
|
||||||
/// @see core (dependence)
|
/// @see core (dependence)
|
||||||
@ -55,7 +55,7 @@ namespace detail
|
|||||||
typedef half value_type;
|
typedef half value_type;
|
||||||
typedef std::size_t size_type;
|
typedef std::size_t size_type;
|
||||||
|
|
||||||
GLM_FUNC_DECL size_type length() const;
|
GLM_FUNC_DECL size_type length() const;
|
||||||
static GLM_FUNC_DECL size_type value_size();
|
static GLM_FUNC_DECL size_type value_size();
|
||||||
|
|
||||||
typedef tvec2<half> type;
|
typedef tvec2<half> type;
|
||||||
@ -148,7 +148,7 @@ namespace detail
|
|||||||
enum ctor{null};
|
enum ctor{null};
|
||||||
typedef half value_type;
|
typedef half value_type;
|
||||||
typedef std::size_t size_type;
|
typedef std::size_t size_type;
|
||||||
GLM_FUNC_DECL size_type length() const;
|
GLM_FUNC_DECL size_type length() const;
|
||||||
static GLM_FUNC_DECL size_type value_size();
|
static GLM_FUNC_DECL size_type value_size();
|
||||||
|
|
||||||
typedef tvec3<half> type;
|
typedef tvec3<half> type;
|
||||||
@ -245,7 +245,7 @@ namespace detail
|
|||||||
enum ctor{null};
|
enum ctor{null};
|
||||||
typedef half value_type;
|
typedef half value_type;
|
||||||
typedef std::size_t size_type;
|
typedef std::size_t size_type;
|
||||||
GLM_FUNC_DECL size_type length() const;
|
GLM_FUNC_DECL size_type length() const;
|
||||||
static GLM_FUNC_DECL size_type value_size();
|
static GLM_FUNC_DECL size_type value_size();
|
||||||
|
|
||||||
typedef tvec4<half> type;
|
typedef tvec4<half> type;
|
||||||
@ -371,7 +371,7 @@ namespace detail
|
|||||||
/// 2 * 2 matrix of half-precision floating-point numbers.
|
/// 2 * 2 matrix of half-precision floating-point numbers.
|
||||||
/// @see gtc_half_float
|
/// @see gtc_half_float
|
||||||
typedef detail::tmat2x2<detail::half> hmat2;
|
typedef detail::tmat2x2<detail::half> hmat2;
|
||||||
|
|
||||||
/// 3 * 3 matrix of half-precision floating-point numbers.
|
/// 3 * 3 matrix of half-precision floating-point numbers.
|
||||||
/// @see gtc_half_float
|
/// @see gtc_half_float
|
||||||
typedef detail::tmat3x3<detail::half> hmat3;
|
typedef detail::tmat3x3<detail::half> hmat3;
|
||||||
@ -383,11 +383,11 @@ namespace detail
|
|||||||
/// 2 * 2 matrix of half-precision floating-point numbers.
|
/// 2 * 2 matrix of half-precision floating-point numbers.
|
||||||
/// @see gtc_half_float
|
/// @see gtc_half_float
|
||||||
typedef detail::tmat2x2<detail::half> hmat2x2;
|
typedef detail::tmat2x2<detail::half> hmat2x2;
|
||||||
|
|
||||||
/// 2 * 3 matrix of half-precision floating-point numbers.
|
/// 2 * 3 matrix of half-precision floating-point numbers.
|
||||||
/// @see gtc_half_float
|
/// @see gtc_half_float
|
||||||
typedef detail::tmat2x3<detail::half> hmat2x3;
|
typedef detail::tmat2x3<detail::half> hmat2x3;
|
||||||
|
|
||||||
/// 2 * 4 matrix of half-precision floating-point numbers.
|
/// 2 * 4 matrix of half-precision floating-point numbers.
|
||||||
/// @see gtc_half_float
|
/// @see gtc_half_float
|
||||||
typedef detail::tmat2x4<detail::half> hmat2x4;
|
typedef detail::tmat2x4<detail::half> hmat2x4;
|
||||||
@ -395,11 +395,11 @@ namespace detail
|
|||||||
/// 3 * 2 matrix of half-precision floating-point numbers.
|
/// 3 * 2 matrix of half-precision floating-point numbers.
|
||||||
/// @see gtc_half_float
|
/// @see gtc_half_float
|
||||||
typedef detail::tmat3x2<detail::half> hmat3x2;
|
typedef detail::tmat3x2<detail::half> hmat3x2;
|
||||||
|
|
||||||
/// 3 * 3 matrix of half-precision floating-point numbers.
|
/// 3 * 3 matrix of half-precision floating-point numbers.
|
||||||
/// @see gtc_half_float
|
/// @see gtc_half_float
|
||||||
typedef detail::tmat3x3<detail::half> hmat3x3;
|
typedef detail::tmat3x3<detail::half> hmat3x3;
|
||||||
|
|
||||||
/// 3 * 4 matrix of half-precision floating-point numbers.
|
/// 3 * 4 matrix of half-precision floating-point numbers.
|
||||||
/// @see gtc_half_float
|
/// @see gtc_half_float
|
||||||
typedef detail::tmat3x4<detail::half> hmat3x4;
|
typedef detail::tmat3x4<detail::half> hmat3x4;
|
||||||
@ -411,11 +411,27 @@ namespace detail
|
|||||||
/// 4 * 3 matrix of half-precision floating-point numbers.
|
/// 4 * 3 matrix of half-precision floating-point numbers.
|
||||||
/// @see gtc_half_float
|
/// @see gtc_half_float
|
||||||
typedef detail::tmat4x3<detail::half> hmat4x3;
|
typedef detail::tmat4x3<detail::half> hmat4x3;
|
||||||
|
|
||||||
/// 4 * 4 matrix of half-precision floating-point numbers.
|
/// 4 * 4 matrix of half-precision floating-point numbers.
|
||||||
/// @see gtc_half_float
|
/// @see gtc_half_float
|
||||||
typedef detail::tmat4x4<detail::half> hmat4x4;
|
typedef detail::tmat4x4<detail::half> hmat4x4;
|
||||||
|
|
||||||
|
/// Returns the absolute value of a half-precision floating-point value
|
||||||
|
/// @see gtc_half_float
|
||||||
|
half abs(half const & x);
|
||||||
|
|
||||||
|
/// Returns the absolute value of a half-precision floating-point two dimensional vector
|
||||||
|
/// @see gtc_half_float
|
||||||
|
hvec2 abs(hvec2 const & x);
|
||||||
|
|
||||||
|
/// Returns the absolute value of a half-precision floating-point three dimensional vector
|
||||||
|
/// @see gtc_half_float
|
||||||
|
hvec3 abs(hvec3 const & x);
|
||||||
|
|
||||||
|
/// Returns the absolute value of a half-precision floating-point four dimensional vector
|
||||||
|
/// @see gtc_half_float
|
||||||
|
hvec4 abs(hvec4 const & x);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
}// namespace glm
|
}// namespace glm
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
///
|
///
|
||||||
/// @ref gtc_half_float
|
/// @ref gtc_half_float
|
||||||
/// @file glm/gtc/half_float.inl
|
/// @file glm/gtc/half_float.inl
|
||||||
/// @date 2009-04-29 / 2011-06-05
|
/// @date 2009-04-29 / 2012-11-06
|
||||||
/// @author Christophe Riccio
|
/// @author Christophe Riccio
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -1006,4 +1006,34 @@ namespace detail
|
|||||||
#endif//(GLM_COMPONENT == GLM_COMPONENT_CXX98)
|
#endif//(GLM_COMPONENT == GLM_COMPONENT_CXX98)
|
||||||
|
|
||||||
}//namespace detail
|
}//namespace detail
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER half abs(half const & x)
|
||||||
|
{
|
||||||
|
return float(x) >= float(0) ? x : -x;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER hvec2 abs(hvec2 const & v)
|
||||||
|
{
|
||||||
|
return hvec2(
|
||||||
|
float(v.x) >= float(0) ? v.x : -v.x,
|
||||||
|
float(v.y) >= float(0) ? v.y : -v.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER hvec3 abs(hvec3 const & v)
|
||||||
|
{
|
||||||
|
return hvec3(
|
||||||
|
float(v.x) >= float(0) ? v.x : -v.x,
|
||||||
|
float(v.y) >= float(0) ? v.y : -v.y,
|
||||||
|
float(v.z) >= float(0) ? v.z : -v.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER hvec4 abs(hvec4 const & v)
|
||||||
|
{
|
||||||
|
return hvec4(
|
||||||
|
float(v.x) >= float(0) ? v.x : -v.x,
|
||||||
|
float(v.y) >= float(0) ? v.y : -v.y,
|
||||||
|
float(v.z) >= float(0) ? v.z : -v.z,
|
||||||
|
float(v.w) >= float(0) ? v.w : -v.w);
|
||||||
|
}
|
||||||
|
|
||||||
}//namespace glm
|
}//namespace glm
|
||||||
|
Loading…
Reference in New Issue
Block a user