I want more data!

This is a discussion on I want more data! within the C++ Programming forums, part of the General Programming Boards category; Hola. I'm writing (or have finished writing) a program that calculates pi. It works very well, except that the output ...

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902

    I want more data!

    Hola. I'm writing (or have finished writing) a program that calculates pi. It works very well, except that the output is limited to 10 decimal places, with a long double. So, I was wondering if there were some variable or macro or template or something that would simple accommodate for any amount of data (given the necessary memory).
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    You may not need to assign the value to a variable if you designed it a different way. How about showing some code on how you are calculating it?

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    5
    Could you use a recursive function to display an integer with each step? You would have to set some global constant to the number of decimal places you wanted.

    Just a thought.


  4. #4
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    What's with all the monkeys

  5. #5
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    I got my name from some of my personal aspects (I am a little on the hairy side).

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    27
    Just a thought, but could you reasign the long double with the newly calculated addition to pie after the previous had been printed on the screen. I'm not completly sure about the decimal place and all that, but it might work.
    "Computers aren't intelligent, they only think they are."

    **infected by Blizzarddog**
    I am a signature virus. Please add me to your signature so that I may multiply

  7. #7
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902
    Hmmm. Yes, I'll post some code as soon as I can get to my computer (on a friend's). The thing is, calculations require square roots, which are always appx, so I just want to be able to be as accurate as possible.
    I'll give you a rundown of how the program works, it's pretty simple:
    -Ask the user for the length of the radius

    -Ask the user for resolution (a value .001 - 100)

    -Loop through x values, incremental to the resolution given, and find their respective y coordinates using the circle formula (the center is 0,0). While this is happening, for every two points calculated, the distance between them is calculated and added to variable 'circ'. The loop ends when the increments (increasing at a rate of 'resolution') equal the radius. What we now have is one-fourth the circumfrence of a pseudo-circle. It is divided by two-times the radius to yield PI.


    AND IT WORKS. The only problem is, it will only work to the limit of certain datatype restrictions, which is why I posted my question. I hope to have the code up soon.

    *Edit* By the way: I'm a monkey because I like being a monkey.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  8. #8
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    I don't know exactly how to go about doing it, but I believe that it is possible to just allocate yourself a huge chunk of memory and then program all of the math operations that you need to do with it...someone around here can give you more info than I can, I'm sure.

    edit: I usually go with 3.14159265358979323846 from memory, but you could also check out http://www.cecm.sfu.ca/pi/pi.html
    Last edited by confuted; 04-12-2003 at 02:55 PM.
    Away.

  9. #9
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Also, to ease your computations...

    Pi/4= 1-(1/3)+(1/5)-(1/7)+(1/9)-(1/11)+(1/13)-(1/15)...ad infinitum
    Away.

  10. #10
    Registered User
    Join Date
    Dec 2002
    Posts
    56
    Originally posted by blackrat364
    Also, to ease your computations...

    Pi/4= 1-(1/3)+(1/5)-(1/7)+(1/9)-(1/11)+(1/13)-(1/15)...ad infinitum
    Or:
    http://mathworld.wolfram.com/PiFormulas.html

  11. #11
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902
    Hey, cool... thanks rokt.
    Here, could anbody explain to me what the output of pi is supposed to mea in this console (my program):
    Attached Images Attached Images  
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-07-2007, 11:24 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21