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:
Fischlurch 2011-03-16 03:43:11 +01:00
parent 827b395806
commit 436979094a
2 changed files with 33 additions and 1 deletions

View file

@ -59,7 +59,16 @@ namespace util {
/** helper to treat int or long division uniformly */
template<typename I>
struct IDiv;
struct IDiv
{
I quot;
I rem;
IDiv (I num, I den)
: quot(num/den)
, rem(num - quot*den)
{ }
};
template<>
struct IDiv<int>

View file

@ -90,6 +90,7 @@ namespace test {
/**********************************************************************
* @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
* of time values into frame intervals. This rule requires time
* points to be rounded towards the next lower frame border always,
@ -111,6 +112,12 @@ namespace test {
{
verifyBehaviour ();
verifyIntegerTypes<int>();
verifyIntegerTypes<long>();
verifyIntegerTypes<short>();
verifyIntegerTypes<int64_t>();
verifyIntegerTypes<long long int>();
if (!isnil (arg))
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.
* This test uses a sequence of random integers, where the values