-
Notifications
You must be signed in to change notification settings - Fork 0
/
miscutil.h
76 lines (72 loc) · 1.14 KB
/
miscutil.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
int testarg(int arg)
{
int pow=1;
for(int k=0; k<d; k++)
{
pow*=(spacing);
}
if(arg>=pow || arg<0)
{
printf("arg that failed=%d\n", arg);
exit(EXIT_FAILURE);
}
else
return 0;
}
double getnorm2(double* a, double *result)
{
return times(star(a,result),a,result)[0];
}
int increment(int mu)
{
int res=1;
for(int r=0; r<mu; r++)
{
res*=spacing;
}
return res;
}
int* findcoord(int coor, int* x)
{
int temp=0;
int coors=coor;
while(coors>=0 && temp<d)
{
x[temp]=coors-(coors/(spacing))*(spacing);
coors/=(spacing);
temp++;
}
return x;
}
int* mods(int coor, int mu, int nu, int* results)
{
int* x=(int*)malloc(d*sizeof(int));
x=findcoord(coor,x);
int mua=increment(mu);
int nua=increment(nu);
//mnemonic=Konami code
//upmod
if(x[nu]==spacing-1)
{
results[0]=-nua*spacing;
}
else
results[0]=0;
//downmod
if(x[nu]==0)
{
results[1]=nua*spacing;
}
else
results[1]=0;
//sidemod
if(x[mu]==spacing-1)
{
results[2]=-mua*spacing;
}
else
results[2]=0;
//b a...
free(x);
return results;
}