bc Programming
導入
 bc は dc 同様、arbitrary calculator であるが、reverse Polish notation を採用していない。C に似た構文を採用している。
 bc は interactive であるが、echo 1+ 2 | bc といった方法もよく使われる。
scale & '.'
 小数点以下の桁数は、dc ではprecision number と表現されるが、dc では、scale という。
 default で 0。 すなわち、整数。
 eg) scal = 20 (20桁表示)
 直前の計算結果は、'.' で示すことができる。
 eg) 1 + 2 => 3
     .*10 => 30
関数
 関数としては、sqrt(x)があるが、-lオプションで起動すると、次の数学関数を使用できる。scaleは20に設定される。
 s(x) sine of x (x:radians)
 c(x) cosine
 a(x) arctangent
 l(x) natural logarithm
 e(x) exponential function
 j(n,x) bassel function of integer order n of x
制御構文 for if while 等
eg) 0~9 まで表示
  for(i=0;i<10;i++)i (改行して表示)
  for(            ) print i => 0123456789
  for(            ) print i, " " => 0 1 2 3 4 5 6 7 8 9
事例
 print "hello world!\n"
 print 1+2 => 3
 print "1+1= ",1+1; => 1+1=2
 define fact(x){
     if (x<=1) return (1);
     return (f(x-1)*x);
 }
 define fact(x){
     if(x<=1) return 1
     else return x*f(x-1);
 }
最終更新:2009年02月06日 15:52