Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2): Difference between revisions
Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2) (view source)
Revision as of 22:53, 9 March 2023
, 1 year ago→{{header|C}}
Line 1,396:
mpz_init_set (tmp[i], env->ng[i]);
mpz_t *term = (!env->overflow) ? cf_ref (env->x, env->ix) : NULL;
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 (
{
env->overflow = true;
Line 1,416 ⟶ 1,415:
mpz_set (env->ng[ng8b1], tmp[ng8b1]);
}
▲ 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;
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 (
{
env->overflow = true;
Line 1,451 ⟶ 1,445:
}
}
▲ env->iy += 1;
}
Line 1,593 ⟶ 1,585:
{
size_t ncfstr = strlen (cfstr);
padding = string_repeat (MAX (
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, "
show ("(1 + 1/sqrt(2))/2", method2, "
show ("(1 + 1/sqrt(2))/2", method3, "
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,...]
silver ratio => [2;2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,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
(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
(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
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]
|