Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- BASE=4
- RES=0
- RES_PREV=0
- ROUND=3 # number of digits used for rounding
- PREC_DEF=200000 # number of iterations with identical results bofore exiting
- X=2
- if [ -n "${1##*[!0-9]*}" ] && [ $1 -le 15 ]; then
- DIGIT=$(($1+$ROUND))
- else
- DIGIT=18
- fi
- while [ $((DIGIT=$DIGIT-1)) -ge 0 ]; do
- BASE=$(($BASE*10))
- done
- PREC=$PREC_DEF
- while [ $PREC -ge 0 ]; do
- RES=$(($RES+($BASE/($X*$((X=$X+1))*$((X=$X+1))))-($BASE/($X*$((X=$X+1))*$((X=$X+1))))))
- if [ $RES_PREV -eq $RES ]; then
- PREC=$(($PREC-1))
- else
- COUNT=0
- ITERATION=$(($ITERATION+1))
- RES_PREV=$RES
- RES_FIN=$RES
- PREC=$PREC_DEF
- while [ $((COUNT=$COUNT+1)) -le $ROUND ]; do RES_FIN=$((($RES_FIN+5)/10)); done
- printf "\r3.$RES_FIN"
- fi
- done
- printf "\nUsed iterations: $ITERATION\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement