1
0
mirror of https://github.com/danog/ton.git synced 2024-12-04 10:28:27 +01:00
ton/crypto/func/test/a6.fc
2019-09-07 14:33:36 +04:00

86 lines
1.5 KiB
Plaintext

(int, int) f(int a, int b, int c, int d, int e, int f) {
;; solve a 2x2 linear equation
int D = a * d - b * c;
int Dx = e * d - b * f;
int Dy = a * f - e * c;
return (Dx / D, Dy / D);
}
int calc_phi() {
var n = 1;
repeat (70) { n *= 10; }
var p = var q = 1;
do {
(p, q) = (q, p + q);
} until (q > n);
return muldivr(p, n, q);
}
int calc_sqrt2() {
var n = 1;
repeat (70) { n *= 10; }
var p = var q = 1;
do {
var t = p + q;
(p, q) = (q, t + q);
} until (q > n);
return muldivr(p, n, q);
}
var calc_root(m) {
int base = 1;
repeat(70) { base *= 10; }
var (a, b, c) = (1, 0, - m);
var (p1, q1, p2, q2) = (1, 0, 0, 1);
do {
int k = -1;
var (a1, b1, c1) = (0, 0, 0);
do {
k += 1;
(a1, b1, c1) = (a, b, c);
c += b;
c += b += a;
} until (c > 0);
(a, b, c) = (- c1, - b1, - a1);
(p1, q1) = (k * p1 + q1, p1);
(p2, q2) = (k * p2 + q2, p2);
} until (p1 > base);
return (p1, q1, p2, q2);
}
{-
operator _/%_ infix 20;
(int, int) ((int x) /% (int y)) {
return (x / y, x % y);
}
(int, int) _/%_ (int x, int y) {
return (x / y, x % y);
}
-}
{-
< type A, type B, type C >
(B, C, A) rot (A x, B y, C z) {
return (y, z, x);
}
-}
int ataninv(int base, int q) { ;; computes base*atan(1/q)
base /~= q;
q *= - q;
int sum = 0;
int n = 1;
do {
sum += base /~ n;
base /~= q;
n += 2;
} until base == 0;
return sum;
}
int calc_pi() {
int base = 64;
repeat (70) { base *= 10; }
return (ataninv(base << 2, 5) - ataninv(base, 239)) >>~ 4;
}