forked from s-e-a-m/faust-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seamPI.lib
67 lines (57 loc) · 2.96 KB
/
seamPI.lib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//############################################################ seamPI.lib ###
//
// A library for the implementation of the Chudnovsky algorithm for calculating the digits of π.
//
//##############################################################################
/*******************************************************************************
Except where noted otherwise, Copyright (C) 2019-2020 by SEAM
GRAME LICENSE
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with the GNU C Library; if not, write to the Free Software Foundation, Inc., 59
Temple Place, Suite 330, Boston, MA 02111-1307 USA.
EXCEPTION TO THE LGPL LICENSE : As a special exception, you may create a larger
FAUST program which directly or indirectly imports this library file and still
distribute the compiled code generated by the FAUST compiler, or a modified
version of this compiled code, under your own copyright and license. This
EXCEPTION TO THE LGPL LICENSE explicitly grants you the right to freely choose
the license for the resulting compiled code. In particular the resulting compiled
code has no obligation to be LGPL or GPL. For example you are free to choose a
commercial or closed source license or any other license if you decide so.
*******************************************************************************/
declare name "PI Chudnovsky algorithm";
declare version "0.1";
declare author "Davide Tedesco";
declare license "CC4";
//factorial(0) = 1;
//factorial(x) = x*(factorial(x-1));
//k = 0 ;//constant for the calculation
c = 42880 : *(10005 : sqrt);
//sommatoria(k) = (m(k) : *l(k))/x(k);
seampi = c;//:(*sommatoria(k) : inv) ;
// from decimal import Decimal as Dec, getcontext as gc
//
// def PI(maxK: int = 70, prec: int = 1008, disp: int = 1007): # Parameter defaults chosen to gain 1000+ digits within a few seconds
// gc().prec = prec
// K, M, L, X, S = 6, 1, 13591409, 1, 13591409
// for k in range(1, maxK + 1):
// M = (K**3 - 16*K) * M // k**3
// L += 545140134
// X *= -262537412640768000
// S += Dec(M * L) / X
// K += 12
// pi = 426880 * Dec(10005).sqrt() / S
// pi = Dec(str(pi)[:disp]) # Drop few digits of precision for accuracy
// print("PI(maxK={} iterations, gc().prec={}, disp={} digits) =\n{}".format(maxK, prec, disp, pi))
// return pi
//
// Pi = PI()
// print("\nFor greater precision and more digits (takes a few extra seconds) - Try")
// print("Pi = PI(317, 4501, 4500)")
// print("Pi = PI(353, 5022, 5020)")