Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Calculating number Pi digits in C

  1. Nov 11, 2015 #1
    Hi
    I was thinking about calculating Pi digits (for example up to 1000) using C programming
    Unfortunately there seems to be no one in our university to know how (even teachers)
    I know that i have to use arrays but i dont know how
    And i don't know what is the best way to do it ?
    -4 times the integration of (1-x^2)^(1/2) for 0 to 1
    - Leibniz's series
    -Wallis's series
    - or ...
     
  2. jcsd
  3. Nov 11, 2015 #2
  4. Nov 11, 2015 #3

    DrClaude

    User Avatar

    Staff: Mentor

  5. Nov 11, 2015 #4
    No , the teacher connected his laptop to projector while he was teaching C his typing speed wasn't much different of a beginner ... I think he was two-finger typing
    Still seems implausible ? FYI im from iran.
     
  6. Nov 11, 2015 #5

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    What does typing speed have to do with knowing how to find the digits of pi? And the question was about all the teachers at your school so why refer to just one?
     
  7. Nov 11, 2015 #6
    This is university ... The teacher (or should i call university teachers professor ?) got his degree from the best university in Iran .. it shows that he doesn't have much experience ... Just ask him intermediate questions and he can't answer more than half of them
    I asked fifth semester students they couldn't
     
  8. Nov 11, 2015 #7

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    Perhaps this is a language problem- you did not respond to either of my questions.
     
  9. Nov 11, 2015 #8

    DrClaude

    User Avatar

    Staff: Mentor

    I think we should stick to the topic of the thread, discussing numerical methods to calculate π.
     
  10. Nov 11, 2015 #9
    First that typing faster means you had more experience coding (and you wrote a bigger variety of programs) but this one is way beyond slow
    Second that i'm first semester i don't know any other teachers and they won't answer unless they know me
     
  11. Nov 11, 2015 #10
    How is that formula can calculate Nth digit of Pi i don't get it
     
  12. Nov 11, 2015 #11
    To get the N't hexadecimal digit you still need to sum n terms (and a few more to prevent roundoff errors), but it's easy to get the nth hexadecimal digit of a single term. The factors of 1/16 will only shift the term 1 digit to the right, the numbers like 4/(8k+1) are rational numbers with a repeating hexadecimal expansion.
    You only need to calculate the digits N through N+20 or so from all the terms to produce the Nth digit of the sum. For the billionth digit you still need to sum a billion terms, but the calculations involve only numbers of 20 digits.
     
  13. Nov 11, 2015 #12
    Sorry still confused .. can you write algorithm ?
     
  14. Nov 12, 2015 #13

    Svein

    User Avatar
    Science Advisor

    What you need is much more complicated than an algorithm (I can direct you to several). You need a way to represent multi-digit numbers with associated arithmetic operations in a consistent way. Fortunately, somebody else has seen the need and created the appropriate definitions and libraries - see http://mpir.org/.
     
  15. Nov 12, 2015 #14
    What i actually need is way to deal with the fact that i can't work with great numbers in C i don't know what the problem is
    The Leibniz's series i said up there , is a summation . I couldn't calculate it because double variable types had limited digits ... i tried multiplying by 10^n and result%10 so that i could get nth digit but it didn't work ...
    Is there any possibility that i can use arrays to solve the problem ? or it takes too much memory ?
    Or any not very complicated way that i can at least understand ?
     
  16. Nov 12, 2015 #15

    rcgldr

    User Avatar
    Homework Helper

  17. Nov 12, 2015 #16

    Svein

    User Avatar
    Science Advisor

    Follow the link! Those people have defined numbers with more than a million digits - the record for π is more than 13 trillion digits (see https://en.wikipedia.org/wiki/Approximations_of_π).
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Calculating number Pi digits in C
  1. Number of digit (Replies: 2)

Loading...