Ramanujan's constant: Difference between revisions

(→‎{{header|Perl}}: calculation via continued fractions)
Line 276:
<pre>Ramanujan's constant to 32 decimal places:
262537412640768743.99999999999925007259719818568888</pre>
 
=={{header|Phix}}==
{{trans|Go}}
<lang Phix>include mpfr.e
 
constant dp_rqd = 18+32+2, -- (18 before, 32 after, plus 2 for kicks.)
precision_rqd = mpz_sizeinbase(mpz_init(repeat('9',dp_rqd)),2)
 
function q(integer d)
mpfr pi = mpfr_init(precision:=precision_rqd)
mpfr_const_pi(pi)
mpfr t = mpfr_init(d,precision:=precision_rqd)
mpfr_sqrt(t,t)
mpfr_mul(t,pi,t)
mpfr_exp(t,t)
return t
end function
printf(1,"Ramanujan's constant to 32 decimal places is:\n")
mpfr_printf(1, "%.32Rf\n", q(163))
sequence heegners = {{19, 96},
{43, 960},
{67, 5280},
{163, 640320},
}
printf(1,"\nHeegner numbers yielding 'almost' integers:\n")
mpfr t = mpfr_init(precision:=precision_rqd), qh
mpz c = mpz_init()
for i=1 to length(heegners) do
integer {h0,h1} = heegners[i]
qh = q(h0)
mpz_ui_pow_ui(c,h1,3)
mpz_add_ui(c,c,744)
mpfr_set_z(t,c)
mpfr_sub(t,t,qh)
string qhs = mpfr_sprintf("%51.32Rf",qh),
cs = mpz_get_str(c),
ts = mpfr_sprintf("%.32Rf",t)
printf(1,"%3d: %s ~= %18s (diff: %s)\n", {h0, qhs, cs, ts})
end for</lang>
{{out}}
<pre>
Ramanujan's constant to 32 decimal places is:
262537412640768743.99999999999925007259719818568888
 
Heegner numbers yielding 'almost' integers:
19: 885479.77768015431949753789348171962682 ~= 885480 (diff: 0.22231984568050246210651828037318)
43: 884736743.99977746603490666193746207858538 ~= 884736744 (diff: 0.00022253396509333806253792141462)
67: 147197952743.99999866245422450682926131257863 ~= 147197952744 (diff: 0.00000133754577549317073868742137)
163: 262537412640768743.99999999999925007259719818568888 ~= 262537412640768744 (diff: 0.00000000000074992740280181431112)
</pre>
 
=={{header|REXX}}==
7,805

edits