aboutsummaryrefslogtreecommitdiffstats
path: root/buch/papers/0f1/listings/kettenbruchRekursion.c
blob: 958d4e1d480b89f9d2bef07bdffe1c9c52aaea35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
}