Jump to content


Photo

pi Calculation not working


  • This topic is locked This topic is locked
8 replies to this topic

#1 Brother156

Brother156

    GMC Member

  • Validating
  • 498 posts

Posted 21 October 2010 - 12:24 AM

Hello, I was just thinking of a way to calculate pie more exact than the regular "pi" constant. So I looked online to see what is a good way to calculate it, and I found a way that should give you the number with around 17,000 decimal places. So I converted it to gml, and got this:

pie = ((4 * arctan(1 / 5))-(arctan(1 / 239)))*4

But when I try to view it or draw it or assign another variable to it, it only shows the "3.14" part of pi. I was wondering what could be causing this or if the formula I used is incorrect in some way.



#2 thatshelby

thatshelby

    GMC Member

  • GMC Member
  • 3823 posts
  • Version:GM8

Posted 21 October 2010 - 12:30 AM

It's because it has too many characters. Use the string_format function to make it show more. I think that's how it works.. I did it that way once. :D
  • 0

#3 Brother156

Brother156

    GMC Member

  • Validating
  • 498 posts

Posted 21 October 2010 - 12:32 AM

I might try to use string_format, thanks for the tip :P

EDIT:
Nope, it didn't work. It only lengthened it by a few decimal places. I got this:
3.141592653589793280


and I used this code to format it:
pie = string_format(pie,50000,5000)

It adds many empty space characters to the string at the begining and at the end so the textbox is HUGE when I show it and the text file I write it to is over 5kb.

Edited by Brother156, 21 October 2010 - 12:43 AM.



#4 thatshelby

thatshelby

    GMC Member

  • GMC Member
  • 3823 posts
  • Version:GM8

Posted 21 October 2010 - 12:51 AM

Try playing with the values then.
  • 0

#5 Ampersand

Ampersand

    Greatest boolean of all

  • New Member
  • 796 posts

Posted 21 October 2010 - 01:58 AM

GM doesn't play very nice with lots of decimal places. I don't remember quite how I did it anymore, but I once made a program that continuously calculates digits of pi (the highest number I ever bothered to run it to went to 1.2 billion). If you'd like, I could upload the .gmk for you.
  • 0

Posted Image
(0.1.6)


#6 BBGaming

BBGaming

    Programmer

  • GMC Member
  • 2478 posts
  • Version:GM7

Posted 21 October 2010 - 04:35 AM

Why the crap would you need pi with more than 18 digits? You realize that at the circumference of the earth 30 digits is only .0000000004 millimeters more accurate?

Edited by BBGaming, 21 October 2010 - 04:35 AM.

  • 0

Posted Image
Game Widgets
- Your pure-GML solution to API DLLs. Featured in Markup Magazine!

My Portfolio - All my good games and resources
Moved away from the forum - e-mail me if you need quick contact (hi_146@hotmail.com).


#7 HaRRiKiRi

HaRRiKiRi

    GMC Member

  • GMC Member
  • 1364 posts

Posted 21 October 2010 - 10:31 AM

Nope, it didn't work. It only lengthened it by a few decimal places.

Thats the maximum you can have. Its also the same as GM's constant, so for calculations you will not get anything better. If you just want to show pi to thousands of decimals, but not use it in any calculations, then you can use some other methods (which can be found in wikipedia). That way you can have a string which has the thousands of digits, but GM can use only the ones you already got. That is because GM's only number datatype is double, which has precision of about 16 decimal places. See here: http://en.wikipedia....ng-point_format .
  • 0

#8 Brother156

Brother156

    GMC Member

  • Validating
  • 498 posts

Posted 21 October 2010 - 06:49 PM

Oh, thanks guys. I guess I'll just calculate each decimal digit and keep adding that to a string. It would be alot more work, but I think I could get it. :D



#9 OTheB

OTheB

    GMC Member

  • GMC Member
  • 46 posts
  • Version:GM:Studio

Posted 25 March 2016 - 04:19 PM

Or you could just use a "real number". Instead of using a calculation every time you want to use pi, just use:

pie = 3.14159265358979323846264338327950288419716939937... (yes I did teach myself pi to that many decimal places)


  • 0
Why is that man wearing a shoe on his head? Bcause it fits!
I leapt onto my horse and galloped off in all directions!