bc
输出:bc 1.06 Copyright 1991-1994,1997,1998,2000 Free Software Foundation,Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 9*2 18
上述命令是来做数学运算。
bc -l
输出:bc 1.06 Copyright 1991-1994,1997,1998,2000 Free Software Foundation,Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 1+2 3
上述命令是求'1+2'的和。
bc calc.txt
输出:bc 1.06 Copyright 1991-1994,1997,1998,2000 Free Software Foundation,Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 3
'calc.txt' 这个文件有代码:1+2。 从文件输入并且显示输出结果。
簡單好用的計算機: bc如果我想要使用簡單的計算器呢?很容易呀!就使用 bc 即可!在輸入 bc 之後, 顯示出版本資訊之後,就進入到等待指示的階段。如下所示:[root@linux ~]# bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
_<==這個時候,游標會停留在這裡等待您的輸入事實上,我們是『進入到 bc 這個指令的工作環境當中』了! 就好像我們在 Windows 裡面使用『小算盤』一樣!所以,我們底下嘗試輸入的資料, 都是在 bc 程式當中在進行運算的動作。所以囉,您輸入的資料當然就得要符合 bc 的要求才行! 在基本的 bc 計算機操作之前,先告知幾個使用的運算子好了:+ 加法
- 減法
* 乘法
/ 除法
^ 指數
% 餘數
在上表當中,粗體字表示輸入的資料,而在每個粗體字的底下就是輸出的結果。 咦!每個計算都還算正確,怎麼 10/100 會變成 0 呢?這是 因為 bc 預設僅輸出整數,如果要輸出小數點下位數,那麼就必須要執行 scale=number ,那個 number 就是小數點位數,例如:[root@linux ~]# bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1+2+3+4<==只有加法時
10
7-8+3
2
10*52
520
10%3<==計算『餘數』
1
10^2
100
10/100<==這個最奇怪!不是應該是 0.1 嗎?
0
quit<==離開 bc 這個計算器
好了!就是這樣子啦!簡單的很吧!以後你可以輕輕鬆鬆的進行加減乘除啦![root@linux ~]# bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
scale=3<==沒錯!就是這裡!!
1/3
.333
340/2349
.144
quitMATH LIBRARY
If bc is invoked with the -l option, a math library is preloaded and the default scale is set to 20.
The math functions will calculate their results to the scale set at the time of their call. The math
library defines the following functions:
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. 贝塞尔函数PS: echo "scale=100; a(1)*4" | bc -l (计算圆周率)
linux ab
原创
©著作权归作者所有:来自51CTO博客作者linchqd的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:Linuxu盘安装制作

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Linux命令(139)之ab
linux命令之ab介绍
数据 Time centos ab