Why define PI = 4 * ATAN (1)

What is the motivation for defining PI as

PI = 4.D0 * DataN (1.D0)

in Fortran 77 code? I understand how this works, but what is reasoning?

+46
fortran fortran77 pi
Jan 28
source share
5 answers

This style ensures that the highest precision available for any architecture is used when assigning a value to PI.

+57
Jan 28
source share

Because Fortran does not have a built-in constant for PI . But instead of entering the number manually and potentially making a mistake or not getting the highest possible accuracy for this implementation, letting the library calculate the result, you guarantee that none of these shortcomings will happen.

They are equivalent, and you will sometimes see them also:

 PI=DACOS(-1.D0) PI=2.D0*DASIN(1.D0) 
+13
Jan 28 2018-10-18T00:
source share

I believe because this is the shortest series on pi. It also means that he is the most accurate.

The Gregory-Leibniz series (4/1 - 4/3 + 4/5 - 4/7 ...) is equal to pi.

atan (x) = x ^ 1/1 - x ^ 3/3 + x ^ 5/5 - x ^ 7/7 ...

So, atan (1) = 1/1 - 1/3 + 1/5 - 1/7 + 1/9 ... 4 * atan (1) = 4/1 - 4/3 + 4/5 - 4 / 7 + 4/9 ...

This is equivalent to the Gregory-Leibniz series and therefore equal to pi, approximately 3.1415926535 8979323846 2643383279 5028841971 69399373510.

Another way to use atan and find pi:

pi = 16 * atan (1/5) - 4 * atan (1/239), but I find this more complicated.

Hope this helps!

(Honestly, I think the Gregory-Leibniz series was based on atan, not 4 * atan (1) based on the Gregory-Leibniz series. In other words, REAL proof:

sin ^ 2 x + cos ^ 2 x = 1 [Theorem] If x = pi / 4 radians, sin ^ 2 x = cos ^ 2 x or sin ^ 2 x = cos ^ 2 x = 1/2.

Then sin x = cos x = 1 / (root 2). tan x (sin x / cos x) = 1, atan x (1 / tan x) = 1.

So, if atan (x) = 1, x = pi / 4 and atan (1) = pi / 4. Finally, 4 * atan (1) = pi.)

Please do not upload me comments - I am still a teenager.

+10
Nov 17 '13 at 2:48 on
source share

This is because it is an accurate way to calculate pi for arbitrary precision. You can simply continue to execute the function to get more and more accuracy and stop at any point to have an approximation.

In contrast, by specifying pi as a constant, you will get exactly the same accuracy as originally set, which may be unacceptable for highly scientific or mathematical applications (since Fortran is often used).

+9
Jan 28
source share

This sounds a lot like a workaround for a compiler error. Or it may be that this particular program depends on accurate identification, and therefore the programmer guaranteed it.

-four
Jan 28
source share



All Articles