mirror of
https://github.com/ton-blockchain/ton
synced 2025-02-15 04:32:21 +00:00
@code_hash to match (boc) hash of compiled.fif against expected. While being much less flexible than @fif_codegen, it nevertheless gives a guarantee of bytecode stability on compiler modifications.
91 lines
1.7 KiB
Text
91 lines
1.7 KiB
Text
(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);
|
|
}
|
|
-}
|
|
|
|
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;
|
|
}
|
|
|
|
int main() {
|
|
return calc_pi();
|
|
}
|
|
|
|
{-
|
|
method_id | in | out
|
|
TESTCASE | 0 | | 31415926535897932384626433832795028841971693993751058209749445923078164
|
|
|
|
@code_hash 84337043972311674339187056298873613816389434478842780265748859098303774481976
|
|
-}
|