Ramanujan's constant: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
No edit summary
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 249:
262537412640768743.9999999999992500725971981856888793538563</pre>
 
=={{header|Perl 6Phix}}==
{{trans|Go}}
{{libheader|mpfr}}
<lang Phix>include mpfr.e
mpfr_set_default_prec(-120) -- (18 before, 100 after, plus 2 for kicks.)
function q(integer d)
mpfr pi = mpfr_init()
mpfr_const_pi(pi)
mpfr t = mpfr_init(d)
mpfr_sqrt(t,t)
mpfr_mul(t,pi,t)
mpfr_exp(t,t)
return t
end function
printf(1,"Ramanujan's constant to 100 decimal places is:\n")
mpfr_printf(1, "%.100Rf\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(), 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 100 decimal places is:
262537412640768743.9999999999992500725971981856888793538563373369908627075374103782106479101186073129511813461860645042
 
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|Raku}}==
(formerly Perl 6)
===Iterative calculations===
To generate a high-precision value for Ramanujan's constant, code is borrowed from three other Rosettacode tasks
Line 386 ⟶ 437:
<pre>Ramanujan's constant to 32 decimal places:
262537412640768743.99999999999925007259719818568888</pre>
 
=={{header|Phix}}==
{{trans|Go}}
{{libheader|mpfr}}
<lang Phix>include mpfr.e
mpfr_set_default_prec(-120) -- (18 before, 100 after, plus 2 for kicks.)
function q(integer d)
mpfr pi = mpfr_init()
mpfr_const_pi(pi)
mpfr t = mpfr_init(d)
mpfr_sqrt(t,t)
mpfr_mul(t,pi,t)
mpfr_exp(t,t)
return t
end function
printf(1,"Ramanujan's constant to 100 decimal places is:\n")
mpfr_printf(1, "%.100Rf\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(), 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 100 decimal places is:
262537412640768743.9999999999992500725971981856888793538563373369908627075374103782106479101186073129511813461860645042
 
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}}==
10,333

edits