How do I do a cube root in GNU bc?
The easiest way to do a cube root in bc is to use the pow() and root() functions from this site’s funcs.bc library; pow({number},1/3) and root({number},3) both achieving the required result. š Of course, you may just want to use the following quick-and-dirty trick that both of those functions are based upon. Again, this example is for the bash shell: echo ‘e(l({number})/3)’ | bc -l This works on the mathematical principle that: nāx = x(1/n) = e(ln x)/n In bc you might like to use this to write your own cube root function: define cbrt(x) { return e(l(x)/3)) } And then use it as you would the built in sqrt(). As you might guess then, the e() and l() used above are the GNU bc exponential and natural logarithm functions respectively. Both are only available as part of the standard library, so the -l flag is absolutely essential for them to be usable.