Skip to content
Sign upLog in

π in Swift

Profile icon

I think I'm pretty much doing pi approximations in every language now, so, here it is in Swift! By the way, compare this to Kotlin and see why Kotlin is starting to take over Java in Android development (Swift is for Mac and iOS development).

Here are the other approximations so far:
C# -
Bash -
Kotlin -
Ruby -
Java -
QBasic -
Fortran -
Forth -
Python and Node.js (Node is linked in post) -
C -

Credit to

, and
for inspiring these approximations. Most of these use the Nilakantha Series, although I also use the arctangent method (multiplying the radian arctangent of 1 by 4 to get pi and getting the arctangent with an infinite series) in three of them (Python, Node, and C).

Also, thank you to

for inspiring this approximation to be done in Swift after attempting your own version with a binary search algorithm!

You are viewing a single comment. View All
Profile icon

This one is also a lot like Kotlin. Honestly, after seeing the similarities, I just copied and pasted and changed the for loop and changed println to print.