bc命令

bc 命令:
     bc 命令是用於命令行計算器。 它相似基本的計算器。 使用這個計算器能夠作基本的數學運算。


[tough@localhost expr]$ echo 8*3|bc
24

[tough@localhost expr]$ echo '8+2'|bc
10

[tough@localhost expr]$ echo "8 -2"|bc
6

 

把要計算工的內容放入文件中:函數

[tough@localhost expr]$ echo "4+5" > cal.txt

[tough@localhost expr]$ bc cal.txt
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
9

 

進入bc模式:
[tough@localhost expr]$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.

6+2
8

6 +2
8

6-2
4

6*2
12

6/2
3


2^4
16

5%3
2

5/3
1


#設置精度 scale
=2 5/3 1.66 5/2 2.50 (5^3 - 25)/4 + 1 26.00 quit

 

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.  log函數(以2爲底)

e (x)  The exponential function of raising e to the value x.  e的指數函數

j (n,x)
       The bessel function of integer order n of x.   貝塞爾函數


echo "scale=100; a(1)*4" | bc -l  (計算圓周率)    
          
相關文章
相關標籤/搜索