π in R

I think I'm pretty much doing pi approximations in every language now, so, here it is in R!

I was going to do NASM before R (and actually before Raku Haskell even), but ran into some issues with floating point numbers that I'm currently working on fixing (if you know how to fix it, please tell me here: https://repl.it/talk/ask/NASM-Print-Floating-Point/41105).

Credit to @NoelBryan, @TheForArkLD , @Warhawk947 , and @LizFoster 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, credit to @HahaYes for inspiring this approximation in R!

Next up is NASM (Assembly; only if I can actually figure it out. I might have to save it for later since it is so difficult to program in. I keep pushing it back anyways due to issues with printing floating point numbers), followed by Dart. If you have any suggestions for after those, please let me know!

You are viewing a single comment. View All
theangryepicbanana (1635)

for this:

``````i <- 0
# Begin while loop
while(i < 150000) {
# Iterate Nilakantha Series
iterate()
# Increment counter variable
i <<- i + 1
}``````

I'm pretty sure that you could have used a for-loop instead like:

``````i <- 0
# Begin while loop
for(i in 0:150000) {
# Iterate Nilakantha Series
iterate()
}``````
AmazingMech2418 (692)

@theangryepicbanana Okay. When reading the documentation, I thought R only supported looping through arrays and strings (and other iterable objects), so I just decided to do a while loop instead.

HahaYes (1048)

@theangryepicbanana oh look, the guy who yelled at me

theangryepicbanana (1635)

@AmazingMech2418 A range (`begin:end`) creates an array so that should be fine