Anonymous user
Pi: Difference between revisions
Added Tailspin solution
m (→{{header|Visual Basic .NET}}: wrapped output) |
(Added Tailspin solution) |
||
Line 5,191:
2000568127145263560827785771342757789609
...</pre>
=={{header|Tailspin}}==
Used the compact algorithm from [https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf Gibbons paper].
Tailspin will at some point have arbitrary precision integers, currently we have to link into java and use BigInteger. Using java code can be slightly awkward as the argument in Tailspin comes before the method, so divide and subtract read backwards.
<lang tailspin>
use 'java:java.math' stand-alone
def zero: 0 -> math/BigInteger::valueOf;
def one: 1 -> math/BigInteger::valueOf;
def two: 2 -> math/BigInteger::valueOf;
def three: 3 -> math/BigInteger::valueOf;
def four: 4 -> math/BigInteger::valueOf;
def seven: 7 -> math/BigInteger::valueOf;
def ten: 10 -> math/BigInteger::valueOf;
templates g&{q:, r:, t:, k:, n:, l:}
def u: $four -> q::multiply -> r::add;
def nt: $n -> t::multiply;
$ -> #
when <?($t -> u::subtract <..~$nt>)> do
$n -> !OUT::write
$ -> \(<=1> $!\) -> '.' -> !OUT::write
def v: $three -> q::multiply -> r::add -> ten::multiply;
def quot: $t -> v::divide;
0 -> g&{q: $ten -> q::multiply,
r: $nt -> r::subtract -> ten::multiply,
t: $t,
k: $k,
n: $ten -> n::multiply -> quot::subtract,
l: $l } !
otherwise
def tl: $t -> l::multiply;
def rl: $r -> l::multiply;
def term: $q -> seven::multiply -> k::multiply -> two::add -> rl::add;
$ -> g&{q: $q -> k::multiply,
r: $two -> q::multiply -> r::add -> l::multiply,
t: $tl,
k: $k -> one::add,
n: $tl -> term::divide,
l: $l -> two::add} !
end g
1 -> g&{q:$one, r:$zero, t:$one, k:$one, n:$three, l:$three} -> !VOID
</lang>
{{out}}
<pre>
3.141592653589793238462643383279502884197169399375105820974...keeps going until stopped.
</pre>
=={{header|Tcl}}==
|