Calculating number Pi digits in C

  • Context:
  • Thread starter Thread starter AliGh
  • Start date Start date
  • Tags Tags
    Pi
Click For Summary

Discussion Overview

The discussion revolves around methods for calculating the digits of Pi using C programming, with participants exploring various numerical approaches and expressing challenges related to implementation. The scope includes theoretical methods, programming techniques, and practical coding issues.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant suggests using arrays for calculating Pi digits but is unsure of the best method, mentioning integration, Leibniz's series, and Wallis's series.
  • Another participant points to the Bailey–Borwein–Plouffe formula as a resource, questioning what qualifies as "best" for the original poster.
  • A different participant advocates for the Monte Carlo method for calculating Pi.
  • There are multiple comments regarding the competence of teachers at the original poster's university, with some participants expressing skepticism about the claim that no teachers know how to calculate Pi digits.
  • One participant explains that the Bailey–Borwein–Plouffe formula allows for calculating the N'th hexadecimal digit of Pi but requires summing multiple terms to avoid roundoff errors.
  • Another participant emphasizes the complexity of representing multi-digit numbers in C and suggests using libraries designed for large number arithmetic.
  • Concerns are raised about the limitations of double variable types for calculating Pi, with a request for a simpler method or algorithm to handle large numbers.
  • Participants mention the need for libraries that can handle large numbers and provide links to resources that could assist with this.

Areas of Agreement / Disagreement

Participants express differing views on the capabilities of their university's teachers and the best methods for calculating Pi. There is no consensus on a single approach or solution, and the discussion remains unresolved regarding the most effective technique for implementation in C.

Contextual Notes

Participants highlight limitations related to the precision of standard data types in C, the complexity of algorithms for large number calculations, and the need for appropriate libraries to manage multi-digit arithmetic.

AliGh
Messages
64
Reaction score
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 don't 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 ...
 
Technology news on Phys.org
  • Like
Likes   Reactions: Dr. Courtney and Silicon Waffle
Integrand said:
Check out https://en.wikipedia.org/wiki/Bailey–Borwein–Plouffe_formula

There are very many methods available. What qualifies as "best" for you?

Incidentally, that no teachers in your university know how to calculate digits of pi seems a little implausible, don't you think? :)

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 I am from iran.
 
  • Like
Likes   Reactions: aikismos
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?
 
  • Like
Likes   Reactions: DrClaude and Silicon Waffle
HallsofIvy said:
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?
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
 
AliGh said:
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
Perhaps this is a language problem- you did not respond to either of my questions.
 
I think we should stick to the topic of the thread, discussing numerical methods to calculate π.
 
HallsofIvy said:
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?
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
 
  • #10
Integrand said:
Check out https://en.wikipedia.org/wiki/Bailey–Borwein–Plouffe_formula

There are very many methods available. What qualifies as "best" for you?

Incidentally, that no teachers in your university know how to calculate digits of pi seems a little implausible, don't you think? :)
How is that formula can calculate Nth digit of Pi i don't get it
 
  • #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.
 
  • #12
willem2 said:
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.
Sorry still confused .. can you write algorithm ?
 
  • #13
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/.
 
  • #14
Svein said:
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/.
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 ?
 
  • #15
  • #16
AliGh said:
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
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_π).
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
22
Views
5K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K