Pathological floating point problems

Muller's sequence

func series (n) {
    var (u, v) = (2, -4)
    (n-2).times { (u, v) = (v, 111 - 1130/v + 3000/(v * u)) }
    return v
}

[(3..8)..., 20, 30, 50, 100].each {|n|
    printf("n = %3d -> %s\n", n, series(n))
}

Output:

n =   3 -> 18.5
n =   4 -> 9.3783783783783783783783783783783783783783783783784
n =   5 -> 7.801152737752161383285302593659942363112391930836
n =   6 -> 7.154414480975249353527890653860362024381233838197
n =   7 -> 6.806784736923632983941756596272009087623276707802
n =   8 -> 6.592632768704438392742002776365994826552982317735
n =  20 -> 6.043552110189268867777477364097540133187715000006
n =  30 -> 6.006786093031205758530554047953239705833072314438
n =  50 -> 6.000175846627187188945614020747195469523735177099
n = 100 -> 6.000000019319477929104086803403585715024350675437

The Chaotic Bank Society

Output:

Siegfried Rump's example

Output:

Last updated

Was this helpful?