Skip to main content

Timeline for Calculating pi using bash

Current License: CC BY-SA 3.0

10 events
when toggle format what by license comment
Apr 30, 2020 at 4:36 comment added dimo414 I'd also suggest SCALE=${1:?} or SCALE=${1:-4} to fail-fast or fall-back to a default value if a scale isn't passed on the command line.
Apr 30, 2020 at 4:33 comment added dimo414 Regarding "I don't know of a bash style guide" there's the Google Shell Style Guide; it's not perfect but it's a good starting point.
May 23, 2017 at 12:41 history edited CommunityBot
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Jun 24, 2015 at 8:14 vote accept insanikov
Jun 23, 2015 at 17:31 history edited Edward CC BY-SA 3.0
simplified echo statements by removing `scale` from all but the calculation for delta
Jun 22, 2015 at 13:52 comment added insanikov I understand it now, I would have never come up with this. Thank you for the explanation.
Jun 21, 2015 at 21:27 history edited Edward CC BY-SA 3.0
added more explanation of how it works with sample output
Jun 21, 2015 at 21:08 comment added Edward It's a bit subtle. Basically, a value of 0.001 (=1e-3) with a scale of 3 is nonzero, but a value of 0.0005 (=5e-4) is considered to be equal to zero at a scale of 3, so when the next term becomes less than smaller than 1e-${SCALE}, the printable part of ${PI} is unlikely to change except in the least significant digit. A refinement would be to use ${SCALE}+1 in the while loop but it doesn't make much difference and this is slightly easier to understand.
Jun 21, 2015 at 18:17 comment added insanikov I really appreciate the suggestions, but I don't completely understand how you've implemented the stopping feature, SCALE simply is how many numbers exist after the decimal point. There's probably something I'm not seeing here...
Jun 21, 2015 at 18:07 history answered Edward CC BY-SA 3.0