mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-25 13:11:00 +00:00
It came about from a discussion in the bivector discord about programmatic testing for blade commutativity and why no texts talked about it. I came up with an idea that turned out not to work (I guess I'd overthought how count_flips works). In the end, I decided to keep it, and simplified metric's sign check.
31 lines
592 B
R
31 lines
592 B
R
#include "metric.h"
|
|
#include "util.h"
|
|
|
|
@implementation Metric
|
|
+(Metric *)R:(int)p, int m, int z
|
|
{
|
|
Metric *metric = [[[Metric alloc] init] autorelease];
|
|
metric.plus = ((1 << p) - 1) << z;
|
|
metric.minus = ((1 << m) - 1) << (z + p);
|
|
metric.zero = (1 << z) - 1;
|
|
return metric;
|
|
}
|
|
|
|
static double
|
|
count_minus (unsigned minus)
|
|
{
|
|
return count_bits (minus) & 1 ? -1 : 1;
|
|
}
|
|
|
|
-(double)apply:(unsigned) a, unsigned b
|
|
{
|
|
// find all the squared elements
|
|
unsigned c = a & b;
|
|
// any elements that square to 0 result in 0
|
|
if (c & zero) {
|
|
return 0;
|
|
}
|
|
return count_minus (c & minus);
|
|
}
|
|
|
|
@end
|