quakeforge/tools/qfcc/test/modulo.r
Bill Currie b920a4dec9 Add a new test case.
It turns out that the optimizer completely breaks (a + b) % (a - b) with v6
code.
2012-11-22 21:59:01 +09:00

56 lines
1,014 B
R

#pragma traditional
void (...) printf = #0;
float foo (float a, float b)
{
float c = a % b;
return c;
}
float bar (float a, float b)
{
float c;
b &= b;
a &= a;
c = a - ((a / b) & -1) * b;
return c;
}
float baz (float a, float b)
{
float c = (a + b) % (a - b);
return c;
}
float test (string name, float (func)(float a, float b),
float a, float b, float c)
{
float ret;
ret = func (a, b);
if (ret != c) {
printf ("%s: %g %% %g: %g != %g\n", name, a, b, ret, c);
return 1;
}
return 0;
}
float main (void)
{
float res = 0;
res |= test ("foo", foo, 5, 3, 2);
res |= test ("bar", bar, 5, 3, 2);
res |= test ("baz", baz, 5, 3, 0);
res |= test ("foo", foo, -5, 3, -2);
res |= test ("bar", bar, -5, 3, -2);
res |= test ("baz", baz, -5, 3, -2);
res |= test ("foo", foo, 5, -3, 2);
res |= test ("bar", bar, 5, -3, 2);
res |= test ("baz", baz, 5, -3, 2);
res |= test ("foo", foo, -5, -3, -2);
res |= test ("bar", bar, -5, -3, -2);
res |= test ("baz", baz, -5, -3, 0);
return res;
}