home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 3
/
goldfish_volume_3.bin
/
files
/
misc
/
math
/
picalc
/
picalc.doc
< prev
next >
Wrap
Text File
|
1995-09-27
|
9KB
|
226 lines
*******************************************************
piCalc - A program to find ¶ - pi - about 3.14159265...
*******************************************************
QUICKSTART:
From the shell type:
piCalc 1000
and piCalc will calculate and display 1000 decimal places of pi.
Requirements to using piCalc V2.6:
- Amiga with 68020 or better CPU (a FPU is not needed and not used anyway)
- Workbench/Kickstart 2.04 or better (I haven't tested it with less than 3.0)
- About 2.5 times as much bytes memory as the accuracy you want pi
- Time (and patience!)
It uses no external libraries.
This program is Freeware: It may be distributed freely for non-commercial
purposes. It should be free and a copying fee must not exceed £2.
This program may not be distributed with any magazine-coverdisk without
written permission. It may be included in any PD-library or on CDs including
PD software, such as the Fish, Aminet and other series including similar
free software.
The program and this docfile may not be changed or modified!
YOU USE THIS PROGRAM ON YOUR OWN RISK. THE AUTHOR CAN NOT AND WILL NOT
GUARANTEE ITS ACCURACY, NOR ANY OTHER DAMAGES ARISING FROM ANY USE OR
MISUSE OF THIS PROGRAM AND DOCUMENTATION.
If publishing a result produced by piCalc, please give credit to the author
and state which version of the program you used (V2.6).
History
-------
This program started as an AMOS program, which was able to calculate pi
to 80 decimal places, in JUST 35 MINUTES! (Amiga 1200) Because as we all know,
AMOS is not particularly fast, so I ported the program to assembler, the
first assembler version was able to calculate the first 1000 decimal places
in 5 minutes. But this wasn't good enough, so I optimised the
assembler-program to be many times faster than the original assembler-program.
That is the program "piCalc" V2.6 and runs 75,000 times faster than the
original (uncompiled) AMOS-program.
Version 1.0 - 1.7 were 68000 code versions, never released publically.
Version 2.0 - 2.4 were based on the 68020, never released.
Version 2.5 was released 16th of July 1995
Version 2.6 uses a better formula to calculate pi and stores pi in binary
internally: In total this makes version 2.6 more than 50% faster
than version 2.5. It's a bit more memory hungry though.
How to use it
-------------
piCalc is Shell/CLI-only utility. To use it you have to open a shell-window.
In its simplest form you write (from Shell)
You can always stop the program with Ctrl-C. (Exception: You can't Ctrl-C
piCalc when it's displaying/saving pi.)
"piCalc XXXXX" where XXXXX is the number of decimal places piCalc should
calculate.
The higher number of decimal places the more time the calculation will take.
If you think of calculating many decimal places (more than 20000) you should
run piCalc with the "ESTIMATE" option:
"piCalc estimate 100000" will estimate how much time a calculation of 100000
decimal places will take, so that you won't be surprised by how slow things
are going.
If you want to save the result to a file, use "SAVEFILE=filename", the result
will be written to this file when it has finished.
Those options in full
---------------------
Type "piCalc ?" for the piCalc Template:
DECIMALS/N,EVERY/N,SAVEFILE,SAVEEVERY/N,NOTIFY/S,NOOUTPUT/S,ESTIMATE/S
DECIMALS
is the number of decimal places you want piCalc to calculate, this must be
between 1 and 2,147,483,647. Except when "ESTIMATE" is selected, you will
need about 2.5 times as much memory free as the number of decimal places you
want to calculate pi to. (e.g. 1,000,000 decimal places requires about 2.5 MB
memory, in 6 chunks of <400 kb)
(If not specified, the program uses 50 decimal places)
EVERY
is how often you want piCalc to output its current calculation of pi. If you
use "EVERY 10000" piCalc will output to screen (StdOut) when it has 10000,
20000, 30000 and so on of decimal places. This option is probably most useful
when used with the "NOTIFY" option.
SAVEFILE
when specified piCalc will save its calculation to the specified file, this
it a much nicer method than running piCalc with a ">" redirection file.
Beware: If piCalc can't create this file it would not give any error messages,
just continue on!
SAVEEVERY
specifies how often piCalc should save its current calculation to SAVEFILE.
NOTIFY
is a very useful option in conjunction with the EVERY and SAVEFILE
options. It notifies you how far it has come, writing "Dec: XXXX" to the
Shell-window, where XXXX is how many decimal places it has calculated so
far, so you have some kind of control of the process.
Write NOTIFY EVERY 1000 to have piCalc notify you every time it has
calculated 1000 new decimal places.
NOOUTPUT
is useful when you use the SAVEFILE option and don't want the pi to be
echoed to screen as this can take quite a while with many decimal places.
ESTIMATE
will estimate the TIME needed to calculate pi. The estimating may take
a number of seconds (5-20) but will display a rough indication on how
long the calculation will take: You should not touch the mouse or keyboard
during this test, as this will cause piCalc to over-estimate the time needed.
Is piCalc calculating the right value for pi?
---------------------------------------------
I can not and will not guarantee the result produced by piCalc, it though
seems to print the right values. Browsing through old editions of
"The Guinness Book of Records" under "Most accurate version of 'pi'" I have
been able to check some parts of the results.
In the 1980 edition, I found this description of pi: 3.141592653589793 ...
(omitting the next 999,975 places) ... 5779458151
Those last 10 decimal places compared exactly to the result produced by
piCalc 1000000, using the same method I have checked the decimal places
before 100000 and 500000 to piCalc and found them to be the same, so piCalc
seems to give correct values for pi.
The first 50000 decimal places have been compared to those found in several
WWW-homepages. (Guess: They were the same!)
In the "E" Amiga programming environment there is a demo program, "pi.e"
which besides that its much slower than piCalc produces the wrong number
when you choose any high number, so better use piCalc!
Please don't have a large number of other programs running when piCalc
is busy calculating. A single bug in any of the programs running alongside
piCalc could accidentally write to a memory location used by piCalc and
giving a wrong result as piCalc does absolutely NONE checking on the
result as this would decrease performance considerably.
Program technicals (programmers)
---------------------------------
This program uses 32/64 bit integer math, using the Mulu.L/Divu.L instructions
heavily. The speed of this program therefore is largely dependent on the speed
the CPU carries out such multiplications and dividitions. The program stores
PI in one long chunk of binary, where each longword represents about
Why is 68020 required?
Just because I was able to make the program 3 times faster when I could
68020 instructions instead of 68000 only. For 68060 users this may not be
the fact though, as these 68020 instructions are NOT supported by the 68060
and have to be emulated, so 68060 & piCalc 2.6 is not a fast combination...
sorry. Contact me if you have an 68060!!!
Program technicals (math)
-------------------------
Calculation method used in piCalc 2.5: (Sorry, I gave a wrong formula in
the piCalc 2.5 documentation)
16/(1*5^1) - 16/(3*5^3) + 16/(5*5^5) - 16/(7*5^7) + 16/(9*5^9)...
- 4/(1*239^1) + 4/(3*239^3) - 4/(5*239^5) + 4/(7*239^7) - 4/(9*239^9)...
New formula used in piCalc 2.6:
pi/4 = 44*arctan(1/57) +7*arctan(1/239) -12*arctan(1/682) +24*arctan(1/12493)
where arctan(1/x) is calculated: 1/x - 1/(3*x^3) + 1/(5*x^5) - 1/(7*x^7) ...
If you know a better formula/method or know another pi-calculation program
(that is faster), please email/write to me!
Author
------
Write if you know of any SERIOUS bugs (pi is not accurate, fails on 68060,
etc.) If you have calculated pi with more than 1,000,000 decimal places using
this program or know a more efficient formula or another Amiga program that
is faster, please write!
Also look out for eCalc V2.6 that is identical to piCalc V2.6 except that it
calculates e=2.718281828459045... (and it's much faster than piCalc)
My email-address is: steffent@stud.unit.no
My WWW-homepage is: http://www.stud.unit.no/~steffent (it's rather small
currently...)
My snail-mail address: (safe, but slow: 1-3 weeks)
Steffen Thorsen
Fjordgt. 8a
N-4300 Sandnes
Norway
Snail-mail while im studying (usually fast, except during my holidays
(Christmas, Easter, Summer: [June-August]):
Steffen Thorsen
Stud.post 198, NTH
N-7043 Trondheim
Norway