Tip All PI's are not born equal!

failedtofail

Member
Joined
Jun 16, 2022
Messages
20
Programming Experience
Beginner
I needed to calculate the formula 2 * PI * freq * 2e-4 :

Using PI = 22/7, I got 0.062857142

However, using PI itself as defined per Math.PI I get 0.062831853

(freq = 50Hz)

The latter result is identical to my calculator and Excel. I was using doubles.

So be warned - it does seem that PI's are not all born equal! (would be interested to know if anyone knows why there is this difference).
 
Why would you expect the same results?
C#:
22/7:
3.1428571428571428571428571428571

Pi:
3.1415926535897932384626433832795...
It's already different 3 decimal places in.

Also recall, that Pi is an irrational number, 22/7 is a rational number.
 
Correct, so 22/7 is just an approximation for PI. Always used to just use 3.141 or what the calculator says and never gave it much thought but now am busy with calcs where the precision to 5 decimal places is important.
 
You should have been using 3.142. Recall rounding rules.

As I recall, there is a rule of thumb regarding the target number of decimal places desired result, and the number of decimal places you will need going into the calculation. I'm blanking on it right now, but I thought that if you need 5 decimal places, you would need to work with at least 6 decimal places until you get your final result, and then you round the final result to 5 decimal places. I can only recall that for addition/subtraction. My mind is blank whether the same is true for multiplication/division.
 

Latest posts

Back
Top Bottom