23 lines
986 B
Text
23 lines
986 B
Text
function continued_fraction(integer steps, integer rid_a, integer rid_b)
|
|
atom res = 0
|
|
for n=steps to 1 by -1 do
|
|
res := call_func(rid_b,{n}) / (call_func(rid_a,{n}) + res)
|
|
end for
|
|
return call_func(rid_a,{0}) + res
|
|
end function
|
|
|
|
function sqr2_a(integer n) return iff(n=0?1:2) end function
|
|
function sqr2_b(integer n) return 1 end function
|
|
|
|
function nap_a(integer n) return iff(n=0?2:n) end function
|
|
function nap_b(integer n) return iff(n=1?1:n-1) end function
|
|
|
|
function pi_a(integer n) return iff(n=0?3:6) end function
|
|
function pi_b(integer n) return iff(n=1?1:power(2*n-1,2)) end function
|
|
|
|
constant precision = 10000
|
|
|
|
printf(1,"Precision: %d\n", {precision})
|
|
printf(1,"Sqr(2): %.10g\n", {continued_fraction(precision, routine_id("sqr2_a"), routine_id("sqr2_b"))})
|
|
printf(1,"Napier: %.10g\n", {continued_fraction(precision, routine_id("nap_a"), routine_id("nap_b"))})
|
|
printf(1,"Pi: %.10g\n", {continued_fraction(precision, routine_id("pi_a"), routine_id("pi_b"))})
|