Bugfix: fallback implementation for integer div and remainder
this fallback allows to use our custom floordiv for all integral types. This solves compilation problems on 32bit, when gavl_time_t is defined to long long int
This commit is contained in:
parent
827b395806
commit
436979094a
2 changed files with 33 additions and 1 deletions
|
|
@ -59,7 +59,16 @@ namespace util {
|
||||||
|
|
||||||
/** helper to treat int or long division uniformly */
|
/** helper to treat int or long division uniformly */
|
||||||
template<typename I>
|
template<typename I>
|
||||||
struct IDiv;
|
struct IDiv
|
||||||
|
{
|
||||||
|
I quot;
|
||||||
|
I rem;
|
||||||
|
|
||||||
|
IDiv (I num, I den)
|
||||||
|
: quot(num/den)
|
||||||
|
, rem(num - quot*den)
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct IDiv<int>
|
struct IDiv<int>
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@ namespace test {
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* @test Evaluate a custom built integer floor function.
|
* @test Evaluate a custom built integer floor function.
|
||||||
|
* Also known as Knuth's floor division.
|
||||||
* This function is crucial for Lumiera's rule of quantisation
|
* This function is crucial for Lumiera's rule of quantisation
|
||||||
* of time values into frame intervals. This rule requires time
|
* of time values into frame intervals. This rule requires time
|
||||||
* points to be rounded towards the next lower frame border always,
|
* points to be rounded towards the next lower frame border always,
|
||||||
|
|
@ -111,6 +112,12 @@ namespace test {
|
||||||
{
|
{
|
||||||
verifyBehaviour ();
|
verifyBehaviour ();
|
||||||
|
|
||||||
|
verifyIntegerTypes<int>();
|
||||||
|
verifyIntegerTypes<long>();
|
||||||
|
verifyIntegerTypes<short>();
|
||||||
|
verifyIntegerTypes<int64_t>();
|
||||||
|
verifyIntegerTypes<long long int>();
|
||||||
|
|
||||||
if (!isnil (arg))
|
if (!isnil (arg))
|
||||||
runPerformanceTest();
|
runPerformanceTest();
|
||||||
}
|
}
|
||||||
|
|
@ -147,6 +154,22 @@ namespace test {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename I>
|
||||||
|
void
|
||||||
|
verifyIntegerTypes ()
|
||||||
|
{
|
||||||
|
I n,d,expectedRes;
|
||||||
|
|
||||||
|
for (int i=-12; i <= 12; ++i)
|
||||||
|
{
|
||||||
|
n = i;
|
||||||
|
d = 4;
|
||||||
|
expectedRes = floordiv (i,4);
|
||||||
|
CHECK (floordiv(n,d) == expectedRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @test timing measurements to compare implementation details.
|
/** @test timing measurements to compare implementation details.
|
||||||
* This test uses a sequence of random integers, where the values
|
* This test uses a sequence of random integers, where the values
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue