Pakku Posted January 24, 2007 Share Posted January 24, 2007 (edited) Hi all, On Wikipedia I found a page about Pi and how to calculate this. So i converted the C code on Wikipedia for calculating Pi in AutoIt code and here it is! The first one is just a script which calculates Pi until you are 80 years or something. The second is a UDF. The script: $a = 0 $b = 0 $c = 0 $start = TimerInit() While 1 $a += 1 $b += 1 $c += 1/($a*$a) If $b = 100000 Then $b = 0 ConsoleWrite(Sqrt($c*6)) ConsoleWrite(@CRLF) ConsoleWrite(" " & Round(TimerDiff($start)) / 1000 & " seconds") ConsoleWrite(@CRLF) $start = TimerInit() EndIf WEnd Feedback is welcome EDIT: Busti optimized the loop in the UDF Edited November 16, 2010 by Pakku How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:My filemanMy profilePM me Link to comment Share on other sites More sharing options...
Busti Posted January 24, 2007 Share Posted January 24, 2007 hi,nice release, but use for loop, its faster : MsgBox( 0 , "" , pi() ) Exit Func pi($calc = 1000) Local $b = 0 For $a = 1 To $calc $b += 1/($a*$a) Next Return Sqrt($b*6) EndFunc My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity Link to comment Share on other sites More sharing options...
Pakku Posted January 24, 2007 Author Share Posted January 24, 2007 (edited) Hi, good one, thanks! i changed 1000 in 100000 because it is more precise than 1000 Edited November 16, 2010 by Pakku How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:My filemanMy profilePM me Link to comment Share on other sites More sharing options...
James Posted January 24, 2007 Share Posted January 24, 2007 Well, I never thought I'd be seeing something like this. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted January 25, 2007 Share Posted January 25, 2007 (edited) interesting.. anyways nice script Edited January 25, 2007 by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
frontmill Posted January 25, 2007 Share Posted January 25, 2007 lol very nice man... i really like it Link to comment Share on other sites More sharing options...
Pakku Posted January 25, 2007 Author Share Posted January 25, 2007 (edited) Thank all! The script returns a number with 14 digits, is there a way to let the script return it's answer with about 100 or something digits? Edited November 16, 2010 by Pakku How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:My filemanMy profilePM me Link to comment Share on other sites More sharing options...
Michel Claveau Posted January 25, 2007 Share Posted January 25, 2007 is there a way to let the script return it's answer with about 100 or something digits? ; Michel Claveau Informatique msgbox(0,"Pi 100 car",_pi()) msgbox(0,"Pi 10 car",_pi(10)) msgbox(0,"Pi 1000 car",_pi(1000)) Func _pi($nb=100) $pi= '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421 170679' $pi=$pi&'821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303 8196' $pi=$pi&'442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914 1273' $pi=$pi&'724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511 6094' $pi=$pi&'330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119 4912' $pi=$pi&'983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940 5132' $pi=$pi&'000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258 9235' $pi=$pi&'420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963 1859' $pi=$pi&'502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914 7303' $pi=$pi&'598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420 1989' Return(StringLeft($pi,$nb)) EndFunc Link to comment Share on other sites More sharing options...
Michel Claveau Posted January 25, 2007 Share Posted January 25, 2007 Hi! Another release, only for test the forum, with big line. ; Michel Claveau Informatique msgbox(0,"Pi 100 car",pi()) msgbox(0,"Pi 10 car",pi(10)) msgbox(0,"Pi 1000 car",pi(1000)) Func pi($nb=100) $pi='3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421 1706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493 0381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249 1412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415 1160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301 1949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669 4051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892 5892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609 6318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669 1473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164 201989' Return(StringLeft($pi,$nb)) EndFunc Link to comment Share on other sites More sharing options...
Pakku Posted January 26, 2007 Author Share Posted January 26, 2007 (edited) Hi, That isn't realy what i ment, i ment: is there a way to CALCULATE the value of Pi with more than 15 characters. According to the help file it can't but maybe we can find an other way to do this? Edited November 16, 2010 by Pakku How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:My filemanMy profilePM me Link to comment Share on other sites More sharing options...
nfwu Posted January 29, 2007 Share Posted January 29, 2007 You'd have to use a string representation of the number and manipulate that- the precision of floating point is too little for your needs. #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() Link to comment Share on other sites More sharing options...
Pakku Posted January 30, 2007 Author Share Posted January 30, 2007 (edited) Hi, next question: how to do that, i have never done that before Edited November 16, 2010 by Pakku How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:My filemanMy profilePM me Link to comment Share on other sites More sharing options...
Wus Posted January 31, 2007 Share Posted January 31, 2007 Just so everyones clear.... 5 decimals of pi is about as far as most people will ever need... bothering to go beyond that is a matter of semantics for 99.9999999999999999999999999999999999999999999999999999999999999999999999999999999999% of the population if you get my drift. Link to comment Share on other sites More sharing options...
Pakku Posted January 31, 2007 Author Share Posted January 31, 2007 Just so everyones clear.... 5 decimals of pi is about as far as most people will ever need... bothering to go beyond that is a matter of semantics for 99.9999999999999999999999999999999999999999999999999999999999999999999999999999999999% of the population if you get my drift.Why would you else calculate Pi for, the fun thing of this script is to calculate Pi over more than 5 decimals, but 15 isn't enough for me. How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:My filemanMy profilePM me Link to comment Share on other sites More sharing options...
Schlumpf Posted January 31, 2007 Share Posted January 31, 2007 Why would you else calculate Pi for, the fun thing of this script is to calculate Pi over more than 5 decimals, but 15 isn't enough for me.I think so, too! I'd link to habe a script, what calculates PI to endless decimals (you should set the number of decimals before) [CENTER]Sorry for my bad English... ;)[/CENTER] Link to comment Share on other sites More sharing options...
Pakku Posted February 2, 2007 Author Share Posted February 2, 2007 (edited) Sorry for my bad English... your english isn't that bad as mine, but do you or any one have an idee how to do this Edited November 16, 2010 by Pakku How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:My filemanMy profilePM me Link to comment Share on other sites More sharing options...
jvanegmond Posted February 4, 2007 Share Posted February 4, 2007 (edited) This was fun to write, although it doesn't show how to calculate Pi in more places.. expandcollapse popupMsgBox(0, "This is a demonstration of calculating Pi", "Actual Pi: 3.1415926535897932384626433832795" & @CRLF & @CRLF & "Arjan: "& Pi() & @CRLF & "Gregory: " & Gregory() & @CRLF & "Newton: " & Newton() & @CRLF & "Manadar: " & Manadar() & @CRLF & "Wallis: " & Wallis()) Func Pi($calc = 100000) Local $b = 0 For $a = 1 To $calc $b += 1/($a*$a) Next Return Sqrt($b*6) EndFunc Func Wallis() ;methos is faulty from 20 and up ;requires integral calculation... I'm clueless?!? Starting on integral calculation in a month at school ^o) ;http://www.escape.com/~paulg53/math/pi/wallis/index.html Local $numerator = 1 Local $dividor = 1 For $x = 1 to 61 If $x/2 = Int($x/2) Then $numerator *= $x * $x Else $dividor *= $x * $x EndIf ;MsgBox(0, "Faulty from 20", $numerator & @CRLF & "---------------------------------" & @CRLF & $dividor) Next Return ($numerator/$dividor)*2 EndFunc Func Gregory() ;Leibniz and Machin ;http://www.escape.com/~paulg53/math/pi/greg/index.html Local $pi = 4*ATan(1/5)-ATan(1/239) Return $pi*4 EndFunc Func Newton() ;http://www.escape.com/~paulg53/math/pi/newton/index.html $a = Sqrt(3)/23 $b = Sqrt(3)/32 $c = $a + $b $d = 24 * $c Return $d EndFunc Func Manadar() ; lol, this is totally random! I want Apple3.14159265358 Return Sin(0.5)*6.5 EndFuncA lot more stuff on Pi that i have to try! http://www.escape.com/~paulg53/math/pi/links.html Edited February 4, 2007 by Manadar mLipok 1 github.com/jvanegmond Link to comment Share on other sites More sharing options...
AutoItKing Posted February 4, 2007 Share Posted February 4, 2007 It would also be nice if it could output the indivudual decimals as they are calculated. Like type them into notepad or something. http://www.autoitking.co.nr Site is DOWN | My deviantART | No Topic Topic - Don't do it!-------------------- UDF's/Scripts:AutoIt: [BenEditor 3.6] [_ShutDown()]PHP: [CommentScript]Web Based AutoIt: [MemStats] [HTML to AU3] [User LogIn and SignUp script] Link to comment Share on other sites More sharing options...
Pakku Posted February 5, 2007 Author Share Posted February 5, 2007 This was fun to write, although it doesn't show how to calculate Pi in more places.. expandcollapse popupMsgBox(0, "This is a demonstration of calculating Pi", "Actual Pi: 3.1415926535897932384626433832795" & @CRLF & @CRLF & "Arjan: "& Pi() & @CRLF & "Gregory: " & Gregory() & @CRLF & "Newton: " & Newton() & @CRLF & "Manadar: " & Manadar() & @CRLF & "Wallis: " & Wallis()) Func Pi($calc = 100000) Local $b = 0 For $a = 1 To $calc $b += 1/($a*$a) Next Return Sqrt($b*6) EndFunc Func Wallis() ;methos is faulty from 20 and up ;requires integral calculation... I'm clueless?!? Starting on integral calculation in a month at school ^o) ;http://www.escape.com/~paulg53/math/pi/wallis/index.html Local $numerator = 1 Local $dividor = 1 For $x = 1 to 61 If $x/2 = Int($x/2) Then $numerator *= $x * $x Else $dividor *= $x * $x EndIf ;MsgBox(0, "Faulty from 20", $numerator & @CRLF & "---------------------------------" & @CRLF & $dividor) Next Return ($numerator/$dividor)*2 EndFunc Func Gregory() ;Leibniz and Machin ;http://www.escape.com/~paulg53/math/pi/greg/index.html Local $pi = 4*ATan(1/5)-ATan(1/239) Return $pi*4 EndFunc Func Newton() ;http://www.escape.com/~paulg53/math/pi/newton/index.html $a = Sqrt(3)/23 $b = Sqrt(3)/32 $c = $a + $b $d = 24 * $c Return $d EndFunc Func Manadar() ; lol, this is totally random! I want Apple3.14159265358 Return Sin(0.5)*6.5 EndFunc A lot more stuff on Pi that i have to try! http://www.escape.com/~paulg53/math/pi/links.html Nicely done! How can someone use Windows without using AutoIt?That one would properly don't know how to handle a computer!My scripts:Send files over internetKind of RSS reader3Draw ProUDF: convert a character string to a binary one and backCalculate PiCommand line downloader (Youtube/Google video)Set the transparency of a window just by hitting a key!Secure your pcOther things:My filemanMy profilePM me Link to comment Share on other sites More sharing options...
Wus Posted February 5, 2007 Share Posted February 5, 2007 ConsoleWrite(ATan(1)*4) This ways pretty simple... and it will give you pi as good as the implementation is in the language. mLipok 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now