Thread: compute pi

  1. #1
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195

    compute pi

    Anybody have a clue how to compute the nth digit of pi?
    'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I bet Google knows! How about you go ask?

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Anybody have a clue how to compute the nth digit of pi?
    Yes.

    -Prelude
    My best code is written with the delete key.

  4. #4
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    Originally posted by quzah
    I bet Google knows! How about you go ask?

    Quzah.
    Never would of thought of that.

    >yes

    If yes, then please give me some insight. I have done some research into this. Where I stand now is this, to compute pi traditionally (arcsin, etc), I think it would be impossible for me to do past 12 decimal places. Atleast on my machine, because the mantissa is only 56 bits long. I am thinking there are some nifty tricks an expreienced programmer might know to exploit your FPU.

    The way I am doing it now is using a fairly new algorithim that amazingly computes any nth digit of pi. The only catch is that the calculation can only be done in hex. Meaning it is impossible to get the answer back to decimal. While this is good, it is not what I want. So I am hoping someone has done this before and can lend some advice....
    'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Never would of thought of that.
    Most people don't.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >If yes, then please give me some insight.
    I would, but you can find it with ease simply by using a search engine. So far I haven't computed PI farther than about 50,000 digits without signifigant slowdown, you might want to be more specific as to what you want your minimum limit to be.

    -Prelude
    My best code is written with the delete key.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >So far I haven't computed PI farther than about 50,000 digits without signifigant slowdown.
    Prelude, don't you have anything better to do! [/sarcasm]
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Prelude, don't you have anything better to do!
    Of course, but better isn't always more fun.

    -Prelude
    My best code is written with the delete key.

  9. #9
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Wait a tick...

    > The only catch is that the calculation can only be done in hex. Meaning it is impossible to get the answer back to decimal.

    Why is it impossible to get from hex to decimal?

  10. #10
    Registered User
    Join Date
    Aug 2002
    Posts
    4
    try with Smalltalk

  11. #11
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    Originally posted by Govtcheez
    Wait a tick...

    > The only catch is that the calculation can only be done in hex. Meaning it is impossible to get the answer back to decimal.

    Why is it impossible to get from hex to decimal?
    i guess the author of that quote screwed up somewhere.

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Actually the author didn't screw up. The algorythm finds the Nth HEX digit of PI, not the Nth DECIMAL digit of PI. Big difference.

    Quzah.
    Last edited by quzah; 08-01-2002 at 06:43 PM.
    Hope is the first step on the road to disappointment.

  13. #13
    Quietly Lurking
    Join Date
    Aug 2001
    Posts
    208
    Here you go, from the Obfuscated C Contest

    Code:
    /*
     * Program to compute an approximation of pi
     * by Brian Westley, 1988
     * (requires pcc macro concatenation; try gcc -traditional-cpp)
     */
    
    #define _ -F<00||--F-OO--;
    int F=00,OO=00;
    main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()
    {
                _-_-_-_
           _-_-_-_-_-_-_-_-_
        _-_-_-_-_-_-_-_-_-_-_-_
      _-_-_-_-_-_-_-_-_-_-_-_-_-_
     _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
     _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
     _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
     _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
      _-_-_-_-_-_-_-_-_-_-_-_-_-_
        _-_-_-_-_-_-_-_-_-_-_-_
            _-_-_-_-_-_-_-_
                _-_-_-_
    }
    Note that this program works by computing its own area. For more digits, write a bigger program.


    Hehe, got to love having the New Hackers Dictionary sitting on my desk, always comes in handy.

    ----------------------
    Proud to be a gun carrying, freedom loving, libertarian.
    Don't Listen to Right Wing Propaganda. Legalize it NOW!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pi - Hm, somethign is not right here.
    By MadnessRed in forum C++ Programming
    Replies: 8
    Last Post: 09-12-2008, 01:07 PM
  2. Compute without Limit - support for fractions and 2G Digits!
    By etlam in forum Projects and Job Recruitment
    Replies: 14
    Last Post: 02-07-2008, 12:46 PM
  3. Pi Calculation
    By EvilGuru in forum C Programming
    Replies: 2
    Last Post: 05-02-2005, 04:25 AM
  4. Pi and the standard library
    By FOOTOO in forum C Programming
    Replies: 7
    Last Post: 04-15-2005, 11:23 AM
  5. C for PI
    By Lynux-Penguin in forum C Programming
    Replies: 13
    Last Post: 04-28-2002, 07:37 PM