bc -l とすること(オプション -l)で、標準的な数学関数が使えるようになる
s (x) The sine of x, x is in radians.~
c (x) The cosine of x, x is in radians.~
a (x) The arctangent of x, arctangent returns radians.~
l (x) The natural logarithm of x.~
e (x) The exponential function of raising e to the value x.~
j (n,x) The bessel function of integer order n of x.~
例1) log_2 (x)
define lg(x) {
return (l(x) / l(2));
}
例2) 二点間の距離
define dist (x,y,z,u,v,w) {
return sqrt((x-u)*(x-u)+(y-v)*(y-v)+(z-w)*(z-w));
}
例3) 羃乗
define pow (x,y) {
auto k, ans;
ans=1;
for ( k=0; k<y; k++ ) {
ans = ans*x;
}
return ans;
}
その他は man bc を参照のこと
平方根は sqrt( )
1.23e-4とかの表現は可能か?