aboutsummaryrefslogtreecommitdiffstats
path: root/buch/papers/0f1/listings/kettenbruchRekursion.c
diff options
context:
space:
mode:
Diffstat (limited to 'buch/papers/0f1/listings/kettenbruchRekursion.c')
-rw-r--r--buch/papers/0f1/listings/kettenbruchRekursion.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/buch/papers/0f1/listings/kettenbruchRekursion.c b/buch/papers/0f1/listings/kettenbruchRekursion.c
new file mode 100644
index 0000000..958d4e1
--- /dev/null
+++ b/buch/papers/0f1/listings/kettenbruchRekursion.c
@@ -0,0 +1,19 @@
+static double fractionIter0f1(const double b0, const double z, unsigned int n)
+{
+ double a = 0.0;
+ double b = 0.0;
+ double abn = 0.0;
+ double temp = 0.0;
+
+ for (; n > 0; --n)
+ {
+ abn = z / (n * ((n - 1) + b0)); //abn = ak, bk
+
+ a = n > 1 ? (1 + abn) : 1; //a0, a1
+ b = n > 1 ? -abn : abn; //b1
+
+ temp = b / (a + temp);
+ }
+
+ return a + temp; //a0 + temp
+} \ No newline at end of file