Share your repls and programming experiences

← Back to all posts
π Approximations in C
h
AmazingMech2418 (894)

So, you might have already seen @StudentFires 's attempt at a fast and accurate π approximation in C++...

So, here are two actually fast and accurate π approximations in C:

The repl linked to this post is the most accurate and is found at https://repl.it/@AmazingMech2418/p-in-C and the other is https://repl.it/@AmazingMech2418/p-in-C-2.

The first one uses trapezoidal sums while the other uses the Nilakantha Series.

Update: The second one was updated to make it faster. It gets to 16 places very quickly.

Commentshotnewtop
Jakman (450)

Also i can do this real fast. Imma challenge you.

Jakman (450)

@AmazingMech2418 the fastest pi approx in a middle, esoteric or low-level language. So no python or js or lua, etc.

AmazingMech2418 (894)

@Jakman I already did Forth... And APL... And LOLCODE...

Jakman (450)

@AmazingMech2418 C is low-level. C# is middle-level.

AmazingMech2418 (894)

@Jakman Yeah, but you said both... Also, try beating my C# and Forth approximations!

Jakman (450)

@AmazingMech2418 you can do it again. I bet Ill do it faster.

AmazingMech2418 (894)

@Jakman My Forth one is instant...

Jakman (450)

@AmazingMech2418 no man. I mean just one language. Ill beat your Forth program any day. C# can be done.

Jakman (450)

@AmazingMech2418 it can still be done faster. Imma use some async processing.

AmazingMech2418 (894)

@Jakman You won't be able to tell if it is faster though... The Forth one is too fast.

Jakman (450)

@AmazingMech2418 ill put on a stopwatch thread.

AmazingMech2418 (894)

@Jakman Forth has no time module...

Jakman (450)

@AmazingMech2418 i am doing it in C# dude. The challenge was any language.

AmazingMech2418 (894)

@Jakman Yes, but my Forth program can't be timed.

Jakman (450)

@AmazingMech2418 hmm. That could be an issue. How about any lang with a time module.

AmazingMech2418 (894)

@Jakman Then, let's do my C# one. Though, Forth is much faster...

AmazingMech2418 (894)

@Jakman It has to be accurate to the same number of places though...

AmazingMech2418 (894)

@Jakman Native trigonometry is like using the normal pi variable... I'm honestly just waiting for you to finish now...

AmazingMech2418 (894)

@Jakman You didn't even finish yours...

AmazingMech2418 (894)

@Jakman Oh. Can you upload to Repl.it so I can try it out? Also, I have the hacker plan, so I get double the speed.

Jakman (450)

@AmazingMech2418 nah man. deleted the source code after i found i lost. Sorry about that.
I used the x * sin(180/x) method of pi.

AmazingMech2418 (894)

@Jakman You still did pretty well. Maybe, next time, try C. :)

Jakman (450)

@AmazingMech2418 next time then. Good Game.

Jakman (450)

If you need help with more C documentation I found free C book by the 2 creators of the language on this link 'http://www2.cs.uregina.ca/~hilder/cs833/Other%20Reference%20Materials/The%20C%20Programming%20Language.pdf'
I dont know if it is pirated so you dont know this from me ok.