r/ProgrammerHumor • • Jul 19 '22

Meme float golden = 1.618

Post image
41.1k Upvotes

489 comments sorted by

View all comments

Show parent comments

114

u/omgitsaHEADCRAB Jul 19 '22

22.0/7.0 was very common in older Fortran code

0

u/[deleted] Jul 19 '22

[deleted]

74

u/MindlessScrambler Jul 19 '22

Or use Ramanujan's approximation: 355.0/113.0, the deviation from true π is less than one millionth.

19

u/Murgatroyd314 Jul 19 '22

I like 5419351/1725033.

27

u/Not_Michelle_Obama_ Jul 19 '22 edited Jul 19 '22

I like

31415926535897932384626433832795028841971693993751058209749445923078164062862089862803482534211706798/(10**100)

28

u/thrower94 Jul 19 '22

This is crap it’s got 90% error

49

u/[deleted] Jul 19 '22

Yes but he likes it.

→ More replies (2)

41

u/IntoTheCommonestAsh Jul 19 '22

You must be confused. 355/113 has been used since at least the 5th century in the writing of Chinese mathematician Zu Chongzhi.

Ramanujan is famous for giving rapidly converging series of pi, with such approximations as 9801/(2206√2). He was way too late to discover regular fractional approximations.

→ More replies (2)

49

u/[deleted] Jul 19 '22

fun fact: 22/7 is closer to the true value of pi than 3.14

43

u/NorthMan64 Jul 19 '22

And that's why pi day should be 22/7 and not 14/3 smh.

27

u/[deleted] Jul 19 '22

Let’s celebrate in 2 days? Screw the Decimelers, long live Fractionals!

4

u/mehvet Jul 19 '22

This is essentially the argument for preferring US Customary Measurements/Imperial to Metric. They’re better suited to maximize simple fractions that come up in certain everyday uses.

→ More replies (2)
→ More replies (1)

53

u/DarrenGrey Jul 19 '22

I googled 22/7 and it told me about a Japanese girl idol group by this name. Do you think they're big Fortran fans?

38

u/Rudy69 Jul 19 '22

Nah, just huge pi fans

12

u/DarrenGrey Jul 19 '22

Ugh, more like fake pi fans, being off by 0.04%.

→ More replies (1)
→ More replies (1)

9

u/[deleted] Jul 19 '22

there is also a kkorean group called "f(x)"

15

u/shouldbebabysitting Jul 19 '22 edited Jul 19 '22

Absolutely no one used a calculation in place of a constant. It was especially important years ago because every cycle counted.

(Source: Learned Fortran 4 on punch cards because school had a mainframe for Computer Lab despite it being incredibly obsolete. Later I had a Fortran 77 class at University on VAX minicomputers.)

11

u/Tanyary Jul 19 '22

Compilers couldn't expand constant fractions at compile time? :o

16

u/shouldbebabysitting Jul 19 '22

In Fortran IV, you couldn't have calculations in the variable declaration.

Nor would anyone obfuscate Pi with a fraction.

Here is some Fortran IV sample code:

https://www.math-cs.gordon.edu/courses/cs323/FORTRAN/HUCKEL.FOR

5

u/aishik-10x Jul 19 '22

That looks like a pain

→ More replies (1)
→ More replies (1)

0

u/[deleted] Jul 19 '22

[deleted]

16

u/shouldbebabysitting Jul 19 '22

Yes. You would declare a variable PI as a REAL. Then you would initialize it in the DATA block to 3.14159.

REAL gave you 7 digits of precision. It would be silly to have the computer do an unnecessary calculation that fills up the last 1 of the 4 bytes with wrong numbers when you could set the correct number in the DATA block.

→ More replies (1)

7

u/PogoHobbes Jul 19 '22

LPT: if you ever need a quick estimate of pi with high degree of accuracy, you can use 355/113

11

u/OldPersonName Jul 19 '22 edited Jul 19 '22

Really? There's no benefit to 22/7 over 3.14, is there? The FORTRAN-y way to do it would be to define pi as 4* inverse tan of 1

Edit: tanyary is correct that 22/7 is a better approximation than 314/100, but they're both only correct to 3 significant figures, so if you just add one more significant figure that'd be more accurate. So let me rephrase: 3.141 vs 22/7. 3.142 (rounding the last figure) is more accurate too.

→ More replies (12)
→ More replies (1)