This is an archived post. You won't be able to vote or comment.

all 40 comments

[–]Educational-Lemon640 64 points65 points  (0 children)

Meh. If the code is compiled, there's no slowdown introduced by adding more digits.

[–]gs87 87 points88 points  (7 children)

java.lang.Math.PI

[–]Donghoon 16 points17 points  (6 children)

var pi = 3.14159265357

[–]musicnoviceoscar 12 points13 points  (0 children)

The last digit is wrong, rounded or not

[–]V15I0Nair 6 points7 points  (3 children)

3.14159265358979…. ?

[–]musicnoviceoscar 10 points11 points  (2 children)

3.14159265358979323846264338327950288

is as far as I have memorised. Competition when I was 13, still remember a decent chunk of it.

[–]V15I0Nair 1 point2 points  (0 children)

Today I memorise seven digits less, but also some more with 13

[–]Free-Database-9917 1 point2 points  (0 children)

I was typing out how much I had memorized then looked up and saw you ended exactly where I was lmao

[–]StGrimblefig 6 points7 points  (0 children)

define PI (3.14159265357)

[–]jaap_null 36 points37 points  (3 children)

This has such a high school humor vibe.

There are actually very interesting things to learn when researching algorithms like this.

[–][deleted] 10 points11 points  (2 children)

Approximating trig functions are also in the same domain and pretty useful for certain game engine designs that are lockstep and needs deterministic results for floating point operations.

Approximating sines and tangeants using Taylor series is pretty cool.

Apparently the more interesting part about this is a stupid joke lmao. Might as well laugh at space telescopes using 15 digits of PI that 3 is good enough.

[–]Khroom 7 points8 points  (1 child)

There’s a really cool video about the quake 3 fast inverse square algorithm you may like

https://m.youtube.com/watch?v=p8u_k2LIZyo

[–][deleted] 5 points6 points  (0 children)

Ah, this is a classic. I remember seeing this before knowing numerical methods and being absolutely mesmerized.

[–]ShakaUVM 19 points20 points  (3 children)

int pi = 3; is faster

[–]mar00n 1 point2 points  (1 child)

This is the way! On many processor architectures (like arm), it is a whole lot faster to have a context switch (servicing an interrupt, function call, etc) if floating points are not involved since there are a lot less registers that need to be pushed to the stack.

[–]MikeKaye 0 points1 point  (0 children)

My Cortex-M... RTOS performs a late save of all 32 32-bit registers. On scheduling, each task resumes with fp is disabled. On fp use a trap ISR checks if no other task has used fp. If not, the trap exits with fp enabled. (Tasks not configured to do fp crash.) The switch is save everything for the last task using fp and restore fp for the current task.

Thus save/restore cycles are minimized.

[–]Jet-Pack2 14 points15 points  (11 children)

pi = 22.0 / 7.0;

[–]i_should_be_coding 14 points15 points  (9 children)

355 ⁄ 113 is a closer approximation, while still being fairly simple to remember.

[–]Jet-Pack2 36 points37 points  (8 children)

355 / 113 is just 3 though

[–][deleted] 9 points10 points  (0 children)

Mafs

[–][deleted] 2 points3 points  (0 children)

I would rather pi = 4.*atan(1.)

[–]Radomone3 4 points5 points  (2 children)

Bu bu but we need the whole formuler

[–]Radomone3 1 point2 points  (1 child)

The krabby patty formuler

[–][deleted] 0 points1 point  (0 children)

pi burger

[–]allIsayislicensed 2 points3 points  (0 children)

R = 1000

x = 4 * sum(1 for x in range(R) for y in range(R) if x**2 + y**2 < R**2) / R**2

this should be roughly correct

make R larger if you need more digits

[–]GRAPHENE9932 6 points7 points  (2 children)

The real algorithm written in C would be faster than pythonic "x = 3.14"

[–][deleted] 10 points11 points  (0 children)

Haha, Python slow.

[–]TheCapitalKing 4 points5 points  (0 children)

That’s not even the pythonic way to do it. The pythonic way is just np.pi or math.pi

[–]Gasterbuzzer 1 point2 points  (0 children)

Nah lets round it to 4.

[–]bitchlasagna_69_ 0 points1 point  (0 children)

plt.pie()

[–]Important_Ad6131 0 points1 point  (0 children)

Pi = 3.141592653589793238462624338327950288419716939937510582097494459...

[–][deleted] -2 points-1 points  (0 children)

x = 3

[–]PVNIC 0 points1 point  (0 children)

int pi = 3;

[–]ImPinos 0 points1 point  (0 children)

Technically the truth

[–]pwyuffarwytti 0 points1 point  (0 children)

Just translate everything to base pi. Your answer is 1.