bc, a Linux command-line calculator, is proficient enough to calculate
3^2
9
Even a negative exponent doesn't confuse it:
3^-2
0.11111
Yet it fails when it encounters
9^0.5
Runtime warning (func=(main), adr=8): non-zero scale in exponent
How could it be that bc can't handle this?
And what does the error message mean?
Yes, I've read this and the solution given there:
e(0.5*l(9))
2.99999999999999999998
And yes, it is no good because of precision loss and
A calculator is supposed to solve expressions. You are not supposed to make life easier for the calculator, it is supposed to be the other way around...
This feature was designed to encourage users to write their own functions. Making it a unique calculator that requires a user-defined function to calculate a square root.
It doesn't really bother me to write a function for tangents or cotangents as it looks pretty straightforward given s(x)
and c(x)
. But in my opinion calculating a square root through a user-defined function is a bit too much.
Why anyone uses bc if there's Python out there? Speed?
bc
has a native square-root function already:scale=5; sqrt(9)
– Cryogenius --exec='81^0.75'
– Affricateecho "e(0.5*l(9))"|bc -l
. I need twicel
here for themathlib
or is the first l for other? – Nastye
is exp,l
is log,-l
is --mathlib – Diapere(0.5*l(9))
and not usinge
as in0.5*l(9)
? I see the result but I do not understand the diff. – Nastyexp(0.5*log(9))
is the same thing as3^0.5
orsqrt(3)
. If it is not obvious to you, revisit the properties of the logarithm function. – Diaperbc
. – Nastya^b
,a
must be int inbc
I think. – Nastyexp(0.5*log(9))=3^0.5
. It must be exp(0.5*log(9))=9^0.5.3
is the result – Nastye
with fractional exponent in bc?e(0.5*l(e))
leads toMath error: overflow: number cannot fit
– Nasty