Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions spark
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ spark()

for n in ${@//,/ }
do
if [ $log = "base2" ]; then
n=`echo "scale = 0; l($n)" | bc -l`
elif [ $log = "base10" ]; then
n=`echo "scale = 0; l($n)/l(10)" | bc -l`
fi
# on Linux (or with bash4) we could use `printf %.0f $n` here to
# round the number but that doesn't work on OS X (bash3) nor does
# `awk '{printf "%.0f",$1}' <<< $n` work, so just cut it off
Expand Down Expand Up @@ -89,6 +94,10 @@ if [ "$BASH_SOURCE" == "$0" ]; then
▁▂▃▄▂█
echo 9 13 5 17 1 | $spark
▄▆▂█▁
echo 1,10,100,1000,10000,100000 | spark -l10
▁▂▃▅▆█
echo 2,4,8,16,32,64,128,256,512,1024,2048,4096,8192 | spark -ln
▁▁▂▂▃▄▄▄▅▅▆▇█
EOF
}

Expand All @@ -99,5 +108,12 @@ EOF
exit 0
fi

# enable log, natural or base10, or no transformation by default
case $1 in
-ln) log=base2 ; shift ;;
-l10) log=base10 ; shift ;;
*) log="_" ;;
esac

spark ${@:-`cat`}
fi