Minimal BC for Mingw
Posted by mazet on 24 Mar 2017 in Bash
Minimal implementation of BC (basic calculator) in bash using perl for math evaluation.
Shell
function bc () { | |
ans=0 | |
while true; do | |
read buf || return | |
[ "$buf" ] || continue | |
for p in atan sin exp log cos; do | |
buf=${buf//${p:0:1}(/$p(} | |
done | |
ans=$(perl -e "sub atan {atan2(\$_[0],1)}; | |
print 0 + ${buf//^/**}" 2>/dev/null) | |
echo $ans | |
done | |
} |