Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2): Difference between revisions

Line 1,396:
mpz_init_set (tmp[i], env->ng[i]);
mpz_t *term = (!env->overflow) ? cf_ref (env->x, env->ix) : NULL;
env->ix += 1;
mpz_set (env->ng[ng8a2], tmp[ng8a12]);
mpz_set (env->ng[ng8a], tmp[ng8a1]);
Line 1,406 ⟶ 1,407:
a_plus_bc (env->ng[ng8b12], tmp[ng8b2], tmp[ng8b12], *term);
a_plus_bc (env->ng[ng8b1], tmp[ng8b], tmp[ng8b1], *term);
if (!ng8_too_big (env->ng))
env->ix += 1;
else
{
env->overflow = true;
Line 1,416 ⟶ 1,415:
mpz_set (env->ng[ng8b1], tmp[ng8b1]);
}
}
else
{
env->ix += 1;
}
}
Line 1,430 ⟶ 1,425:
mpz_init_set (tmp[i], env->ng[i]);
mpz_t *term = (!env->overflow) ? cf_ref (env->y, env->iy) : NULL;
env->iy += 1;
mpz_set (env->ng[ng8a1], tmp[ng8a12]);
mpz_set (env->ng[ng8a], tmp[ng8a2]);
Line 1,440 ⟶ 1,436:
a_plus_bc (env->ng[ng8b12], tmp[ng8b1], tmp[ng8b12], *term);
a_plus_bc (env->ng[ng8b2], tmp[ng8b], tmp[ng8b2], *term);
if (!ng8_too_big (env->ng))
env->iy += 1;
else
{
env->overflow = true;
Line 1,451 ⟶ 1,445:
}
}
else
env->iy += 1;
}
 
Line 1,593 ⟶ 1,585:
{
size_t ncfstr = strlen (cfstr);
padding = string_repeat (MAX (5048, ncfstr + 1) - ncfstr, " ");
line = string_append3 (line, padding, note);
}
Line 1,655 ⟶ 1,647:
show ("three", three, NULL);
show ("four", four, NULL);
show ("(1 + 1/sqrt(2))/2", method1, "method1method 1");
show ("(1 + 1/sqrt(2))/2", method2, "method2method 2");
show ("(1 + 1/sqrt(2))/2", method3, "method3method 3");
show ("method1 - method2", make_cf_ng8 (ng8_sub, method1, method2),
NULL);
show ("method1 - method3", make_cf_ng8 (ng8_sub, method1, method3),
NULL);
show ("method2 - method3", make_cf_ng8 (ng8_sub, method2, method3),
NULL);
show ("sqrt(2) + sqrt(2)", make_cf_ng8 (ng8_add, sqrt2, sqrt2),
NULL);
Line 1,681 ⟶ 1,667:
{{out}}
<pre>$ gcc -std=gnu2x -Wall -Wextra -g bivariate-continued-fraction-task-gmp.c -lgmp -lgc && ./a.out
golden ratio => [1;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,...] (1 + sqrt(5))/2
silver ratio => [2;2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,...] 1 + sqrt(2)
sqrt(2) => [1;2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,...]
13/11 => [1;5,2]
Line 1,690 ⟶ 1,676:
three => [3]
four => [4]
(1 + 1/sqrt(2))/2 => [0;1,5,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,...] method method11
(1 + 1/sqrt(2))/2 => [0;1,5,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,...] method method22
(1 + 1/sqrt(2))/2 => [0;1,5,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,...] method method33
method1 - method2 => [0]
method1 - method3 => [0]
method2 - method3 => [0]
sqrt(2) + sqrt(2) => [2;1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,...]
sqrt(2) - sqrt(2) => [0]
1,448

edits