Skip to content

SylwesterBogusiak/ComputePi

Repository files navigation

ComputePi

Calculate π

Pi value calculations with use different formulas.

The goal of this repository is to present a few algorithms that allow you to calculate π with a high level of precision.

In order to do this we use C language with math library and in some cases MPFR library is used. The MPFR library is open source project, and is dedicated when You use floating point numbers with lots of decimal places. Obviously the greater precision of number you use, the longer the calculation will take.

Logic behind the calculation

Each of the presented algorithms are in single c file. Each of it has unique name.

To compile source code best to use GCC.

To run the app from terminal You need to add few parameters. For example number of iterations or precision as number of decimal places used to calculate the final value.

When increase the the number of iterations, the more loops the calculation is run. When precision is higher processor compute same iteration much longer.

While the program is running does not give any output until the end of calculations.

At the end the value of Pi is printed and also the total time of calcuations.

Example usage:

./cpill1 1000 1000

Result

=================== PI for (n = 999): 3.142593654340043051026127768502212378655491381805237245745646878089181568058156812867473482582957851053314840753777580334655425308891884399468696472251832391611097631948860234406643155444226824961708419396662932306446416339821638437192773161404920125422017906491634858641728463229711830672950908240122440022413505992427623516528067359553034467708963303080265736972746800366914551863691787950646171743260309727071761822248557176182415740422622670834325138786617832376117890511114798104003715217832069164924829169433059113744611595699027085770181703754109011827415419219104417289000039152572126769380596973590795684326947722407450187352865244221252002554045949867927992833273218985782631341935948296939589904420887481709755743196852372725437468242452057978184352938003020382783417287921147462694161501939923043710086811342131324219395184527976554424817246308038173310475318525177744514155238443085309185507147325672456026618274483936422288430187707306032006285625990393839401804143562912940979003906250e0

=================== PI for (n = 1000): 3.144592654839793175963659002885020974357640307342468630053492955050700808437966907819997220713892383786948024162073432408618443799646507088124368636169873371121342509510079624711490731656120877935221662774973776884157560767607745383719509793089078046461498166361699826157970342290181595790392187600442140555909429948905087866956962229069701417353763695363640641055471961136647709250084207467953674978729579681600920736095051292191216776658236572369303941344206370271515898064856937371002724799047400865651344650769901911673433712945299494896258303354778596557573717868204394616127867558869364308239765146855120572329429220665731300072584868353768174720582767121439221910490985272180147740073489731315006762798137120104582453508155222148097660617964915907549165075147605869014677247842240114742270806593554363966158131692741030458859776616660597140080376770244742948058006351842416432494876295940514929073254534236470708015840319239321885695759325821418045431368537556693354417802765965461730957031250e0

Your calculations took 0.001 seconds to run.

If You want to print the result to the text file redirect standard output by simply add at the end > operator and the name of file.

Example:

./cpill1 1000 1000 > CPILL_1000_1000.txt

Algorithms used

Archimedes - CPIARCH - Compute Pi Archimedes algorithm.

Madhava-Gregory-Leibniz - CPILL1 - COMPUTE PI LONG LEIBNIZ V1

Madhava-Gregory-Leibniz - CPILL2 - COMPUTE PI LONG LEIBNIZ V2

Machin - MLPI - MACHIN-LIKE PI

Euler's - CPISE - COMPUTE PI STANDARD EULER'S

Euler's - CPILE - COMPUTE PI LONG EULER'S

Madhava - CPILM - Compute Pi Long Madhava.

Gauss-Legendre aka Brent-Salamin - CPIGLL - COMPUTE PI GAUSS-LEGENDRE LONG

and for other Pi values related with Golden Ratio and Golden Number Phi

FDSPHIPI algorithm - Four div by squared Phi - JAIN PI

FTSPHIPI algorithm - Four Times Squared phi - JAIN PI

FTSPHIPI2 algorithm - Four Times Squared phi - JAIN PI

extra

BRESPI - BRESENHAM AND PI CIRCLES IN COLOURS OF R G B - for testing the Pi values with drawing circles

To do

Ramanujan-Sato

Chudnovsky

Bailey-Borwein-Plouffe

Newton

Other

Links

More info and results here: www.bogusiak.pl

About

Pi value calculations with use different formulas.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages