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  (计算圆周率)    

 

          

你可能感兴趣的:(命令)