Jump to content



Photo

Calculate Pi


  • Please log in to reply
24 replies to this topic

#1 Pakku

Pakku

    Prodigy

  • Active Members
  • PipPipPip
  • 183 posts

Posted 24 January 2007 - 02:56 PM

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 by Pakku, 16 November 2010 - 12:31 AM.

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:http://www.autoitscript.com/fileman/users/arjan%20staring/My profilePM me





#2 Busti

Busti

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 337 posts

Posted 24 January 2007 - 06:00 PM

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

#3 Pakku

Pakku

    Prodigy

  • Active Members
  • PipPipPip
  • 183 posts

Posted 24 January 2007 - 06:12 PM

Hi,

good one, thanks!
i changed 1000 in 100000 because it is more precise than 1000

Edited by Pakku, 16 November 2010 - 12:31 AM.

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:http://www.autoitscript.com/fileman/users/arjan%20staring/My profilePM me

#4 James

James

    jbrooksuk

  • MVPs
  • 9,468 posts

Posted 24 January 2007 - 08:27 PM

Well, I never thought I'd be seeing something like this.

#5 WeMartiansAreFriendly

WeMartiansAreFriendly

    Where's the kaboom?

  • Active Members
  • PipPipPipPipPipPip
  • 1,245 posts

Posted 25 January 2007 - 05:17 AM

interesting.. Posted Image

anyways nice script

Edited by mrRevoked, 25 January 2007 - 05:18 AM.

Posted ImageDon't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

#6 frontmill

frontmill

    Adventurer

  • Active Members
  • PipPip
  • 106 posts

Posted 25 January 2007 - 12:31 PM

lol very nice man... i really like it :)

#7 Pakku

Pakku

    Prodigy

  • Active Members
  • PipPipPip
  • 183 posts

Posted 25 January 2007 - 05:56 PM

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 by Pakku, 16 November 2010 - 12:31 AM.

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:http://www.autoitscript.com/fileman/users/arjan%20staring/My profilePM me

#8 Michel Claveau

Michel Claveau

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 352 posts

Posted 25 January 2007 - 06:48 PM

is there a way to let the script return it's answer with about 100 or something digits?

Plain Text         
; 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


#9 Michel Claveau

Michel Claveau

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 352 posts

Posted 25 January 2007 - 06:59 PM

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


#10 Pakku

Pakku

    Prodigy

  • Active Members
  • PipPipPip
  • 183 posts

Posted 26 January 2007 - 11:30 AM

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 by Pakku, 16 November 2010 - 12:31 AM.

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:http://www.autoitscript.com/fileman/users/arjan%20staring/My profilePM me

#11 nfwu

nfwu

    I'm not active on these forums

  • Active Members
  • PipPipPipPipPipPip
  • 1,234 posts

Posted 29 January 2007 - 10:16 PM

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.

#)

#12 Pakku

Pakku

    Prodigy

  • Active Members
  • PipPipPip
  • 183 posts

Posted 30 January 2007 - 04:52 PM

Hi,

next question: how to do that, i have never done that before

Edited by Pakku, 16 November 2010 - 12:31 AM.

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:http://www.autoitscript.com/fileman/users/arjan%20staring/My profilePM me

#13 Wus

Wus

    Indentured Servant

  • Active Members
  • PipPipPipPipPipPip
  • 513 posts

Posted 31 January 2007 - 05:52 AM

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.
Posted Image

#14 Pakku

Pakku

    Prodigy

  • Active Members
  • PipPipPip
  • 183 posts

Posted 31 January 2007 - 03:17 PM

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:http://www.autoitscript.com/fileman/users/arjan%20staring/My profilePM me

#15 Schlumpf

Schlumpf

    Seeker

  • Active Members
  • 40 posts

Posted 31 January 2007 - 05:02 PM

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) :)

Sorry for my bad English... ;)


#16 Pakku

Pakku

    Prodigy

  • Active Members
  • PipPipPip
  • 183 posts

Posted 02 February 2007 - 02:07 PM

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 by Pakku, 16 November 2010 - 12:32 AM.

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:http://www.autoitscript.com/fileman/users/arjan%20staring/My profilePM me

#17 Manadar

Manadar

    Taking a REST.

  • MVPs
  • 10,714 posts

Posted 04 February 2007 - 08:55 PM

This was fun to write, although it doesn't show how to calculate Pi in more places..

AutoIt         
MsgBox(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

Edited by Manadar, 04 February 2007 - 08:58 PM.


#18 AutoItKing

AutoItKing

    Don't mess with the king.

  • Active Members
  • PipPipPipPipPipPip
  • 1,379 posts

Posted 04 February 2007 - 11:14 PM

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]

#19 Pakku

Pakku

    Prodigy

  • Active Members
  • PipPipPip
  • 183 posts

Posted 05 February 2007 - 08:30 AM

This was fun to write, although it doesn't show how to calculate Pi in more places..

AutoIt         
MsgBox(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:http://www.autoitscript.com/fileman/users/arjan%20staring/My profilePM me

#20 Wus

Wus

    Indentured Servant

  • Active Members
  • PipPipPipPipPipPip
  • 513 posts

Posted 05 February 2007 - 08:48 PM

ConsoleWrite(ATan(1)*4)


This ways pretty simple... and it will give you pi as good as the implementation is in the language.
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users