Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You will remember something that you should not have forgotten.


sci / sci.crypt / Re: Found this old C code to calculate Pi

SubjectAuthor
* Found this old C code to calculate PiCri-Cri
`* Re: Found this old C code to calculate PiCri-Cri
 `* Re: Found this old C code to calculate PiStefan Claas
  `- Re: Found this old C code to calculate PiCri-Cri

1
Subject: Found this old C code to calculate Pi
From: Cri-Cri
Newsgroups: sci.crypt
Organization: Easynews - www.easynews.com
Date: Sun, 16 Jun 2024 20:43 UTC
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx13.ams4.POSTED!not-for-mail
From: cri@cri.cri.invalid (Cri-Cri)
Subject: Found this old C code to calculate Pi
Newsgroups: sci.crypt
MIME-Version: 1.0
x-hc-9: yes
x-no-archive: yes
User-Agent: Pan/0.157 (Mariinka; 7c3c6087)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 74
Message-ID: <U7IbO.120739$RcM6.4693@fx13.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sun, 16 Jun 2024 20:43:32 GMT
X-Received-Bytes: 3013
View all headers

It only does 9 digits at a time, so I wrapped it in some Python to get all
decimals in one blow. Results are sort of interesting, but it gets
increasingly slower:

$ time python make-pie.py 1000
141592653589793238462643383279502884197...

real 0m2,378s
user 0m2,279s
sys 0m0,097s

$ time python make-pie.py 2000
141592653589793238462643383279502884197...

real 0m16,254s
user 0m16,009s
sys 0m0,232s

I dare not run it with 10,000 decimals, or it'll probably sit there for a
week.

I've checked the first 1,000 and it seems to be exactly like online lists
of decimals.

You have to imagine the "3." in the beginning of it.

That Leibnitz formula is also interesting, but it takes forever to yield
but a handful of decimals.

The readme in the C file reads:

* Computation of the n'th decimal digit of pi with very little memory.
* Written by Fabrice Bellard on February 26, 1997.
*
* We use a slightly modified version of the method described by Simon
* Plouffe in "On the Computation of the n'th decimal digit of various
* transcendental numbers" (November 1996). We have modified the algorithm
* to get a running time of O(n^2) instead of O(n^3log(n)^3).
*
* This program uses a variation of the formula found by Gosper in 1974 :
*
* pi = sum( (25*n-3)/(binomial(3*n,n)*2^(n-1)), n=0..infinity);
*
* This program uses mostly integer arithmetic. It may be slow on some
* hardwares where integer multiplications and divisons must be done by
* software. We have supposed that 'int' has a size of at least 32 bits.
* If your compiler supports 'long long' integers of 64 bits, you may use
* the integer version of 'mul_mod' (see HAS_LONG_LONG).

Using LONG LONG I get the following:

1,000 decimals:

real 0m1,943s
user 0m1,835s
sys 0m0,107s

2,000 decimals:

real 0m12,854s
user 0m12,639s
sys 0m0,202s

It's about 250 lines of C.

https://bellard.org/pi/ (depending on security settings you may have to
reload the page as http instead of https, SSL certificate warning)

Are there any quicker things out there, that a normal, non C programmer
can use? I suppose some type of Cuda thing would be way faster, but I
don't have that.

--
Cri-Cri

Subject: Re: Found this old C code to calculate Pi
From: Cri-Cri
Newsgroups: sci.crypt
Organization: Easynews - www.easynews.com
Date: Tue, 18 Jun 2024 19:51 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx06.ams4.POSTED!not-for-mail
From: cri@cri.cri.invalid (Cri-Cri)
Subject: Re: Found this old C code to calculate Pi
Newsgroups: sci.crypt
References: <U7IbO.120739$RcM6.4693@fx13.ams4>
MIME-Version: 1.0
x-hc-9: yes
x-no-archive: yes
User-Agent: Pan/0.157 (Mariinka; 7c3c6087)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 10
Message-ID: <tzlcO.57813$bHO6.53390@fx06.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Tue, 18 Jun 2024 19:51:53 GMT
X-Received-Bytes: 1030
View all headers

On Sun, 16 Jun 2024 20:43:32 GMT, Cri-Cri wrote:

> It's about 250 lines of C.

I found a smaller and faster algorithm, but it only creates 800 decimals,
under 0.015 seconds:
https://crypto.stanford.edu/pbc/notes/pi/code.html

--
Cri-Cri

Subject: Re: Found this old C code to calculate Pi
From: Stefan Claas
Newsgroups: sci.crypt
Organization: ℭ𝔥𝔦𝔣𝔣𝔯𝔢𝔭𝔲𝔫𝔨𝔰
Date: Tue, 18 Jun 2024 20:40 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: pollux@tilde.club (Stefan Claas)
Newsgroups: sci.crypt
Subject: Re: Found this old C code to calculate Pi
Date: Tue, 18 Jun 2024 22:40:54 +0200
Organization: ℭ𝔥𝔦𝔣𝔣𝔯𝔢𝔭𝔲𝔫𝔨
𝔰
Message-ID: <v4srcm$cnon$3@i2pn2.org>
References: <U7IbO.120739$RcM6.4693@fx13.ams4>
<tzlcO.57813$bHO6.53390@fx06.ams4>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 18 Jun 2024 20:40:54 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="417559"; mail-complaints-to="usenet@i2pn2.org";
posting-account="uWi4uQdALkj7ETOfPbhNXfz0+Ra/gM5z6/Fa40dJi9U";
Finger: tilde.club/~pollux/
X-Spam-Checker-Version: SpamAssassin 4.0.0
View all headers

Cri-Cri wrote:

> On Sun, 16 Jun 2024 20:43:32 GMT, Cri-Cri wrote:
>
> > It's about 250 lines of C.
>
> I found a smaller and faster algorithm, but it only creates 800 decimals,
> under 0.015 seconds:
> https://crypto.stanford.edu/pbc/notes/pi/code.html
>

You should check GitHub, for lot's of pi programs.

Simply enter there 'compute pi', or something similar
and it should show you many repositories, in various
programming languages.

--
Regards
Stefan

Subject: Re: Found this old C code to calculate Pi
From: Cri-Cri
Newsgroups: sci.crypt
Organization: Easynews - www.easynews.com
Date: Tue, 18 Jun 2024 20:53 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.szaf.org!news.bawue.net!npeer.as286.net!npeer-ng0.as286.net!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx06.ams4.POSTED!not-for-mail
From: cri@cri.cri.invalid (Cri-Cri)
Subject: Re: Found this old C code to calculate Pi
Newsgroups: sci.crypt
References: <U7IbO.120739$RcM6.4693@fx13.ams4>
<tzlcO.57813$bHO6.53390@fx06.ams4> <v4srcm$cnon$3@i2pn2.org>
MIME-Version: 1.0
x-hc-9: yes
x-no-archive: yes
User-Agent: Pan/0.157 (Mariinka; 7c3c6087)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 8
Message-ID: <VsmcO.57939$bHO6.38607@fx06.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Tue, 18 Jun 2024 20:53:09 GMT
X-Received-Bytes: 996
View all headers

On Tue, 18 Jun 2024 22:40:54 +0200, Stefan Claas wrote:

> You should check GitHub, for lot's of pi programs.

Good idea. Thanks. :)

--
Cri-Cri

1

rocksolid light 0.9.8
clearnet tor