mirror of
https://github.com/g-truc/glm.git
synced 2024-11-10 12:41:54 +00:00
Updated GTX_multiple
This commit is contained in:
parent
4b4b6f6cac
commit
23d2735e03
@ -62,6 +62,18 @@ namespace glm
|
||||
genType Source,
|
||||
genType Multiple);
|
||||
|
||||
/// Higher multiple number of Source.
|
||||
///
|
||||
/// @tparam genType Floating-point or integer scalar or vector types.
|
||||
/// @param Source
|
||||
/// @param Multiple Must be a null or positive value
|
||||
///
|
||||
/// @see gtx_multiple
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<T, P> higherMultiple(
|
||||
vecType<T, P> const & Source,
|
||||
vecType<T, P> const & Multiple);
|
||||
|
||||
/// Lower multiple number of Source.
|
||||
///
|
||||
/// @tparam genType Floating-point or integer scalar or vector types.
|
||||
@ -74,6 +86,18 @@ namespace glm
|
||||
genType Source,
|
||||
genType Multiple);
|
||||
|
||||
/// Lower multiple number of Source.
|
||||
///
|
||||
/// @tparam genType Floating-point or integer scalar or vector types.
|
||||
/// @param Source
|
||||
/// @param Multiple Must be a null or positive value
|
||||
///
|
||||
/// @see gtx_multiple
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<T, P> lowerMultiple(
|
||||
vecType<T, P> const & Source,
|
||||
vecType<T, P> const & Multiple);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
||||
|
@ -13,11 +13,41 @@
|
||||
namespace glm{
|
||||
namespace detail
|
||||
{
|
||||
template <bool Signed>
|
||||
struct higherMultiple
|
||||
template <bool is_float, bool is_signed>
|
||||
struct compute_higherMultiple{};
|
||||
|
||||
template <>
|
||||
struct compute_higherMultiple<true, true>
|
||||
{
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType operator()(genType Source, genType Multiple)
|
||||
GLM_FUNC_QUALIFIER static genType call(genType Source, genType Multiple)
|
||||
{
|
||||
if(Source > genType(0))
|
||||
{
|
||||
genType Tmp = Source - genType(1);
|
||||
return Tmp + (Multiple - std::fmod(Tmp, Multiple));
|
||||
}
|
||||
else
|
||||
return Source + std::fmod(-Source, Multiple);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct compute_higherMultiple<false, false>
|
||||
{
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER static genType call(genType Source, genType Multiple)
|
||||
{
|
||||
genType Tmp = Source - genType(1);
|
||||
return Tmp + (Multiple - (Tmp % Multiple));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct compute_higherMultiple<false, true>
|
||||
{
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER static genType call(genType Source, genType Multiple)
|
||||
{
|
||||
if(Source > genType(0))
|
||||
{
|
||||
@ -29,14 +59,54 @@ namespace detail
|
||||
}
|
||||
};
|
||||
|
||||
template <bool is_float, bool is_signed>
|
||||
struct compute_lowerMultiple{};
|
||||
|
||||
template <>
|
||||
struct higherMultiple<false>
|
||||
struct compute_lowerMultiple<true, true>
|
||||
{
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType operator()(genType Source, genType Multiple)
|
||||
GLM_FUNC_QUALIFIER static genType call(genType Source, genType Multiple)
|
||||
{
|
||||
genType Tmp = Source - genType(1);
|
||||
return Tmp + (Multiple - (Tmp % Multiple));
|
||||
if(Source >= genType(0))
|
||||
return Source - std::fmod(Source, Multiple);
|
||||
else
|
||||
{
|
||||
genType Tmp = Source + genType(1);
|
||||
return Tmp - std::fmod(Tmp, Multiple) - Multiple;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct compute_lowerMultiple<false, false>
|
||||
{
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER static genType call(genType Source, genType Multiple)
|
||||
{
|
||||
if(Source >= genType(0))
|
||||
return Source - Source % Multiple;
|
||||
else
|
||||
{
|
||||
genType Tmp = Source + genType(1);
|
||||
return Tmp - Tmp % Multiple - Multiple;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct compute_lowerMultiple<false, true>
|
||||
{
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER static genType call(genType Source, genType Multiple)
|
||||
{
|
||||
if(Source >= genType(0))
|
||||
return Source - Source % Multiple;
|
||||
else
|
||||
{
|
||||
genType Tmp = Source + genType(1);
|
||||
return Tmp - Tmp % Multiple - Multiple;
|
||||
}
|
||||
}
|
||||
};
|
||||
}//namespace detail
|
||||
@ -47,32 +117,7 @@ namespace detail
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType higherMultiple(genType Source, genType Multiple)
|
||||
{
|
||||
detail::higherMultiple<std::numeric_limits<genType>::is_signed> Compute;
|
||||
return Compute(Source, Multiple);
|
||||
}
|
||||
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER float higherMultiple(float Source, float Multiple)
|
||||
{
|
||||
if(Source > float(0))
|
||||
{
|
||||
float Tmp = Source - float(1);
|
||||
return Tmp + (Multiple - std::fmod(Tmp, Multiple));
|
||||
}
|
||||
else
|
||||
return Source + std::fmod(-Source, Multiple);
|
||||
}
|
||||
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER double higherMultiple(double Source, double Multiple)
|
||||
{
|
||||
if(Source > double(0))
|
||||
{
|
||||
double Tmp = Source - double(1);
|
||||
return Tmp + (Multiple - std::fmod(Tmp, Multiple));
|
||||
}
|
||||
else
|
||||
return Source + std::fmod(-Source, Multiple);
|
||||
return detail::compute_higherMultiple<std::numeric_limits<genType>::is_iec559, std::numeric_limits<genType>::is_signed>::call(Source, Multiple);
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
@ -87,37 +132,7 @@ namespace detail
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType lowerMultiple(genType Source, genType Multiple)
|
||||
{
|
||||
if(Source >= genType(0))
|
||||
return Source - Source % Multiple;
|
||||
else
|
||||
{
|
||||
genType Tmp = Source + genType(1);
|
||||
return Tmp - Tmp % Multiple - Multiple;
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER float lowerMultiple(float Source, float Multiple)
|
||||
{
|
||||
if(Source >= float(0))
|
||||
return Source - std::fmod(Source, Multiple);
|
||||
else
|
||||
{
|
||||
float Tmp = Source + float(1);
|
||||
return Tmp - std::fmod(Tmp, Multiple) - Multiple;
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
GLM_FUNC_QUALIFIER double lowerMultiple(double Source, double Multiple)
|
||||
{
|
||||
if (Source >= double(0))
|
||||
return Source - std::fmod(Source, Multiple);
|
||||
else
|
||||
{
|
||||
double Tmp = Source + double(1);
|
||||
return Tmp - std::fmod(Tmp, Multiple) - Multiple;
|
||||
}
|
||||
return detail::compute_lowerMultiple<std::numeric_limits<genType>::is_iec559, std::numeric_limits<genType>::is_signed>::call(Source, Multiple);
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
|
Loading…
Reference in New Issue
Block a user