mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
c1c77bd64a
This is for developing methods of implementing geometric algebra and eventually playing with it visually.
40 lines
618 B
R
40 lines
618 B
R
#include <runtime.h>
|
|
#include "util.h"
|
|
|
|
void printf(string fmt, ...) = #0;
|
|
void traceon(void) = #0;
|
|
void traceoff(void) = #0;
|
|
|
|
int *
|
|
binomial (int n)
|
|
{
|
|
int *coef = obj_malloc ((n + 1) * sizeof (int));
|
|
int c = 1;
|
|
for (int i = 0; i < n + 1; i++) {
|
|
coef[i] = c;
|
|
c = (c * (n - i)) / (i + 1);
|
|
}
|
|
return coef;
|
|
}
|
|
|
|
int
|
|
count_bits (unsigned v)
|
|
{
|
|
int c = 0;
|
|
for (; v; c++) {
|
|
v &= v - 1u; //XXX bug in qfcc: just 1 results in extra temp
|
|
}
|
|
return c;
|
|
}
|
|
|
|
int
|
|
count_flips (unsigned a, unsigned b)
|
|
{
|
|
int c = 0;
|
|
a >>= 1;
|
|
while (a) {
|
|
c += count_bits (a & b);
|
|
a >>= 1;
|
|
}
|
|
return c;
|
|
}
|