Click to See Complete Forum and Search --> : Pi
appi101
Aug 4th, 2001, 07:26 PM
Hi
How can we find the value of pi in VB
Appi.
kedaman
Aug 5th, 2001, 04:07 AM
Pi is not a built in constant, you can declare it like this:
Const pi As Double = 3.14159265358979
appi101
Aug 6th, 2001, 04:46 AM
HI
I meant How to keep on getting more and more accurate values of pi, like computing it to say 1 million places of decimal
kedaman
Aug 6th, 2001, 05:09 AM
atn(1)*4 gives pi, and arcus tangens can be written as a series:
atn(x) = x - x^3/3+x^5/5-x^7/7...
therefore
pi = sumof( 4/(n*4-3)-4/(n*4-1))
you just need to work out the operations on say a byte array, because there's no huge datatype. You need addition, substraction and division.
nishantp
Aug 8th, 2001, 07:59 AM
I cant imagine what use you would have for Pi calculated to 1000000 decimals, however if all you want to do is calculate it...then you should know its been done and is probably available on the internet.
kedaman
Aug 8th, 2001, 08:15 AM
for fun :p
SteveCRM
Aug 21st, 2001, 11:39 PM
22/7
nishantp
Aug 22nd, 2001, 10:49 AM
You could hard code a division functions that uses human techniques (long-division) and return a string. Technically you could return about (2^64) -2 decimals...it might take a while though:D
HarryW
Aug 22nd, 2001, 11:17 AM
Pi is an irrational number so simply finding the decimal representation of a fraction isn't what needs to be done.
I don't actually know what the formal mathematical definition of Pi is, other than it being the ratio of a circle's diameter to its circumference. Kedaman's sum of a converging series looks probable though.
HarryW
Aug 22nd, 2001, 11:20 AM
Oh, and incidentally, if I was doing this I'd use Python for its built-in long datatype which is only limited in size by the amount of RAM you have plus virtual memory (string representation of the number).
If you're doing it in VB you may have to code an extra long datatype yourself.
kedaman
Aug 22nd, 2001, 11:24 AM
What kind of operations can you do on the long datatype?
nishantp
Aug 22nd, 2001, 11:40 AM
Well if all you want is the value of 22/7 to a LOT of decimals (dont see the point) this would work. Its crude, but it works fine.
Function LongDivision(ByVal Num As Long, ByVal Den As Long, ByVal Decimals As Long) As String
Dim i As Long
Dim Dec1 As Long
Dim Dec3 As Long
Dim StrOut As String
Dim DecimalAdd As Boolean
For i = 1 To Decimals
Dec1 = Int(Num / Den)
StrOut = StrOut & Dec1
If Not DecimalAdd Then
StrOut = StrOut & "."
DecimalAdd = True
End If
Dec3 = (Num - (Dec1 * Den)) * 10
Num = Dec3
Next
LongDivision = StrOut
End Function
This can technically return up to (2^64) -2 decimals...but i dont suggest trying that...:p
HarryW
Aug 22nd, 2001, 12:40 PM
Ked, you can do whatever you like with it really. Just treat it as a normal integer. Might be a little slower obviously.
nishantp
Aug 22nd, 2001, 01:48 PM
Originally posted by HarryW
Oh, and incidentally, if I was doing this I'd use Python for its built-in long datatype which is only limited in size by the amount of RAM you have plus virtual memory (string representation of the number).
If you're doing it in VB you may have to code an extra long datatype yourself. Where is the Python available? Like is it free?
kedaman
Aug 22nd, 2001, 02:54 PM
obviously it could be a lot slower, one cpu instruction for a regular 32bit integer addition, 20 or more for 64
banij
Aug 23rd, 2001, 08:39 AM
Slightly off topic (and I did register just to post this! tells something about my personality :) )
WARNING: Do NOT calculate Pi in binary. It is conjectured that this number is normal, meaning that it contains ALL finite bit strings.
If you compute it, you will be guilty of:
Copyright infringement (of all books, all short stories, all newspapers, all magazines, all web sites, all music, all movies, and all software, including the complete Windows source code)
Trademark infringement
Possession of child pornography
Espionage (unauthorized possession of top secret information)
Possession of DVD-cracking software
Possession of threats to the President
Possession of everyone's SSN, everyone's credit card numbers, everyone's PIN numbers, everyone's unlisted phone numbers, and everyone's passwords
Defaming Islam. Not technically illegal, but you'll have to go into hiding along with Salman Rushdie.
Defaming Scientology. Which IS illegal -- just ask Keith Henson.
Also, your computer will contain all of the nastiest known computer viruses. In fact, all of the nastiest POSSIBLE computer viruses.
Some of the files on my PC are intensely personal, and I for one don't want you snooping through a copy of them.
You might get away with computing just a few digits, but why risk it? There's no telling how far into Pi you can go without finding the secret documents about the JFK assassination, a photograph of your neighbor's six year old daughter doing the nasty with the family dog, or a complete copy of the not-yet-released Pearl Harbor movie. So just don't do it.
The same warning applies to e, the square root of 2, Euler's constant, Phi, the cosine of any non-zero algebraic number, and the vast majority of all other real numbers.
There's a reason why these numbers are always computed and shown in decimal, after all.
[(c) ? sorry, from the depths of the net, and there was no author given when I got it]
kedaman
Aug 23rd, 2001, 08:53 AM
There is no information without a context.
btw, if i could find the decimal indexes for all the mp3's I have, that would be a rather huger format to store them in.
appi101
Aug 23rd, 2001, 09:44 AM
So how will we calculate the value of pi, to say 10 million places of decimal. What do you mean work on a byte array, and how do we find the sumof( 4/(n*4-3)-4/(n*4-1)) and how do we find it. I am new to this kind of math and processing this kind of math.
When I use a for loop like this
dim a as double, b as double
a = 1
For i = 2 To 1000000
b = (-1) ^ i
a = a - b / i
Next i
where a = pi/4 (the series pi/4=1-1/3+1/5-1/7----) I just get the value till some 7-10 places of decimal. How do I increase it.
Appi
kedaman
Aug 23rd, 2001, 10:03 AM
You can't, because there's no support for that in vb. The decimal datatype is the biggest integer datatype and it is extreemly slow. There should be a thread somewhere around in chitchat in which some algoritms was made to handle huge integers
HarryW
Aug 23rd, 2001, 11:41 AM
Python is completely free and is commonly used by scientists for this kind of stuff, although you wouldn't want to use it for anything performance-critical like calculating pi to however many billion decimal places. It would be fine for calculating to a few thousand or something though.
You can get the latest version (Python 2.1) from www.python.org
Also has a built-in complex datatype if you need it.
appi101
Aug 23rd, 2001, 09:38 PM
Hi
I'll search around the forums. Maybe I find something.
Thanks for the help
Appi
DaoK
Aug 23rd, 2001, 09:41 PM
Pi = 3.141592551104866223558431126381048812355898112276391048823661691
12648104891237105711355110577023712221136511058672371277113652105
86823713861136671058762371496113682105891237171611369410589123723
75113696105806987498576984769847609873409867439857694387569803475
28937465283974658927364587923645897236458723645987236859742365298
76458726345897623897465283746587293465897236458726458972436952384
92322547392938475623987562897465298376598726549872365987236598726
87968197871987261987618719876187632198716239874168971236489761238
97641238976143298761911010101032178648764387263874687638763286234
23189432943213458745984753489760975645784326574365743256743657432
65743256743265743276543265743265743268743268743268743268732468742
38763468727364872364872634872634876238476287346872164872648726348
71623487216348762138746218764318726348712634876123876482173647126
34872163487621387462873647213648271364872136487126348726487126387
62487263847623876418276348716234871623874682734687126348721634872
61873461287364871263487126348761238746128736418732648712648754354
39875438935409453809543805349854309854309801010101029389813287243
87634287643287648723648762384762387462873648726348726348726348726
34876234876238746328746238764827364827346282828736482764828238723
76464626237646273462876482736487263487263487263486243876234873264
67843114691106720238467811469810672123847881147001067212385008114
72210672123853371147321067212385447114742106721238566711475010672
12385887114751106722238599611476810672323865461147691067242386656
11481410676923874241148341067892387534114835106790238819311483910
67902388303114843106790238863311484810679123895671148511067942389
62111485210679523897311148571067962389841114865106796239011611488
51067962390171114897106796239050011492110679623906101149271067962
39313711502410688123932471150251068822395883115036106892239599311
50371068932397641115052106899239764111505310690024121411153411071
72241230611550410733524124151155171073392412800115523107345241291
01155771073562413020115578107357241334911559810737524135691156001
07377241549111571610749324155461157171074942420489115728107498224
12306115504107335241241511551714600106719238292111460610671923830
30114634106719238314011465010671923836901146521067192383909114654
10671923841291146661067192384349114676106719238445911469010671923
84568114691106720238467811469810672123847881147001067212385008114
72210672123853371147321067212385447114742106721238566711475010672
12385887114751106722238599611476810672323865461147691067242386656
11481410676923874241148341067892387534114835106790238819311483910
67902388303114843106790238863311484810679123895671148511067942389
62111485210679523897311148571067962389841114865106796239011611488
51067962390171114897106796239050011492110679623906101149271067962
39313711502410688123932471150251068822395883115036106892239599311
50371068932397641115052106899239764111505310690024121411153411071
72241230691237270511370010589323733641137241058942373474113726105
89423736931137361058942374023113750105894237616511386910601223803
39114418106555238044911452010665723806141145361066692380724114550
10668123810531145621066812381273114564106683238182211458110670023
82481114587106706238259111460010671923829211146061067192383030114
63410671923831401146501067192383690114652106719238390911465410671
92384129114666106719238434911467610671923844591146901067192384568
91237270511370010589323733641137241058942373474113726105894237369
31137361058942374023113750105894237616511386910601223803391144181
06555238044911452010665723806141145361066692380724114550106681238
10531145621066812381273114564106683238182211458110670023824811145
87106706238259111460010671923829211146061067192383030114634106719
23831401146501067192383690114652106719238390911465410671923841291
49853984759837459837498573984758324759254786324785698788881466610
45457634875634876532765978659872364598723645987264598723645987326
45987632498756328974652389746598372645987364598736459876324987562
39874653987465298376459873264589763249875632984765239874659873264
59873264598762348756239847653298746582376458972364587263485976328
76984357693845769384075698347569843756912365231047256148752198769
87987787985764398787694123765423764587349060670984587567263579879
12316564765230987098347654874869346426765476547858435435435643543
89423736931137361058942374023113750105894237616511386910601223803
39114418106555238044911452010665723806141145361066692380724114550
10668123810531145621066812381273114564106683238182211458110670023
82481114587106706238259111460010671923829211146061067192383030114
63410671923831401146501067192383690114652106719238390911465410671
92384129114666106719238434911467610671923844591146901067192384568
91237270511370010589323733641137241058942373474113726105894237369
31137361058942374023113750105894237616511386910601223803391144181
06555238044911452010665723806141145361066692380724114550106681238
10531145621066812381273114564106683238182211458110670023824811145
87106706238259111460010671923829211146061067192383030114634106719
23831408753984759874598374598374598374597349587349857398475938475
98374598371146501067192383690114652106719238390911465410671923841
29114666106715983759837495873498573984983609850968409586094586094
85069892384349114676106719238445911469010671923845682349691112621
10486622355843112638104881235589811263910488236616911264810489123
71057113551105770237122211365110586723712771136521058682371386113
66710587623714961136821058912371716113694105891237237511369610589
48573874659827645873645897326589763245897623489756389746538746538
74652987346592873645987236459872634985763294857629387465923846593
92322547392938475623987562897465298376598726549872365987236598726
87968197871987261987618719876187632198716239874168971236489761238
56435435435435435432143214332144521321213542154343521354213542134
72210672123853371147321067212385447114742106721238566711475010672
12385887114751106722238599611476810672323865461147691067242386656
11481410676923874241148341067892387534114835106790238819311483910
67902388303114843106790238863311484810679123895671148511067942389
62111485210679523897311148571067962389841114865106796239011611488
51067962390171114897106796239050011492110679623906101149271067962
39313711502410688123932471150251068822395883115036106892239599311
50371068932397641115052106899239764111505310690024121411153411071
72241230691237270511370010589323733641137241058942373474113726105
89423736931137361058942374023113750105894237616511386910601223803
39114418106555238044911452010665723806141145361066692380724114550
10668123810531145621066812381273114564106683238182211458110670023
82481114587106706238259111460010671923829211146061067192383030114
63410671923831401146501067192383690114652106719238390911465410671
92384129114666106719238434911467610671923844591146901067192384568
91237270511370010589323733641137241058942373474113726105894237369
31137361058942374023113750105894237616511386910601223803391144181
06555238044911452010665723806141145361066692380724114550106681238
10531145621066812381273114564106683238182211458110670023824811145
87106706238259111460010671923829211146061067192383030114634106719
23831408753984759874598374598374598374597349587349857398475938475
98374598371146501067192383690114652106719238390911465410671923841
29114666106715983759837495873498573984983609850968409586094586094
85069892384349114676106719238445911469010671923845682349691112621
10486622355843112638104881235589811263910488236616911264810489123
71057113551105770237122211365110586723712771136521058682371386113
66710587623714961136821058912371716113694105891237237511369610589
48573874659827645873645897326589763245897623489756389746538746538
74652987346592873645987236459872634985763294857629387465923846593
24589234503245234534850234578320467045608574976485976409567045607
46507546094675049857640567840956784098576498759870937097098127980
17981789237498275409834709210910983175483750983720072789023487957
84570983745098746580976543789654379863457980657980564379865437980
63409857643098567809654370986543789654379865347980654379863450987
63049857609834576098347569083475609873450986734098576039845769084
35760984576098347560987435908674530987603948576098435760983457609
83475609834709687430986743098576943058760984357609834576098437560
98435760984756983475609843756984357690856098760980910910982310948
02938409321840928340921830941803980198409218430910930943218094321
80943210984320983420984398065890896048906490842853280981098210943
6654387653487645876348576348576348756384765387465837
DaoK
Aug 23rd, 2001, 09:42 PM
But this is a link who show how to calculate it :
http://forum.swarthmore.edu/~isaac/problems/pi1.html
and
http://gallery.uunet.be/kurtvdb/pi.html
sail3005
Aug 26th, 2001, 02:05 AM
warning though. It takes hours to calculate it to just say the 30th decimal place. I have done it before, so i doubt you are gonna get to 10,000,000. :D
appi101
Aug 26th, 2001, 09:37 PM
Hi
HOw will we do that in VB
APpi
sail3005
Aug 26th, 2001, 09:42 PM
do what in VB? Calculate pi?
Use the series that kedaman posted above. There are other ways, but a series is probably the best.
I say calculating PI should be left to the super computers, and not VB though. :p
appi101
Aug 27th, 2001, 05:20 AM
Hi
How will we calculate pi in VB using that series>
Appi
mlewis
Aug 27th, 2001, 12:56 PM
FORGET IT!!!!!!! It will take you literal days to get to say 5000 digits; 10million is impossible with VB; it would take you until the world explodes from all of the dinosaur crap in the core. Which will never happen cuz dinosaurs are extinct...perhaps they will be resurected, but it will take a while...
sail3005
Aug 27th, 2001, 02:54 PM
Pi = 3.141592551104866223558431126381048812355898112276391048823661691
12648104891237105711355110577023712221136511058672371277113652105
86823713861136671058762371496113682105891237171611369410589123723
75113696105806987498576984769847609873409867439857694387569803475
28937465283974658927364587923645897236458723645987236859742365298
76458726345897623897465283746587293465897236458726458972436952384
92322547392938475623987562897465298376598726549872365987236598726
87968197871987261987618719876187632198716239874168971236489761238
97641238976143298761911010101032178648764387263874687638763286234
23189432943213458745984753489760975645784326574365743256743657432
65743256743265743276543265743265743268743268743268743268732468742
38763468727364872364872634872634876238476287346872164872648726348
71623487216348762138746218764318726348712634876123876482173647126
34872163487621387462873647213648271364872136487126348726487126387
62487263847623876418276348716234871623874682734687126348721634872
61873461287364871263487126348761238746128736418732648712648754354
39875438935409453809543805349854309854309801010101029389813287243
87634287643287648723648762384762387462873648726348726348726348726
34876234876238746328746238764827364827346282828736482764828238723
76464626237646273462876482736487263487263487263486243876234873264
67843114691106720238467811469810672123847881147001067212385008114
72210672123853371147321067212385447114742106721238566711475010672
12385887114751106722238599611476810672323865461147691067242386656
11481410676923874241148341067892387534114835106790238819311483910
67902388303114843106790238863311484810679123895671148511067942389
62111485210679523897311148571067962389841114865106796239011611488
51067962390171114897106796239050011492110679623906101149271067962
39313711502410688123932471150251068822395883115036106892239599311
50371068932397641115052106899239764111505310690024121411153411071
72241230611550410733524124151155171073392412800115523107345241291
01155771073562413020115578107357241334911559810737524135691156001
07377241549111571610749324155461157171074942420489115728107498224
12306115504107335241241511551714600106719238292111460610671923830
30114634106719238314011465010671923836901146521067192383909114654
10671923841291146661067192384349114676106719238445911469010671923
84568114691106720238467811469810672123847881147001067212385008114
72210672123853371147321067212385447114742106721238566711475010672
12385887114751106722238599611476810672323865461147691067242386656
11481410676923874241148341067892387534114835106790238819311483910
67902388303114843106790238863311484810679123895671148511067942389
62111485210679523897311148571067962389841114865106796239011611488
51067962390171114897106796239050011492110679623906101149271067962
39313711502410688123932471150251068822395883115036106892239599311
50371068932397641115052106899239764111505310690024121411153411071
72241230691237270511370010589323733641137241058942373474113726105
89423736931137361058942374023113750105894237616511386910601223803
39114418106555238044911452010665723806141145361066692380724114550
10668123810531145621066812381273114564106683238182211458110670023
82481114587106706238259111460010671923829211146061067192383030114
63410671923831401146501067192383690114652106719238390911465410671
92384129114666106719238434911467610671923844591146901067192384568
91237270511370010589323733641137241058942373474113726105894237369
31137361058942374023113750105894237616511386910601223803391144181
06555238044911452010665723806141145361066692380724114550106681238
10531145621066812381273114564106683238182211458110670023824811145
87106706238259111460010671923829211146061067192383030114634106719
23831401146501067192383690114652106719238390911465410671923841291
49853984759837459837498573984758324759254786324785698788881466610
45457634875634876532765978659872364598723645987264598723645987326
45987632498756328974652389746598372645987364598736459876324987562
39874653987465298376459873264589763249875632984765239874659873264
59873264598762348756239847653298746582376458972364587263485976328
76984357693845769384075698347569843756912365231047256148752198769
87987787985764398787694123765423764587349060670984587567263579879
12316564765230987098347654874869346426765476547858435435435643543
89423736931137361058942374023113750105894237616511386910601223803
39114418106555238044911452010665723806141145361066692380724114550
10668123810531145621066812381273114564106683238182211458110670023
82481114587106706238259111460010671923829211146061067192383030114
63410671923831401146501067192383690114652106719238390911465410671
92384129114666106719238434911467610671923844591146901067192384568
91237270511370010589323733641137241058942373474113726105894237369
31137361058942374023113750105894237616511386910601223803391144181
06555238044911452010665723806141145361066692380724114550106681238
10531145621066812381273114564106683238182211458110670023824811145
87106706238259111460010671923829211146061067192383030114634106719
23831408753984759874598374598374598374597349587349857398475938475
98374598371146501067192383690114652106719238390911465410671923841
29114666106715983759837495873498573984983609850968409586094586094
85069892384349114676106719238445911469010671923845682349691112621
10486622355843112638104881235589811263910488236616911264810489123
71057113551105770237122211365110586723712771136521058682371386113
66710587623714961136821058912371716113694105891237237511369610589
48573874659827645873645897326589763245897623489756389746538746538
74652987346592873645987236459872634985763294857629387465923846593
92322547392938475623987562897465298376598726549872365987236598726
87968197871987261987618719876187632198716239874168971236489761238
56435435435435435432143214332144521321213542154343521354213542134
72210672123853371147321067212385447114742106721238566711475010672
12385887114751106722238599611476810672323865461147691067242386656
11481410676923874241148341067892387534114835106790238819311483910
67902388303114843106790238863311484810679123895671148511067942389
62111485210679523897311148571067962389841114865106796239011611488
51067962390171114897106796239050011492110679623906101149271067962
39313711502410688123932471150251068822395883115036106892239599311
50371068932397641115052106899239764111505310690024121411153411071
72241230691237270511370010589323733641137241058942373474113726105
89423736931137361058942374023113750105894237616511386910601223803
39114418106555238044911452010665723806141145361066692380724114550
10668123810531145621066812381273114564106683238182211458110670023
82481114587106706238259111460010671923829211146061067192383030114
63410671923831401146501067192383690114652106719238390911465410671
92384129114666106719238434911467610671923844591146901067192384568
91237270511370010589323733641137241058942373474113726105894237369
31137361058942374023113750105894237616511386910601223803391144181
06555238044911452010665723806141145361066692380724114550106681238
10531145621066812381273114564106683238182211458110670023824811145
87106706238259111460010671923829211146061067192383030114634106719
23831408753984759874598374598374598374597349587349857398475938475
98374598371146501067192383690114652106719238390911465410671923841
29114666106715983759837495873498573984983609850968409586094586094
85069892384349114676106719238445911469010671923845682349691112621
10486622355843112638104881235589811263910488236616911264810489123
71057113551105770237122211365110586723712771136521058682371386113
66710587623714961136821058912371716113694105891237237511369610589
48573874659827645873645897326589763245897623489756389746538746538
74652987346592873645987236459872634985763294857629387465923846593
24589234503245234534850234578320467045608574976485976409567045607
46507546094675049857640567840956784098576498759870937097098127980
17981789237498275409834709210910983175483750983720072789023487957
84570983745098746580976543789654379863457980657980564379865437980
63409857643098567809654370986543789654379865347980654379863450987
63049857609834576098347569083475609873450986734098576039845769084
35760984576098347560987435908674530987603948576098435760983457609
83475609834709687430986743098576943058760984357609834576098437560
98435760984756983475609843756984357690856098760980910910982310948
02938409321840928340921830941803980198409218430910930943218094321
80943210984320983420984398065890896048906490842853280981098210943
6654387653487645876348576348576348756384765387465837
it probably took a super computer days to calculate the above and it in only 8630 digits!
As far as i know, supercomputers have been calculation pi to the billion something digit, but they have been running for YEARS, even decades.
appi101
Aug 28th, 2001, 03:43 AM
Hi
How will we do it anyway?
Appi
sail3005
Aug 28th, 2001, 12:04 PM
do what? People have told you like 3 times to use that series!
appi101
Aug 28th, 2001, 10:30 PM
Hi
I know that people have told me to use that series 3 times. But what I want to know is how to use it. If u could give me some code I'd appreciate it.
Appi
Dillinger4
Aug 28th, 2001, 11:28 PM
kedaman..... what is atn? Is that a function in VB? Im curious
atn(1)*4 gives pi, and arcus tangens can be written as a series:
appi101
Aug 29th, 2001, 03:01 AM
Atn is arctangent function.
Since tan(pi/4) i.e. tan(45) is 1 atn(1) gives the value of pi/4. BUt this is just till some 6-9 places of decimal.
Appi
mlewis
Aug 29th, 2001, 12:21 PM
Use this code:
X = 3
Place:
Y=1/X^2+Y
X=X+2
A=A+1
lblPiValue = (8(1+Y))
lblTries = A
Goto Place
Make sure its on a form with a two labels: lblPiValue and lblTries
HarryW
Aug 29th, 2001, 12:38 PM
That code will never end though :rolleyes: Might need to refresh the form or something so the values get updated.
mlewis
Aug 29th, 2001, 12:41 PM
It will end -- use Ctrl+Pause or Ctrl+Alt+Del or if all else fails, pull the power cord.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.