compute pow() with shell only, in case we don't have bc, dc, perl

This commit is contained in:
don fong
2011-07-26 12:54:42 -07:00
parent ea15324e30
commit 54bc41ffaf

View File

@@ -40,9 +40,21 @@ fakedate()
fakecmd "$1" date +$fmt
}
#
# compute x**n.
# use only the shell, in case we need to run on machines
# without bc, dc, perl, etc.
#
pow()
{
dc -e "$1 $2 ^ p"
typeset x="$1" n="$2"
typeset r=1
typeset i=0
while ((i < n)); do
((r = r*x))
((i++))
done
echo $r
}
# run a fakedate test with a given time t