• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1define fast_gcd(a, b) {
2
3	if (a == b) return a;
4	if (a > b) return fast_gcd(a - b, b)
5
6	return fast_gcd(a, b - a);
7}
8
9define void r_reduce(*r[]) {
10
11	auto g,s;
12
13	if (length(r[]) != 2) sqrt(-1);
14	if (scale(r[0])) 2^r[0];
15	if (scale(r[1])) 2^r[1];
16
17	if (r[0] >= 0 && r[1] >= 0) g = fast_gcd(r[0], r[1]);
18	else g = gcd(r[0], r[1]);
19
20	s = scale;
21	scale = 0;
22
23	r[0] /= g;
24	r[1] /= g;
25
26	scale = s;
27}
28
29define void r_init(*r[], a, b) {
30	r[0] = a;
31	r[1] = b;
32	r_reduce(r[]);
33}
34
35define void r_initi(*r[], i, a, b) {
36
37	length(r[]);
38
39	r[0] = i * b + a;
40	r[1] = b;
41
42	length(r[]);
43
44	r_reduce(r[]);
45}
46
47length(a[])
48r_initi(a[], 5, 63, 94);
49