Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I do a cube root in GNU bc?

CUBE GNU
0
Posted

How do I do a cube root in GNU bc?

0

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.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123