Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / mmmmmm Pi

Author
Message
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Oct 2008 01:13
I wrote this little loop that calculates pi (watched the story of mathematics on BBC4 ) but DB only show five decimal places.

Is there a way to get more accuracy.
PS this has no practical use for me just interesting.

A small program that works is better than a large one that doesn't.

DBC Challenge Rank: Rookie
Ashingda 27
17
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 15th Oct 2008 04:48
When using division, use the ABS() command.

pi# = pi# + ( 4 / ABS( n# ) )* sign
jasonhtml
21
Years of Service
User Offline
Joined: 20th Mar 2004
Location: OC, California, USA
Posted: 15th Oct 2008 06:18
why would he use abs? n# is already always positive

BlobVanDam
16
Years of Service
User Offline
Joined: 26th Jul 2008
Location: one of Cybertrons moons
Posted: 15th Oct 2008 10:07
would declaring the variable pi# as a double float work? Try sticking the line "global pi# as double float" at the beginning. I think that might work
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 15th Oct 2008 20:27
This is dbc, globals and double floats don't work.

And, for the record:
Pi>Cake

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 15th Oct 2008 20:53
You can store the individual numbers you generate each loop in separate variables, or just print each number generated to the screen with the backdrop off next to the last one.

How far do you wan`t to generate it?

Suicide is away of telling God, You can’t fire me I quit !!!!!
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 16th Oct 2008 16:34
In DBC a float can only store up to five decimal places. I don`t think PRINT rounds anything though...

Suicide is away of telling God, You can’t fire me I quit !!!!!
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 16th Oct 2008 21:18
Must just be DarkBasic? No Idea...

Suicide is away of telling God, You can’t fire me I quit !!!!!
NanoGamez guy
18
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 16th Oct 2008 21:18 Edited at: 17th Oct 2008 10:10
@Obese
To do that, you'll need to covert all the float variables into strings and then write functions to add, subtract and divide strings, just like primary school math. I've made the add and subtract functions and I'm working on the divide function. They don't yet support decimal points, but I'm sure you could add that in or work around it.

Add function:



And subtract:



Strings will allow you to have 253 decimal places (255 minus the "3."), but If you wanted to, you could use an array with 65534(I think) decimal places, an array of strings - 16711678 decimal places (35536*255), or even a multidimensional array with an even larger number of decimal places (around 4667242141955653632000 with a 3 dimensional, which would take centuries to calculate!).


"To succeed is not enough, others must fail" - Gore Vidal
Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 18th Oct 2008 12:59
Quote: ""In DBC a float can only store up to five decimal places."

How can that be? A float is a data type supported by the CPU."


A float is a CPU data type, but one that DBC uses as well. "Single" floats (as used by DBC) support at most up to seven decmal places but this varies depending on the size of the number stored.

In DBC, the only way we have of viewing the contents of a float is by converting it to a string of text - whereupon DBC immediately formats it to just 6 digits (5 decimal places).

I think NanoGamez guy has the best and the simplestway of getting more decimal places and greater accuracy with "floats" - it's quite ingenious!

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 18th Oct 2008 20:21
There was a user named Alien 001 that was doing all of this sort of thing at one time or another. Check out:

http://forum.thegamecreators.com/?m=forum_view&t=108126&b=10

Enjoy your day.

Login to post a reply

Server time is: 2025-06-07 08:01:31
Your offset time is: 2025-06-07 08:01:31