Just starting out? Need help? Post your questions and find answers here.
Kale
PureBasic Expert
Posts: 3000 Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:
Post
by Kale » Mon Jan 16, 2006 1:52 pm
Has anyone got a way in PB to accurately calculate Pi? Here are a few ways but not very accurate:
Code: Select all
Debug StrF(4 * (ATan(1/2) + ATan(1/3)), 10)
Debug StrF(4 * (4 * ATan(1/5) - ATan(1/239)), 10)
Debug StrF((16 * ATan(1/5)) - (4 * ATan(1/239)), 10)
Debug StrF(4 * ATan(1), 10)
Any more?
--Kale
Rings
Moderator
Posts: 1435 Joined: Sat Apr 26, 2003 1:11 am
Post
by Rings » Mon Jan 16, 2006 3:07 pm
Code: Select all
a.s=a.s+ StrF(4 * (ATan(1/2) + ATan(1/3)), 10) + Chr(13)
a.s=a.s+ StrF(4 * (4 * ATan(1/5) - ATan(1/239)), 10)+ Chr(13)
a.s=a.s+ StrF((16 * ATan(1/5)) - (4 * ATan(1/239)), 10)+ Chr(13)
a.s=a.s+ StrF(4 * ATan(1), 10) + Chr(13)
a.s=a.s+ StrD(4 * (ATan(1/2) + ATan(1/3)), 10) + Chr(13)
a.s=a.s+ StrD(4 * (4 * ATan(1/5) - ATan(1/239)), 10)+ Chr(13)
a.s=a.s+ StrD((16 * ATan(1/5)) - (4 * ATan(1/239)), 10)+ Chr(13)
a.s=a.s+ StrD(4 * ATan(1), 10) + Chr(13)
MessageRequester("Info",a.s ,0)
SPAMINATOR NR.1
MikeB
Enthusiast
Posts: 183 Joined: Sun Apr 27, 2003 8:39 pm
Location: Cornwall UK
Post
by MikeB » Mon Jan 16, 2006 3:10 pm
Until we get higher precision floating point with PB (hopefully in V4.0) I don't think you can do an accurate calculation, even then you won't be able to get great precision without resorting to a huge loop calculating each decimal place one by one. This is an inherent problem with a never ending (as far as we know) calculation.
DarkDragon
Addict
Posts: 2345 Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:
Post
by DarkDragon » Mon Jan 16, 2006 3:21 pm
Rings wrote: Code: Select all
a.s=a.s+ StrF(4 * (ATan(1/2) + ATan(1/3)), 10) + Chr(13)
a.s=a.s+ StrF(4 * (4 * ATan(1/5) - ATan(1/239)), 10)+ Chr(13)
a.s=a.s+ StrF((16 * ATan(1/5)) - (4 * ATan(1/239)), 10)+ Chr(13)
a.s=a.s+ StrF(4 * ATan(1), 10) + Chr(13)
a.s=a.s+ StrD(4 * (ATan(1/2) + ATan(1/3)), 10) + Chr(13)
a.s=a.s+ StrD(4 * (4 * ATan(1/5) - ATan(1/239)), 10)+ Chr(13)
a.s=a.s+ StrD((16 * ATan(1/5)) - (4 * ATan(1/239)), 10)+ Chr(13)
a.s=a.s+ StrD(4 * ATan(1), 10) + Chr(13)
MessageRequester("Info",a.s ,0)
Works great here: PB 3.94
should I say anything else?
bye,
Daniel
RichardL
Enthusiast
Posts: 532 Joined: Sat Sep 11, 2004 11:54 am
Location: UK
Post
by RichardL » Mon Jan 16, 2006 5:40 pm
Hi,
A bit off topic.
PI is about 3 and a bit ... good enough for gardening
PI is about 22/7... good enough for early schooling
PI is about 355/113... good to about ten decimal places.
(11 33 55 first three odd numbers with a stutter; that how I remember it.)
Stupid rhyme...
Sir I have a rhyme excelling in mystic force and magic spelling
Celestial sprites elucidate all my own striving can't relate
Twenty places, count the letters! (Assuming I can spell!)
Richard L
Last edited by
RichardL on Mon Jan 16, 2006 5:51 pm, edited 2 times in total.
Dare2
Moderator
Posts: 3321 Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land
Post
by Dare2 » Mon Jan 16, 2006 5:50 pm
@}--`--,-- A rose by any other name ..
netmaestro
PureBasic Bullfrog
Posts: 8451 Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada
Post
by netmaestro » Mon Jan 16, 2006 6:31 pm
One way to "calculate" pi without reinventing the wheel:
Code: Select all
ProcedureDLL.s GetPi()
#INTERNET_FLAG_RELOAD = $80000000
Bytes.l = 0
Html.s = Space(1024)
r$ ="";
hInet.l = InternetOpen_("http://3.141592653589793238462643383279502884197169399375105820974944592.com/", 1, #Null, #Null, 0)
If hInet
hURL.l = InternetOpenUrl_(hInet, "http://3.141592653589793238462643383279502884197169399375105820974944592.com/", #Null, 0, #INTERNET_FLAG_RELOAD, 0)
If hURL
If InternetReadFile_(hURL, @Html, Len(Html), @Bytes)
Html = Mid(html,FindString(Html,"3.14",1),400)
For i= 1 To Bytes
;If (Mid(Html,i,1) >= "0" And Mid(Html,i,1) <= "9") Or Mid(Html,i,1) = "."
r$ = r$ + Mid(Html,i,1)
;EndIf
Next
InternetCloseHandle_(hURL)
Else
ProcedureReturn "Failed"
EndIf
Else
ProcedureReturn "Failed"
EndIf
InternetCloseHandle_(hInet)
Else
ProcedureReturn "Failed"
EndIf
ProcedureReturn r$
EndProcedure
pi$=Getpi()
MessageRequester("400 digits of pi",pi$)
Last edited by
netmaestro on Wed Feb 22, 2006 3:31 am, edited 5 times in total.
BERESHEIT
jack
Addict
Posts: 1358 Joined: Fri Apr 25, 2003 11:10 pm
Post
by jack » Mon Jan 16, 2006 7:22 pm
PB
PureBasic Expert
Posts: 7581 Joined: Fri Apr 25, 2003 5:24 pm
Post
by PB » Mon Jan 16, 2006 9:10 pm
> Sir I have a rhyme excelling in mystic force and magic spelling
> Celestial sprites elucidate all my own striving can't relate
Wouldn't be any good in the USA.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Num3
PureBasic Expert
Posts: 2812 Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:
Post
by Num3 » Mon Jan 16, 2006 10:55 pm
Psychophanta
Always Here
Posts: 5153 Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:
Post
by Psychophanta » Fri Apr 14, 2006 5:10 pm
Kale wrote: Has anyone got a way in PB to accurately calculate Pi? Here are a few ways but not very accurate:
Code: Select all
Debug StrF(4 * (ATan(1/2) + ATan(1/3)), 10)
Debug StrF(4 * (4 * ATan(1/5) - ATan(1/239)), 10)
Debug StrF((16 * ATan(1/5)) - (4 * ATan(1/239)), 10)
Debug StrF(4 * ATan(1), 10)
Any more?
va!n
Addict
Posts: 1104 Joined: Wed Apr 20, 2005 12:48 pm
Post
by va!n » Fri Apr 14, 2006 5:25 pm
Code: Select all
OwnPi.d= ATan(1)*4
Debug OwnPi.d
Debug #PI
va!n aka Thorsten
Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
akj
Enthusiast
Posts: 668 Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham
Post
by akj » Fri Apr 14, 2006 7:59 pm
For a method to calculate Pi to a large number of decimal places, see my PB program near the end of the forum topic:
www.purebasic.fr/english/viewtopic.php?t=8530
Anthony Jordan
SFSxOI
Addict
Posts: 2970 Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....
Post
by SFSxOI » Sat Apr 15, 2006 1:11 am
maybe i missed something, but isn't the #PI constant in PB enough already?
va!n
Addict
Posts: 1104 Joined: Wed Apr 20, 2005 12:48 pm
Post
by va!n » Sat Apr 15, 2006 3:16 am
@SFSxOI
maybe some ppl only want to know the math / algo behind #pi
va!n aka Thorsten
Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,